|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + #push: |
| 5 | + # branches: [ 'main' ] |
| 6 | + workflow_dispatch: |
| 7 | + release_force: |
| 8 | + # see https://python-semantic-release.readthedocs.io/en/latest/github-action.html#command-line-options |
| 9 | + description: 'force release be one of: [major | minor | patch]' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - major |
| 13 | + - minor |
| 14 | + - patch |
| 15 | + default: "" |
| 16 | + required: false |
| 17 | + prerelease_token: |
| 18 | + description: 'The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver. Like the rc in `1.2.0-rc.8`.' |
| 19 | + type: choice |
| 20 | + options: |
| 21 | + - rc |
| 22 | + - beta |
| 23 | + - alpha |
| 24 | + default: rc |
| 25 | + required: false |
| 26 | + prerelease: |
| 27 | + description: "Is a pre-release" |
| 28 | + type: boolean |
| 29 | + default: false |
| 30 | + required: false |
| 31 | + |
| 32 | +concurrency: |
| 33 | + group: deploy |
| 34 | + cancel-in-progress: false # prevent hickups with semantic-release |
| 35 | + |
| 36 | +env: |
| 37 | + PYTHON_VERSION_DEFAULT: "3.11" |
| 38 | + POETRY_VERSION: "1.4.1" |
| 39 | + |
| 40 | +jobs: |
| 41 | + release: |
| 42 | + # https://github.community/t/how-do-i-specify-job-dependency-running-in-another-workflow/16482 |
| 43 | + # limit this to being run on regular commits, not the commits that semantic-release will create |
| 44 | + if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'chore(release):') |
| 45 | + runs-on: ubuntu-latest |
| 46 | + concurrency: release |
| 47 | + permissions: |
| 48 | + # NOTE: this enables trusted publishing. |
| 49 | + # See https://github.com/pypa/gh-action-pypi-publish/tree/release/v1#trusted-publishing |
| 50 | + # and https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/ |
| 51 | + id-token: write |
| 52 | + contents: write |
| 53 | + steps: |
| 54 | + - name: Checkout code |
| 55 | + # see https://github.com/actions/checkout |
| 56 | + uses: actions/checkout@v3 |
| 57 | + with: |
| 58 | + fetch-depth: 0 |
| 59 | + |
| 60 | + - name: Setup python |
| 61 | + # see https://github.com/actions/setup-python |
| 62 | + uses: actions/setup-python@v4 |
| 63 | + with: |
| 64 | + python-version: ${{ env.PYTHON_VERSION_DEFAULT }} |
| 65 | + architecture: 'x64' |
| 66 | + - name: Install and configure Poetry |
| 67 | + # See https://github.com/marketplace/actions/install-poetry-action |
| 68 | + uses: snok/install-poetry@v1 |
| 69 | + with: |
| 70 | + version: ${{ env.POETRY_VERSION }} |
| 71 | + virtualenvs-create: true |
| 72 | + virtualenvs-in-project: true |
| 73 | + installer-parallel: true |
| 74 | + - name: Install dependencies |
| 75 | + run: poetry install --no-root |
| 76 | + - name: View poetry version |
| 77 | + run: poetry --version |
| 78 | + |
| 79 | + - name: Python Semantic Release |
| 80 | + id: release |
| 81 | + # see https://python-semantic-release.readthedocs.io/en/latest/automatic-releases/github-actions.html |
| 82 | + # see https://github.com/python-semantic-release/python-semantic-release |
| 83 | + uses: python-semantic-release/[email protected] |
| 84 | + with: |
| 85 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + force: ${{ github.event.inputs.release_force }} |
| 87 | + prerelease: ${{ github.event.inputs.prerelease && "true" || "false" }} |
| 88 | + prerelease_token: ${{ github.event.inputs.prerelease_token }} |
| 89 | + |
| 90 | + - name: Publish package distributions to PyPI |
| 91 | + if: steps.release.outputs.released == 'true' |
| 92 | + # see https://github.com/pypa/gh-action-pypi-publish |
| 93 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 94 | + with: |
| 95 | + password: ${{ secrets.PYPI_TOKEN }} |
| 96 | + |
| 97 | + - name: Publish package distributions to GitHub Releases |
| 98 | + if: steps.release.outputs.released == 'true' |
| 99 | + # see https://github.com/python-semantic-release/upload-to-gh-release |
| 100 | + uses: python-semantic-release/upload-to-gh-release@main |
| 101 | + with: |
| 102 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + tag: ${{ steps.release.outputs.tag }} |
0 commit comments