Skip to content

Commit bf54479

Browse files
committed
version on release
1 parent 7445ddd commit bf54479

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/release.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
name: Release New PyPi Version
22

3+
permissions:
4+
id-token: write
5+
contents: write
6+
37
on:
48
workflow_dispatch: # This event allows manual triggering
59

610
jobs:
711
release:
812
runs-on: ubuntu-latest
13+
14+
outputs:
15+
version: ${{ steps.version.outputs.version }}
916

1017
steps:
1118
- name: Checkout Repository
1219
uses: actions/checkout@v5
20+
with:
21+
fetch-tags: true
22+
fetch-depth: 0
1323

1424
- name: Setup Python
1525
uses: actions/setup-python@v6
@@ -28,7 +38,53 @@ jobs:
2838
- name: Install dependencies
2939
run: poetry install --all-extras
3040

41+
- name: Check for version bump
42+
id: version
43+
continue-on-error: false
44+
shell: bash {0}
45+
run: |
46+
PYPROJECT_TOML="pyproject.toml"
47+
48+
# Extract the version using grep and sed
49+
version=$(grep -m 1 "version" "$PYPROJECT_TOML" | sed -E 's/.*version[[:space:]]*=[[:space:]]*"([^"]*)".*/\1/')
50+
51+
echo "Project version: $version"
52+
53+
if [ -z "$version" ]
54+
then
55+
echo "Missing version file!"
56+
echo "Repository must have a package.json or a version.txt file!"
57+
exit 1
58+
fi
59+
60+
echo "Checking if $version already exists..."
61+
version_commit="$(git rev-parse "$version" 2>/dev/null)"
62+
if [ ! -z "$version_commit" ] && [ "$version_commit" != "$version" ];
63+
then
64+
echo "Version $version already exist on commit $version_commit!"
65+
echo "Abandoning build..."
66+
echo "To complete this release update the version field in the package.json with an appropriate semantic version."
67+
exit 1
68+
else
69+
echo "version=$version" >> "$GITHUB_OUTPUT"
70+
exit 0
71+
fi
72+
3173
- name: Upload to PyPI
3274
env:
3375
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
3476
run: poetry publish --build -u __token__ -p $PYPI_PASSWORD
77+
78+
- name: Tag
79+
id: tag
80+
continue-on-error: false
81+
run: |
82+
version="${{ steps.version.outputs.version }}"
83+
echo "Configuring github bot"
84+
git config user.name "github-actions[bot]"
85+
# Comes from https://api.github.com/users/github-actions%5Bbot%5D
86+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
87+
echo "Creating github tag: $version"
88+
git tag "$version"
89+
echo "Pushing tags"
90+
git push --tags

0 commit comments

Comments
 (0)