build: Add a github workflow for python-semantic-release #3
Workflow file for this run
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
| name: Python Semantic Release | ||
|
Check failure on line 1 in .github/workflows/release.yml
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| jobs: | ||
| run_tests: | ||
| uses: ./.github/workflows/ci.yml | ||
| release: | ||
| needs: run_tests | ||
| runs-on: ubuntu-latest | ||
| if: github.ref_name == 'main' | ||
| concurrency: | ||
| group: ${{ github.workflow }}-release-${{ github.ref_name }} | ||
| cancel-in-progress: false | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| # Note: We checkout the repository at the branch that triggered the workflow. | ||
| # Python Semantic Release will automatically convert shallow clones to full clones | ||
| # if needed to ensure proper history evaluation. However, we forcefully reset the | ||
| # branch to the workflow sha because it is possible that the branch was updated | ||
| # while the workflow was running, which prevents accidentally releasing un-evaluated | ||
| # changes. | ||
| - name: Setup | Checkout Repository on Release Branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.ref_name }} | ||
| - name: Setup | Force release branch to be at workflow sha | ||
| run: | | ||
| git reset --hard ${{ github.sha }} | ||
| - name: Action | Semantic Version Release | ||
| id: release | ||
| # Adjust tag with desired version if applicable. | ||
| uses: python-semantic-release/[email protected] | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| git_committer_name: "github-actions" | ||
| git_committer_email: "[email protected]" | ||
| working-directory: './backend' | ||
| - name: Publish | Upload to GitHub Release Assets | ||
| uses: python-semantic-release/[email protected] | ||
| if: steps.release.outputs.released == 'true' | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| tag: ${{ steps.release.outputs.tag }} | ||
| working-directory: './backend' | ||
| - name: Upload | Distribution Artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: distribution-artifacts | ||
| path: dist | ||
| if-no-files-found: error | ||
| working-directory: './backend' | ||
| outputs: | ||
| released: ${{ steps.release.outputs.released || 'false' }} | ||
| deploy: | ||
| # 1. Separate out the deploy step from the publish step to run each step at | ||
| # the least amount of token privilege | ||
| # 2. Also, deployments can fail, and its better to have a separate job if you need to retry | ||
| # and it won't require reversing the release. | ||
| runs-on: ubuntu-latest | ||
| needs: release | ||
| if: github.ref_name == 'main' && needs.release.outputs.released == 'true' | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| - name: Setup | Download Build Artifacts | ||
| uses: actions/download-artifact@v4 | ||
| id: artifact-download | ||
| with: | ||
| name: distribution-artifacts | ||
| path: dist | ||
| - name: Publish to PyPi | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| packages-dir: dist | ||
| user: __token__ | ||
| password: ${{ secrets.PYPI_UPLOAD_TOKEN }} | ||