Repository navigation
ci: publish to PyPI with Trusted Publishing from master #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fca510c
ci: publish to PyPI with Trusted Publishing
mogita bbd7802
ci: release on push to master and publish from a locked environment
mogita f7563bb
ci: skip already uploaded files when publishing
mogita fdfbf97
ci: tag the release commit before publishing to PyPI
mogita b5e9354
ci: release until the version is on PyPI and rebuild the tagged commit
mogita 1b13dff
ci: run one release at a time and require both files on PyPI
mogita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,115 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: read | ||
| permissions: {} | ||
|
|
||
| # One release run at a time, so overlapping pushes cannot build the same version twice. | ||
| concurrency: | ||
| group: release | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| Release: | ||
| name: 🚀 Release | ||
| if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-') | ||
| # A merged release PR bumps __version__, so a version without both files on PyPI is a release to finish. | ||
| # Once tagged, the tagged commit is rebuilt, so a rerun or a later push publishes the same code. | ||
| check: | ||
| name: 🔎 Check for a new version | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| outputs: | ||
| ref: ${{ steps.version.outputs.ref }} | ||
| release: ${{ steps.version.outputs.release }} | ||
| version: ${{ steps.version.outputs.version }} | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: actions/github-script@v5 | ||
| - id: version | ||
| run: | | ||
| version="v$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' stream_chat/__pkg__.py)" | ||
| echo "version=$version" >> "$GITHUB_OUTPUT" | ||
| if curl -sf --retry 3 "https://pypi.org/pypi/stream-chat/${version#v}/json" | | ||
| jq -e '[.urls[].packagetype] | index("sdist") and index("bdist_wheel")' >/dev/null; then | ||
| echo "release=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "release=true" >> "$GITHUB_OUTPUT" | ||
| echo "ref=$(git rev-parse -q --verify "refs/tags/$version^{commit}" || echo "$GITHUB_SHA")" >> "$GITHUB_OUTPUT" | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
|
||
| build: | ||
| name: 🏗️ Build | ||
| needs: check | ||
| if: needs.check.outputs.release == 'true' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| outputs: | ||
| changelog: ${{ steps.changelog.outputs.changelog }} | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| with: | ||
| ref: ${{ needs.check.outputs.ref }} | ||
|
|
||
| - id: changelog | ||
| uses: actions/github-script@v5 | ||
| with: | ||
| script: | | ||
| const get_change_log_diff = require('./scripts/get_changelog_diff.js') | ||
| core.exportVariable('CHANGELOG', get_change_log_diff()) | ||
|
|
||
| // Getting the release version from the PR source branch | ||
| // Source branch looks like this: release-1.0.0 | ||
| const version = context.payload.pull_request.head.ref.split('-')[1] | ||
| core.exportVariable('VERSION', version) | ||
| core.setOutput('changelog', get_change_log_diff()) | ||
|
|
||
| - uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: "3.10" | ||
|
|
||
| - name: Publish to PyPi | ||
| env: | ||
| TWINE_USERNAME: "__token__" | ||
| TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}" | ||
| - name: Build | ||
| run: | | ||
| pip install -q twine==3.7.1 wheel==0.37.1 | ||
| pip install -q wheel==0.37.1 | ||
| python setup.py sdist bdist_wheel | ||
| twine upload --non-interactive dist/* | ||
|
|
||
| - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
|
|
||
| # Tags the release commit before the upload. A rerun keeps the existing release. | ||
| release: | ||
| name: 🚀 Release | ||
| needs: [check, build] | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Create release on GitHub | ||
| uses: ncipollo/release-action@v1 | ||
| with: | ||
| body: ${{ env.CHANGELOG }} | ||
| tag: ${{ env.VERSION }} | ||
| body: ${{ needs.build.outputs.changelog }} | ||
| tag: ${{ needs.check.outputs.version }} | ||
| commit: ${{ needs.check.outputs.ref }} | ||
| skipIfReleaseExists: true | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| # The only job that can mint a PyPI token, so it runs no project code. The PyPI trusted | ||
| # publisher requires the pypi environment, which only master can deploy to. | ||
| publish: | ||
| name: 📦 Publish to PyPI | ||
| needs: [build, release] | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| runs-on: ubuntu-latest | ||
| environment: pypi | ||
| permissions: | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
|
|
||
| # A rerun after a partial upload skips the files PyPI already has. | ||
| - name: Publish to PyPI (Trusted Publishing) | ||
| uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 | ||
| with: | ||
| skip-existing: true | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.