|
| 1 | +name: Bump version |
| 2 | + |
| 3 | +# Don't let more than one version bump job run at a time |
| 4 | +# this prevents a race condition where two merges occur |
| 5 | +# at the same time and the version bump of the first one is not |
| 6 | +# finished before the second one starts, then they will both |
| 7 | +# try to bump to the same version. |
| 8 | +concurrency: version |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: [main] |
| 13 | + |
| 14 | +jobs: |
| 15 | + version: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: ${{ github.actor != 'botify-app[bot]' }} # prevent infinite loop |
| 18 | + steps: |
| 19 | + - name: Generate a GitHub App token |
| 20 | + id: generateAppToken |
| 21 | + uses: actions/create-github-app-token@3ff1caaa28b64c9cc276ce0a02e2ff584f3900c5 # v2.0.2 |
| 22 | + with: |
| 23 | + app-id: ${{ vars.BOTIFY_APP_CLIENT_ID }} |
| 24 | + private-key: ${{ secrets.BOTIFY_APP_PRIVATE_KEY }} |
| 25 | + |
| 26 | + # This step setups up the git config which is then used later to push the tag. |
| 27 | + # Auth for the repo is setup at this step, so we need to pass the bot token |
| 28 | + # in so that it does not use the GITHUB_TOKEN when the tag is pushed. This |
| 29 | + # allows this workflow to trigger another workflow from the tag event. |
| 30 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 31 | + with: |
| 32 | + ref: main |
| 33 | + token: ${{ steps.generateAppToken.outputs.token }} |
| 34 | + |
| 35 | + - name: Install the latest version of uv |
| 36 | + uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2 |
| 37 | + with: |
| 38 | + enable-cache: true |
| 39 | + cache-dependency-glob: "uv.lock" |
| 40 | + |
| 41 | + - name: Get merged pull request |
| 42 | + id: getMergedPullRequest |
| 43 | + run: | |
| 44 | + echo "ORIGINAL_PR_URL=$(gh pr list --state merged --json 'mergeCommit,url' --jq '.[] | select(.mergeCommit.oid | contains("${{ github.sha }}")) | .url')" >> "$GITHUB_ENV" |
| 45 | + shell: bash |
| 46 | + env: |
| 47 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + # Bumps the version and automatically locks and syncs. |
| 50 | + - name: Bump version |
| 51 | + id: bump-version |
| 52 | + run: ./scripts/bump-version.sh |
| 53 | + shell: bash |
| 54 | + |
| 55 | + - name: Created signed commit and push tags |
| 56 | + run: | |
| 57 | + set -euxo pipefail |
| 58 | + VERSION="$(uv version --short)" |
| 59 | + readonly VERSION |
| 60 | +
|
| 61 | + # Push commits for the updated files |
| 62 | + for FILE in pyproject.toml uv.lock ; do |
| 63 | + MESSAGE="Update $FILE version to $VERSION" |
| 64 | + SHA=$(git rev-parse "main:$FILE") |
| 65 | + # Create a file with the base64 encoded content |
| 66 | + base64 -i "$FILE" > "base64.txt" |
| 67 | + NEW_COMMIT_SHA=$(gh api --method PUT "/repos/:owner/:repo/contents/$FILE" \ |
| 68 | + --field message="$MESSAGE" \ |
| 69 | + --field content="@base64.txt" \ |
| 70 | + --field encoding="base64" \ |
| 71 | + --field branch="main" \ |
| 72 | + --field sha="$SHA" \ |
| 73 | + --jq '.commit.sha') |
| 74 | + done |
| 75 | +
|
| 76 | + # Set up git user info so we can push a tag |
| 77 | + # botify-app[bot] GitHub App ID can be found here: https://api.github.com/users/botify-app[bot] |
| 78 | + git config --global user.name "botify-app[bot]" |
| 79 | + git config --global user.email "208549588+botify-app[bot]@users.noreply.github.com" |
| 80 | +
|
| 81 | + # Fetch the commit that was made via the API |
| 82 | + git fetch origin main |
| 83 | +
|
| 84 | + # Tag new_commit_sha with our new version |
| 85 | + git tag -a "$VERSION" "$NEW_COMMIT_SHA" -m "$VERSION" |
| 86 | +
|
| 87 | + # Push the new tag |
| 88 | + git push origin tag "$VERSION" |
| 89 | + shell: bash |
| 90 | + env: |
| 91 | + GH_TOKEN: ${{ steps.generateAppToken.outputs.token }} |
| 92 | + |
| 93 | + - name: Comment on PR |
| 94 | + run: | |
| 95 | + gh pr comment ${{ env.ORIGINAL_PR_URL }} --body ":rocket: Released in version $(uv version --short) :rocket:" |
| 96 | + env: |
| 97 | + GH_TOKEN: ${{ steps.generateAppToken.outputs.token }} |
| 98 | + shell: bash |
0 commit comments