Skip to content

Commit 9cb1d6b

Browse files
committed
chore: add alpha canary CI workflow
Adds a workflow that pulls next into the canary PR when bootstrap.sh or ci3/ files change. Includes CI running check to avoid duplicate runs.
1 parent 71ffa49 commit 9cb1d6b

File tree

3 files changed

+173
-1
lines changed

3 files changed

+173
-1
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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

ci3/bootstrap_ec2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ container_script=$(
188188
case \$code in
189189
155) ;;
190190
0) log_ci_run PASSED \$ci_log_id ;;
191-
*) log_ci_run FAILED \$ci_log_id && merge_train_failure_slack_notify \$ci_log_id ;;
191+
*) log_ci_run FAILED \$ci_log_id && merge_train_failure_slack_notify \$ci_log_id && release_canary_slack_notify \$ci_log_id ;;
192192
esac
193193
exit \$code
194194
EOF

ci3/release_canary_slack_notify

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
# Sends Slack notification for alpha team canary CI failures.
5+
# Called from ci3/bootstrap_ec2 on CI failure.
6+
#
7+
# Usage: alpha_team_canary_slack_notify <ci_log_id>
8+
#
9+
# Environment variables:
10+
# SLACK_BOT_TOKEN - Required for sending Slack messages
11+
# PR_HEAD_REF - Branch name (set for PR runs)
12+
# REF_NAME - Git ref name (set for tag runs)
13+
14+
ALPHA_CANARY_BRANCH="ad/chore/ci-release-pr-canary"
15+
16+
# Determine if this is an alpha canary run:
17+
# 1. PR run on the canary branch
18+
# 2. Release tag (v0.0.1-commit.*) where the commit is on the canary branch
19+
is_alpha_canary=false
20+
21+
if [[ "${PR_HEAD_REF:-}" == "$ALPHA_CANARY_BRANCH" ]]; then
22+
# Case 1: Direct PR run on the canary branch
23+
is_alpha_canary=true
24+
elif [[ "${REF_NAME:-}" =~ ^v0\.0\.1-commit\. ]]; then
25+
# Case 2: Release tag from ci-release-pr label - check if commit is on canary branch
26+
if git fetch --depth=50 origin "$ALPHA_CANARY_BRANCH" 2>/dev/null && \
27+
git merge-base --is-ancestor HEAD FETCH_HEAD 2>/dev/null; then
28+
is_alpha_canary=true
29+
fi
30+
fi
31+
32+
if [[ "$is_alpha_canary" != "true" ]]; then
33+
exit 0
34+
fi
35+
36+
ci_log_id=${1:-}
37+
38+
send_slack_message() {
39+
local message=$1
40+
if [[ -z "${SLACK_BOT_TOKEN:-}" ]]; then
41+
echo "SLACK_BOT_TOKEN not set, skipping notification"
42+
return 0
43+
fi
44+
45+
local data=$(cat <<EOF
46+
{
47+
"channel": "#alpha-team",
48+
"text": "$message"
49+
}
50+
EOF
51+
)
52+
curl -s -X POST https://slack.com/api/chat.postMessage \
53+
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
54+
-H "Content-type: application/json" \
55+
--data "$data"
56+
}
57+
58+
set -x
59+
60+
send_slack_message "CI failed on alpha team canary (ci-release-pr): http://ci.aztec-labs.com/$ci_log_id"

0 commit comments

Comments
 (0)