Skip to content

Commit 4414516

Browse files
committed
feat: add semantic versioning
1 parent 62641c2 commit 4414516

4 files changed

Lines changed: 70 additions & 21 deletions

File tree

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
name: Publish to PyPI
1+
name: Release (release → PyPI)
22

33
on:
44
push:
55
branches:
66
- release
77

8+
permissions:
9+
contents: write
10+
id-token: write
11+
pull-requests: write
12+
813
jobs:
9-
deploy:
10-
name: Build and Publish to PyPI
14+
release:
1115
runs-on: ubuntu-latest
1216
environment: pypi-universalpython
13-
14-
permissions:
15-
id-token: write
1617

1718
steps:
1819
- uses: actions/checkout@v4
19-
20+
with:
21+
fetch-depth: 0
22+
2023
- name: Set up Python
2124
uses: actions/setup-python@v5
2225
with:
@@ -25,11 +28,28 @@ jobs:
2528
- name: Install dependencies
2629
run: |
2730
python -m pip install --upgrade pip
28-
pip install build twine
31+
pip install build twine python-semantic-release
2932
pip install -r utils/requirements.txt
30-
33+
34+
- name: Create stable release
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: |
38+
semantic-release version --commit --tag --push
39+
3140
- name: Build package
3241
run: bash utils/build_package.sh
3342

3443
- name: Publish to PyPI
35-
uses: pypa/gh-action-pypi-publish@release/v1
44+
uses: pypa/gh-action-pypi-publish@release/v1
45+
46+
- name: Create PR to sync release → main
47+
uses: peter-evans/create-pull-request@v5
48+
with:
49+
token: ${{ secrets.GITHUB_TOKEN }}
50+
base: main
51+
head: release
52+
title: "chore: merge release changes back into main"
53+
body: |
54+
This PR was created automatically after publishing a new PyPI release.
55+
It keeps `main` in sync with version and changelog updates.
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
name: Publish to Test PyPI
1+
name: Prerelease (main → TestPyPI)
22

33
on:
44
push:
55
branches:
66
- main
77

8+
permissions:
9+
contents: write
10+
id-token: write
11+
812
jobs:
9-
deploy:
10-
name: Build and Publish to Test PyPI
13+
prerelease:
1114
runs-on: ubuntu-latest
1215
environment: test-pypi-universalpython
13-
14-
permissions:
15-
id-token: write
1616

1717
steps:
1818
- uses: actions/checkout@v4
19-
19+
with:
20+
fetch-depth: 0
21+
2022
- name: Set up Python
2123
uses: actions/setup-python@v5
2224
with:
@@ -25,12 +27,19 @@ jobs:
2527
- name: Install dependencies
2628
run: |
2729
python -m pip install --upgrade pip
28-
pip install build twine
30+
pip install build twine python-semantic-release
2931
pip install -r utils/requirements.txt
32+
33+
- name: Determine and tag prerelease version
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
run: |
37+
semantic-release version --prerelease --prerelease-token b --commit --tag --push
38+
3039
- name: Build package
3140
run: bash utils/build_package.sh
3241

33-
- name: Publish to Test PyPI
42+
- name: Publish to TestPyPI
3443
uses: pypa/gh-action-pypi-publish@release/v1
3544
with:
36-
repository-url: https://test.pypi.org/legacy/
45+
repository-url: https://test.pypi.org/legacy/

pyproject.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,27 @@ universalpython = "universalpython.universalpython:main"
4646

4747
[tool.semantic_release]
4848
version_toml = ["pyproject.toml:project.version"]
49+
upload_to_pypi = false
50+
tag_format = "{version}"
4951
build_command = "bash ./utils/build_package.sh"
5052
commit_parser = "conventional"
5153
major_on_zero = true
5254
allow_zero_version = true
55+
prerelease_token = "b"
5356

5457
[tool.semantic_release.commit_parser_options]
5558
parse_squash_commits = true
5659
ignore_merge_commits = true
5760

5861
[tool.semantic_release.changelog.default_templates]
5962
changelog_file = "./CHANGELOG.md"
60-
output_format = "md"
63+
output_format = "md"
64+
65+
[tool.semantic_release.branches.release]
66+
match = "release"
67+
prerelease = false
68+
69+
[tool.semantic_release.branches.main]
70+
match = "main"
71+
prerelease = true
72+
prerelease_token = "b"

universalpython/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/usr/bin/env python
2+
from importlib.metadata import version as get_version, PackageNotFoundError
3+
4+
try:
5+
__version__ = get_version("universalpython")
6+
except PackageNotFoundError:
7+
# When running locally before installation
8+
__version__ = "0.0.0"
9+
210
"""
311
UniversalPython.
412

0 commit comments

Comments
 (0)