Promote Main to Stable #5
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
| # Promote Main to Stable Workflow | |
| # | |
| # Creates a promotional PR to sync the stable branch with main. | |
| # Runs automatically every Sunday night (midnight UTC) and can be triggered manually. | |
| # | |
| # This workflow: | |
| # 1. Checks if stable is behind main | |
| # 2. Creates a PR from main -> stable if there are new changes | |
| # 3. Reuses an existing open PR if one already exists | |
| name: Promote Main to Stable | |
| on: | |
| schedule: | |
| - cron: '0 0 * * 0' # Every Sunday at midnight UTC | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| env: | |
| GH_USER_NAME: github-actions[bot] | |
| GH_USER_EMAIL: github-actions[bot]@users.noreply.github.com | |
| jobs: | |
| promote: | |
| name: Create Promotion PR | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure Git | |
| run: | | |
| git config user.name "${{ env.GH_USER_NAME }}" | |
| git config user.email "${{ env.GH_USER_EMAIL }}" | |
| - name: Promote main to stable | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git fetch origin main stable | |
| DIFF_COUNT=$(git rev-list --count origin/stable..origin/main) | |
| if [ "$DIFF_COUNT" -eq 0 ]; then | |
| echo "stable is already up to date with main. Nothing to promote." | |
| echo "## Promote Main to Stable" >> "$GITHUB_STEP_SUMMARY" | |
| echo "stable is already up to date with main. No PR needed." >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| echo "Found $DIFF_COUNT commit(s) to promote from main to stable." | |
| COMMIT_LOG=$(git log --oneline origin/stable..origin/main --no-merges | head -30) | |
| BODY="Automated promotion of **${DIFF_COUNT} commit(s)** from \`main\` to \`stable\`." | |
| BODY="${BODY}"$'\n\n'"\`\`\`"$'\n'"${COMMIT_LOG}"$'\n'"\`\`\`" | |
| EXISTING_PR=$(gh pr list --base stable --head main --state open --json number --jq '.[0].number // empty') | |
| if [ -n "$EXISTING_PR" ]; then | |
| if ! echo "$BODY" | gh pr edit "$EXISTING_PR" --body-file -; then | |
| echo "::error::Failed to update existing promotion PR #${EXISTING_PR}" | |
| exit 1 | |
| fi | |
| echo "Updated existing promotion PR #${EXISTING_PR}" | |
| else | |
| if ! echo "$BODY" | gh pr create --base stable --head main \ | |
| --title "chore: promote main to stable" \ | |
| --body-file -; then | |
| echo "::error::Failed to create promotion PR" | |
| exit 1 | |
| fi | |
| echo "Created new promotion PR" | |
| fi |