3939 needs : [build]
4040 steps :
4141 - uses : actions/checkout@v4
42+ with :
43+ fetch-depth : 0
44+
45+ - name : Get version from pyproject.toml
46+ id : get_version
47+ run : |
48+ VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
49+ echo "version=v$VERSION" >> $GITHUB_OUTPUT
50+
51+ - name : Check if tag exists
52+ id : check_tag
53+ run : |
54+ if git rev-parse "${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
55+ echo "exists=true" >> $GITHUB_OUTPUT
56+ else
57+ echo "exists=false" >> $GITHUB_OUTPUT
58+ fi
59+
60+ - name : Create and push tag
61+ if : steps.check_tag.outputs.exists == 'false'
62+ run : |
63+ git config user.name "github-actions[bot]"
64+ git config user.email "github-actions[bot]@users.noreply.github.com"
65+ git tag -a "${{ steps.get_version.outputs.version }}" -m "Release ${{ steps.get_version.outputs.version }}"
66+ git push origin "${{ steps.get_version.outputs.version }}"
4267
4368 - name : Download dist artifacts
4469 uses : actions/download-artifact@v4
@@ -47,29 +72,13 @@ jobs:
4772 path : dist/
4873
4974 - name : Create GitHub Release
75+ if : steps.check_tag.outputs.exists == 'false'
5076 uses : softprops/action-gh-release@v2
5177 with :
78+ tag_name : ${{ steps.get_version.outputs.version }}
5279 files : dist/*
5380 generate_release_notes : true
5481 draft : false
5582 prerelease : false
5683 env :
5784 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
58-
59- # Uncomment this job if you want to publish to PyPI
60- # pypi-publish:
61- # runs-on: ubuntu-latest
62- # needs: [build]
63- # environment:
64- # name: pypi
65- # url: https://pypi.org/project/dtm-differ
66- # permissions:
67- # id-token: write # For trusted publishing
68- # steps:
69- # - uses: actions/download-artifact@v4
70- # with:
71- # name: dist
72- # path: dist/
73- #
74- # - name: Publish to PyPI
75- # uses: pypa/gh-action-pypi-publish@release/v1
0 commit comments