Skip to content

Commit 77f1a80

Browse files
committed
re-ordering workflow, so that if an existing tag matches the version in pyproject.toml, it means that the library with this version was already released and we should fail
1 parent bf98923 commit 77f1a80

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,34 @@ jobs:
1717
- name: Setup the Python Environment by installing Poetry
1818
uses: ./.github/actions/setup-python-build-env
1919

20+
- name: Retrieve the project version
21+
id: version
22+
shell: bash
23+
run: |
24+
echo "proj_version=$(poetry version -s)" >> $GITHUB_OUTPUT
25+
26+
- name: Check if tag exists, only proceed if version has not been released
27+
run: |
28+
echo "Checking for tag: $PROJ_TAG"
29+
if git rev-parse "refs/tags/$PROJ_TAG" >/dev/null 2>&1
30+
echo "Version $PROJ_TAG already exists, version bump required to proceed."
31+
exit 1
32+
fi
33+
env:
34+
PROJ_TAG: v${{ steps.version.outputs.PROJ_VERSION }}
35+
2036
- name: Code Quality Check
2137
shell: bash
2238
run: make install && make tests
2339

24-
- name: Poetry bump version, build and publish
25-
id: build
40+
- name: Build library and publish to PyPi
2641
shell: bash
2742
run: |
28-
proj_version=$(poetry version -s)
29-
echo ::set-output name=PROJ_VERSION::$proj_version
3043
poetry publish --build -u __token__ -p $PYPI_TOKEN
3144
env:
3245
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
3346

34-
- name: Check if Tag exists 🔍
35-
id: check_tag
36-
run: |
37-
echo "Checking for tag: $PROJ_TAG"
38-
if git rev-parse "refs/tags/$PROJ_TAG" >/dev/null 2>&1
39-
then
40-
echo "Tag $PROJ_TAG already exists."
41-
echo "tag_exists=true" >> $GITHUB_OUTPUT
42-
exit 0
43-
else
44-
echo "Tag $PROJ_TAG does not exist."
45-
echo "tag_exists=false" >> $GITHUB_OUTPUT
46-
fi
47-
env:
48-
PROJ_TAG: v${{ steps.build.outputs.PROJ_VERSION }}
49-
5047
- name: Create and Push Tag 🏷️
51-
if: steps.check_tag.outputs.tag_exists == 'false'
5248
run: |
5349
git tag $PROJ_TAG
5450
git config user.name "GitHub Actions"
@@ -58,13 +54,13 @@ jobs:
5854
echo "tag_created=true" >> $GITHUB_OUTPUT
5955
env:
6056
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61-
PROJ_TAG: v${{ steps.build.outputs.PROJ_VERSION }}
57+
PROJ_TAG: v${{ steps.version.outputs.PROJ_VERSION }}
6258

6359
- name: Create a GitHub Release
64-
uses: softprops/action-gh-release@v1
60+
uses: softprops/action-gh-release@v2
6561
env:
6662
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67-
PROJ_TAG: v${{ steps.build.outputs.PROJ_VERSION }}
63+
PROJ_TAG: v${{ steps.version.outputs.PROJ_VERSION }}
6864
with:
6965
generate_release_notes: true
7066
tag_name: $PROJ_TAG

0 commit comments

Comments
 (0)