Skip to content

Commit 74afedd

Browse files
committed
feat: add semanting versioning
1 parent f8b1c75 commit 74afedd

File tree

3 files changed

+100
-11
lines changed

3 files changed

+100
-11
lines changed

.github/workflows/release.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Continuous Delivery
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
# testing:
11+
# uses: ./.github/workflows/test.yml
12+
13+
semantic-versioning-release:
14+
name: Upload release to PyPI
15+
runs-on: ubuntu-latest
16+
# needs:
17+
# - testing
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-release-${{ github.ref_name }}
21+
cancel-in-progress: false
22+
environment:
23+
name: pypi
24+
url: https://pypi.org/p/PyFracVAL
25+
permissions:
26+
id-token: write
27+
contents: write
28+
29+
steps:
30+
- name: Setup | Checkout Repository on Release Branch
31+
uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.ref_name }}
34+
fetch-depth: 0
35+
36+
- name: Setup | Force release branch to be at workflow sha
37+
run: git reset --hard ${{ github.sha }}
38+
39+
- name: Setup | Install uv
40+
uses: astral-sh/setup-uv@v4
41+
42+
- name: Evaluate | Verify upstream has NOT changed
43+
shell: bash
44+
run: |
45+
set +o pipefail
46+
47+
UPSTREAM_BRANCH_NAME="$(git status -sb | head -n 1 | cut -d' ' -f2 | grep -E '\.{3}' | cut -d'.' -f4)"
48+
printf '%s\n' "Upstream branch name: $UPSTREAM_BRANCH_NAME"
49+
50+
set -o pipefail
51+
52+
if [ -z "$UPSTREAM_BRANCH_NAME" ]; then
53+
printf >&2 '%s\n' "::error::Unable to determine upstream branch name!"
54+
exit 1
55+
fi
56+
57+
git fetch "${UPSTREAM_BRANCH_NAME%%/*}"
58+
59+
if ! UPSTREAM_SHA="$(git rev-parse "$UPSTREAM_BRANCH_NAME")"; then
60+
printf >&2 '%s\n' "::error::Unable to determine upstream branch sha!"
61+
exit 1
62+
fi
63+
64+
HEAD_SHA="$(git rev-parse HEAD)"
65+
66+
if [ "$HEAD_SHA" != "$UPSTREAM_SHA" ]; then
67+
printf >&2 '%s\n' "[HEAD SHA] $HEAD_SHA != $UPSTREAM_SHA [UPSTREAM SHA]"
68+
printf >&2 '%s\n' "::error::Upstream has changed, aborting release..."
69+
exit 1
70+
fi
71+
72+
printf '%s\n' "Verified upstream branch has not changed, continuing with release..."
73+
74+
- name: Action | Semantic Version Release
75+
id: release
76+
uses: python-semantic-release/[email protected]
77+
with:
78+
github_token: ${{ secrets.GITHUB_TOKEN }}
79+
git_committer_name: "github-actions"
80+
git_committer_email: "[email protected]"
81+
82+
- name: Publish | Upload to GitHub Release Assets
83+
uses: python-semantic-release/[email protected]
84+
if: steps.release.outputs.released == 'true'
85+
with:
86+
github_token: ${{ secrets.GITHUB_TOKEN }}
87+
tag: ${{ steps.release.outputs.tag }}
88+
89+
- name: Publish | Build and Publish to PyPI
90+
if: steps.release.outputs.released == 'true'
91+
run: uv publish

pyfracval/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
_authors = ""
88

99
package_src = Path(__file__).parent
10-
# _version = package_src / "VERSION"
1110
_pyproject = package_src.parent / "pyproject.toml"
1211
if _pyproject.is_file():
1312
with open(_pyproject, "rb") as f:
1413
data = tomllib.load(f)
1514

16-
if "version" in data["project"]:
17-
__version__ = data["project"]["version"]
18-
else:
19-
raise ValueError("Version not found in pyproject.toml")
20-
2115
if "authors" in data["project"]:
2216
_authors = ",".join([x["name"] for x in data["project"]["authors"]])
2317
else:
24-
raise ValueError("Version not found in pyproject.toml")
18+
raise ValueError("Author not found in pyproject.toml")

pyproject.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ docs = [
3535
"sphinxcontrib-bibtex>=2.6.3",
3636
"sphinxcontrib-napoleon>=0.7",
3737
]
38-
test = [
39-
"py-spy>=0.4.0",
40-
"pytest>=8.3.3",
41-
]
38+
test = ["py-spy>=0.4.0", "pytest>=8.3.3"]
4239

4340
[project.scripts]
4441
pyfracval = "pyfracval.cli:cli"
4542

4643
[build-system]
4744
requires = ["hatchling"]
4845
build-backend = "hatchling.build"
46+
47+
[semantic_release]
48+
version_variable = ["pyfracval/__init__.py:__version__"]
49+
version_toml = ["pyproject.toml:project.version:nf"]
50+
major_on_zero = false
51+
branch = "main"
52+
build_command = "curl -LsSf https://astral.sh/uv/install.sh | sh && source $HOME/.local/bin/env && uv build"

0 commit comments

Comments
 (0)