|
| 1 | +name: Alpha Team Canary |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - next |
| 7 | + paths: |
| 8 | + # Match any file named bootstrap.sh |
| 9 | + - '**/bootstrap.sh' |
| 10 | + # Anything in ci3 folder |
| 11 | + - 'ci3/**' |
| 12 | + |
| 13 | +env: |
| 14 | + CANARY_BRANCH: ad/chore/ci-release-pr-canary |
| 15 | + PR_TITLE: "no-merge: alpha canary PR" |
| 16 | + PR_LABEL: ci-release-pr |
| 17 | + |
| 18 | +jobs: |
| 19 | + update-canary-pr: |
| 20 | + name: Update alpha team canary PR |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Configure Git |
| 30 | + run: | |
| 31 | + git config --global user.name AztecBot |
| 32 | + git config --global user.email [email protected] |
| 33 | +
|
| 34 | + - name: Ensure canary branch and PR exist |
| 35 | + id: ensure-pr |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} |
| 38 | + run: | |
| 39 | + # Check if branch exists |
| 40 | + if ! git ls-remote --exit-code --heads origin "$CANARY_BRANCH" >/dev/null 2>&1; then |
| 41 | + echo "Creating canary branch from next" |
| 42 | + git checkout -b "$CANARY_BRANCH" origin/next |
| 43 | + git push -u origin "$CANARY_BRANCH" |
| 44 | + fi |
| 45 | +
|
| 46 | + # Check if PR exists |
| 47 | + pr_number=$(gh pr list --state open --head "$CANARY_BRANCH" --json number --jq '.[0].number') |
| 48 | +
|
| 49 | + if [[ -z "$pr_number" ]]; then |
| 50 | + echo "Creating canary PR" |
| 51 | + pr_url=$(gh pr create \ |
| 52 | + --head "$CANARY_BRANCH" \ |
| 53 | + --base next \ |
| 54 | + --title "$PR_TITLE" \ |
| 55 | + --label "$PR_LABEL" \ |
| 56 | + --body "This PR tests certain CI labels periodically. Any failures in this branch log to alpha-team channel with slack. |
| 57 | +
|
| 58 | + This PR is automatically updated when \`**/bootstrap.sh\` or \`ci3/**\` files are pushed to \`next\`. |
| 59 | +
|
| 60 | + **Important:** This PR should never be merged. It exists solely to test the \`ci-release-pr\` label.") |
| 61 | +
|
| 62 | + pr_number=$(gh pr list --state open --head "$CANARY_BRANCH" --json number --jq '.[0].number') |
| 63 | + echo "Created canary PR #$pr_number" |
| 64 | + fi |
| 65 | +
|
| 66 | + echo "pr_number=$pr_number" >> $GITHUB_OUTPUT |
| 67 | +
|
| 68 | + - name: Check if CI is already running |
| 69 | + id: check-ci |
| 70 | + env: |
| 71 | + GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} |
| 72 | + run: | |
| 73 | + pr_number="${{ steps.ensure-pr.outputs.pr_number }}" |
| 74 | +
|
| 75 | + # Check if CI is currently running on this PR |
| 76 | + running_ci=$(gh run list --branch "$CANARY_BRANCH" --workflow ci3.yml --status in_progress --json databaseId --jq 'length') |
| 77 | +
|
| 78 | + if [[ "$running_ci" -gt 0 ]]; then |
| 79 | + echo "CI is already running on canary PR #$pr_number, skipping update" |
| 80 | + echo "skip=true" >> $GITHUB_OUTPUT |
| 81 | + else |
| 82 | + echo "No CI running, proceeding with update" |
| 83 | + echo "skip=false" >> $GITHUB_OUTPUT |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Merge next into canary branch |
| 87 | + if: steps.check-ci.outputs.skip != 'true' |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} |
| 90 | + run: | |
| 91 | + pr_number="${{ steps.ensure-pr.outputs.pr_number }}" |
| 92 | +
|
| 93 | + # Fetch both branches |
| 94 | + git fetch origin "$CANARY_BRANCH" next |
| 95 | +
|
| 96 | + # Checkout the canary branch |
| 97 | + git checkout "$CANARY_BRANCH" |
| 98 | +
|
| 99 | + # Merge next into canary branch |
| 100 | + if git merge origin/next --no-edit -m "Merge branch 'next' into $CANARY_BRANCH"; then |
| 101 | + echo "Successfully merged next into $CANARY_BRANCH" |
| 102 | + git push origin "$CANARY_BRANCH" |
| 103 | + echo "Pushed update to $CANARY_BRANCH" |
| 104 | +
|
| 105 | + # Re-add the ci-release-pr label (it gets removed after each CI run) |
| 106 | + gh pr edit "$pr_number" --add-label "$PR_LABEL" |
| 107 | + echo "Re-added $PR_LABEL label to PR #$pr_number" |
| 108 | + else |
| 109 | + echo "Merge conflict detected, aborting" |
| 110 | + git merge --abort |
| 111 | + exit 1 |
| 112 | + fi |
0 commit comments