1414 description : Create a (pre-)release when CI passes
1515 default : false
1616 required : false
17- update_dependencies :
18- type : boolean
19- description : Update dependencies to their latest version
20- default : false
21- required : false
2217 outputs :
2318 tag :
2419 description : " The created release tag"
@@ -102,10 +97,9 @@ jobs:
10297
10398 - name : Run All Code Quality Checks & Tests
10499 run : poe all --check
105-
106100
107101 github-release :
108- if : ${{ inputs.create_release == 'true' }}
102+ if : ${{ github.ref == 'refs/heads/main' && inputs.create_release }}
109103 needs :
110104 - build-python
111105 - tests
@@ -125,7 +119,6 @@ jobs:
125119 path : dist/
126120
127121 - name : Prevent automatic major/minor release
128- if : (github.event_name == 'push')
129122 run : |
130123 echo "Fetching the latest release..."
131124 tag=$(gh release view --json tagName --jq '.tagName')
@@ -150,12 +143,44 @@ jobs:
150143 run : echo "${{ steps.tag.outputs.tag }}"
151144
152145 - name : Release
153- if : (inputs.create_release)
154146 uses : softprops/action-gh-release@v2
155147 with :
156148 files : |
157149 ./dist/*
158150 tag_name : ${{ steps.tag.outputs.tag }}
159- prerelease : ${{github.ref != 'refs/heads/main'}}
160151 generate_release_notes : true
161152 target_commitish : ${{ github.sha }}
153+
154+ publish :
155+ name : Publish to PyPI
156+ needs : github-release
157+ runs-on : ubuntu-latest
158+ permissions :
159+ contents : write
160+ id-token : write # Required for Trusted Publishing
161+ steps :
162+ - name : Download assets from latest GitHub release using gh CLI
163+ env :
164+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
165+ run : |
166+ mkdir -p assets-to-publish
167+ release_tag="${{ needs.build-test-release.outputs.tag }}"
168+ gh release download "$release_tag" --repo "$GITHUB_REPOSITORY" --dir assets-to-publish
169+
170+ - name : List downloaded assets
171+ run : ls -la assets-to-publish
172+
173+ - name : Upload assets to PyPI
174+ uses : pypa/gh-action-pypi-publish@release/v1
175+ with :
176+ # To test, use the TestPyPI:
177+ # repository-url: https://test.pypi.org/legacy/
178+ # You must also create an account and project on TestPyPI,
179+ # as well as set the trusted-publisher in the project settings:
180+ # https://docs.pypi.org/trusted-publishers/adding-a-publisher/
181+ # To publish to the official PyPI repository, just keep
182+ # repository-url commented out.
183+ packages-dir : assets-to-publish
184+ skip-existing : true
185+ print-hash : true
186+ verbose : true
0 commit comments