|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 11 | + contents: write # needed for github actions bot to write to repo |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + name: "Bump version, create changelog and publish" |
| 18 | + environment: |
| 19 | + name: pypi |
| 20 | + url: https://pypi.org/p/postgrest |
| 21 | + steps: |
| 22 | + - name: Set up Python 3.11 |
| 23 | + uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: 3.11 |
| 26 | + |
| 27 | + - name: Set up Poetry |
| 28 | + uses: abatilo/actions-poetry@v3 |
| 29 | + with: |
| 30 | + poetry-version: 1.8.3 |
| 31 | + |
| 32 | + - uses: googleapis/release-please-action@v4 |
| 33 | + id: release |
| 34 | + with: |
| 35 | + target-branch: ${{ github.ref_name }} |
| 36 | + |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }} |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - if: ${{ steps.release.outputs }} |
| 43 | + id: versions |
| 44 | + run: | |
| 45 | + set -ex |
| 46 | +
|
| 47 | + RELEASE_CANDIDATE=true |
| 48 | + NOT_RELEASE_CANDIDATE='${{ steps.release.outputs.release_created }}' |
| 49 | + if [ "$NOT_RELEASE_CANDIDATE" == "true" ] |
| 50 | + then |
| 51 | + RELEASE_CANDIDATE=false |
| 52 | + fi |
| 53 | +
|
| 54 | + MAIN_RELEASE_VERSION=x |
| 55 | + RELEASE_VERSION=y |
| 56 | +
|
| 57 | + if [ "$RELEASE_CANDIDATE" == "true" ] |
| 58 | + then |
| 59 | + # Release please doesn't tell you the candidate version when it |
| 60 | + # creates the PR, so we have to take it from the title. |
| 61 | + MAIN_RELEASE_VERSION=$(node -e "console.log('${{ steps.release.outputs.pr && fromJSON(steps.release.outputs.pr).title }}'.split(' ').reverse().find(x => x.match(/[0-9]+[.][0-9]+[.][0-9]+/)))") |
| 62 | +
|
| 63 | + # Use git describe tags to identify the number of commits the branch |
| 64 | + # is ahead of the most recent non-release-candidate tag, which is |
| 65 | + # part of the rc.<commits> value. |
| 66 | + RELEASE_VERSION=$MAIN_RELEASE_VERSION-rc.$(node -e "console.log('$(git describe --tags --exclude rc*)'.split('-')[1])") |
| 67 | +
|
| 68 | + # release-please only ignores releases that have a form like [A-Z0-9]<version>, so prefixing with rc<version> |
| 69 | + RELEASE_NAME="rc$RELEASE_VERSION" |
| 70 | + else |
| 71 | + MAIN_RELEASE_VERSION=${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }} |
| 72 | + RELEASE_VERSION="$MAIN_RELEASE_VERSION" |
| 73 | + RELEASE_NAME="v$RELEASE_VERSION" |
| 74 | + fi |
| 75 | +
|
| 76 | + echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}" >> "${GITHUB_ENV}" |
| 77 | + echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}" |
| 78 | + echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}" >> "${GITHUB_ENV}" |
| 79 | + echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_ENV}" |
| 80 | +
|
| 81 | + echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}" >> "${GITHUB_OUTPUT}" |
| 82 | + echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_OUTPUT}" |
| 83 | + echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}" >> "${GITHUB_OUTPUT}" |
| 84 | + echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_OUTPUT}" |
| 85 | +
|
| 86 | + - name: Install dependencies |
| 87 | + run: poetry install |
| 88 | + |
| 89 | + - name: Build package distribution directory |
| 90 | + id: build_dist |
| 91 | + run: poetry build |
| 92 | + |
| 93 | + - name: Publish package distributions to PyPI |
| 94 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 95 | + # NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true. |
| 96 | + # See https://github.com/actions/runner/issues/1173 |
| 97 | + if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }} |
0 commit comments