|
| 1 | +name: Weekly release |
| 2 | + |
| 3 | +# Automated weekly version bump and release. |
| 4 | +# |
| 5 | +# Creates a PR to bump version.txt and fstar.opam to the current date, |
| 6 | +# enables auto-merge, waits for CI to pass and the PR to merge, then |
| 7 | +# dispatches the release workflow on the exact merge commit. |
| 8 | +# |
| 9 | +# Requirements: |
| 10 | +# - "Allow auto-merge" must be enabled in repo settings |
| 11 | +# - Branch protection must not require PR reviews (or the bot must |
| 12 | +# be able to satisfy them) |
| 13 | + |
| 14 | +on: |
| 15 | + schedule: |
| 16 | + - cron: '0 12 * * 0' # Every Sunday at noon UTC |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: weekly-release |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: write |
| 25 | + pull-requests: write |
| 26 | + actions: write |
| 27 | + |
| 28 | +jobs: |
| 29 | + bump-and-release: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v6 |
| 33 | + with: |
| 34 | + submodules: true |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Compute new version |
| 38 | + id: version |
| 39 | + run: | |
| 40 | + NEW_VERSION=$(date -u +%Y.%m.%d) |
| 41 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 42 | +
|
| 43 | + git fetch --tags |
| 44 | + if git tag -l "v$NEW_VERSION" | grep -q .; then |
| 45 | + echo "::notice::Version v$NEW_VERSION already released, skipping" |
| 46 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 47 | + else |
| 48 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Close stale auto-bump PRs |
| 52 | + if: steps.version.outputs.skip != 'true' |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ github.token }} |
| 55 | + run: | |
| 56 | + gh pr list --state open --json number,headRefName \ |
| 57 | + -q '.[] | select(.headRefName | startswith("auto/bump-v")) | .number' \ |
| 58 | + | while read -r pr; do |
| 59 | + echo "Closing stale auto-bump PR #$pr" |
| 60 | + gh pr close "$pr" --comment "Superseded by weekly bump to v${{ steps.version.outputs.new_version }}." |
| 61 | + done |
| 62 | +
|
| 63 | + - name: Bump version and create PR |
| 64 | + if: steps.version.outputs.skip != 'true' |
| 65 | + env: |
| 66 | + GH_TOKEN: ${{ secrets.DZOMO_GITHUB_TOKEN }} |
| 67 | + NEW_VERSION: ${{ steps.version.outputs.new_version }} |
| 68 | + run: | |
| 69 | + BRANCH="auto/bump-v$NEW_VERSION" |
| 70 | +
|
| 71 | + git config user.name "Dzomo, the Everest Yak" |
| 72 | + git config user.email "24394600+dzomo@users.noreply.github.com" |
| 73 | +
|
| 74 | + git checkout -b "$BRANCH" |
| 75 | + echo "$NEW_VERSION" > version.txt |
| 76 | + sed -i 's/^version: ".*"/version: "'"$NEW_VERSION"'~dev"/' fstar.opam |
| 77 | + git add version.txt fstar.opam |
| 78 | + git commit -m "Bump version to $NEW_VERSION" |
| 79 | +
|
| 80 | + # Push with PAT so that CI triggers on the PR |
| 81 | + git push "https://${{ secrets.DZOMO_GITHUB_TOKEN }}@github.com/${{ github.repository }}" "$BRANCH" |
| 82 | +
|
| 83 | + gh pr create \ |
| 84 | + --title "Bump version to $NEW_VERSION" \ |
| 85 | + --body "Automated weekly version bump for release v$NEW_VERSION." \ |
| 86 | + --base master \ |
| 87 | + --head "$BRANCH" |
| 88 | +
|
| 89 | + gh pr merge "$BRANCH" --auto --squash |
| 90 | +
|
| 91 | + - name: Wait for PR merge |
| 92 | + if: steps.version.outputs.skip != 'true' |
| 93 | + id: merged |
| 94 | + timeout-minutes: 180 |
| 95 | + env: |
| 96 | + GH_TOKEN: ${{ github.token }} |
| 97 | + run: | |
| 98 | + BRANCH="auto/bump-v${{ steps.version.outputs.new_version }}" |
| 99 | + while true; do |
| 100 | + PR_JSON=$(gh pr view "$BRANCH" --json state,mergeCommit) |
| 101 | + STATE=$(echo "$PR_JSON" | jq -r '.state') |
| 102 | + if [[ "$STATE" == "MERGED" ]]; then |
| 103 | + MERGE_SHA=$(echo "$PR_JSON" | jq -r '.mergeCommit.oid') |
| 104 | + echo "PR merged at $MERGE_SHA" |
| 105 | + echo "merge_sha=$MERGE_SHA" >> "$GITHUB_OUTPUT" |
| 106 | + break |
| 107 | + elif [[ "$STATE" == "CLOSED" ]]; then |
| 108 | + echo "::error::PR was closed without merging" |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | + echo "PR state: $STATE, waiting..." |
| 112 | + sleep 60 |
| 113 | + done |
| 114 | +
|
| 115 | + - name: Delete bump branch |
| 116 | + if: steps.version.outputs.skip != 'true' && steps.merged.outputs.merge_sha != '' |
| 117 | + env: |
| 118 | + GH_TOKEN: ${{ github.token }} |
| 119 | + run: | |
| 120 | + BRANCH="auto/bump-v${{ steps.version.outputs.new_version }}" |
| 121 | + git push origin --delete "$BRANCH" || true |
| 122 | +
|
| 123 | + - name: Trigger release |
| 124 | + if: steps.version.outputs.skip != 'true' |
| 125 | + env: |
| 126 | + GH_TOKEN: ${{ github.token }} |
| 127 | + run: | |
| 128 | + MERGE_SHA="${{ steps.merged.outputs.merge_sha }}" |
| 129 | + echo "Dispatching release.yml for commit $MERGE_SHA" |
| 130 | + gh workflow run release.yml -f target_sha="$MERGE_SHA" |
0 commit comments