Skip to content

fix: make sure queries are not made ahead of the anchor block #10815

fix: make sure queries are not made ahead of the anchor block

fix: make sure queries are not made ahead of the anchor block #10815

Workflow file for this run

name: Automatic backport action
on:
pull_request_target:
types: ["labeled", "closed"]
jobs:
label_checker:
name: Check labels
runs-on: ubuntu-latest
outputs:
state: ${{ steps.check.outputs.label_check }}
steps:
- id: check
uses: agilepathway/label-checker@825944377ab3bce1269b38c99b718767e2ca6bbc
with:
prefix_mode: true
any_of: backport-to-
repo_token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
allow_failure: true
- name: Print status
shell: bash
run: 'echo "Label detection status: ${{ steps.check.outputs.label_check }}"'
backport:
needs: [label_checker]
name: Backport PR
if: github.event.pull_request.merged == true && needs.label_checker.outputs.state == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
- name: Extract target branch from labels
id: extract-branch
env:
LABELS_JSON: ${{ toJson(github.event.pull_request.labels.*.name) }}
run: |
LABELS="$LABELS_JSON"
echo "All labels: $LABELS"
# Extract the branch name from backport-to-* label
TARGET_BRANCH=$(echo "$LABELS" | jq -r '.[] | select(startswith("backport-to-")) | sub("backport-to-"; "")')
if [ -z "$TARGET_BRANCH" ]; then
echo "No backport-to-* label found"
exit 1
fi
echo "target_branch=$TARGET_BRANCH" >> $GITHUB_OUTPUT
echo "Target branch: $TARGET_BRANCH"
- name: Run backport script
id: backport
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
run: |
# Kludge. We should write this in Python or not checkout history.
# Bash has an ugly footgun with changing history while running the script.
buffer_script=$(cat ./scripts/backport_to_staging.sh)
bash <(echo "$buffer_script") \
${{ github.event.pull_request.number }} \
${{ steps.extract-branch.outputs.target_branch }}
- name: Comment on original PR (success)
if: steps.backport.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
run: |
TARGET_BRANCH="${{ steps.extract-branch.outputs.target_branch }}"
STAGING_BRANCH="backport-to-${TARGET_BRANCH}-staging"
STAGING_PR=$(gh pr list --base "$TARGET_BRANCH" --head "$STAGING_BRANCH" --json number,url --jq '.[0]')
STAGING_PR_NUMBER=$(echo "$STAGING_PR" | jq -r '.number')
STAGING_PR_URL=$(echo "$STAGING_PR" | jq -r '.url')
gh pr comment "${{ github.event.pull_request.number }}" --body \
"✅ Successfully backported to [$STAGING_BRANCH #$STAGING_PR_NUMBER]($STAGING_PR_URL)."
- name: Comment on original PR (failure)
if: steps.backport.outcome == 'failure'
env:
GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
run: |
TARGET_BRANCH="${{ steps.extract-branch.outputs.target_branch }}"
WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
gh pr comment "${{ github.event.pull_request.number }}" --body \
"❌ Failed to cherry-pick to \`$TARGET_BRANCH\` due to conflicts. (🤖) [View backport run]($WORKFLOW_URL)."
- name: Notify Slack and dispatch ClaudeBox on backport failure
if: steps.backport.outcome == 'failure'
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.number }}
TITLE: ${{ github.event.pull_request.title }}
URL: ${{ github.event.pull_request.html_url }}
AUTHOR: ${{ github.event.pull_request.user.login }}
BRANCH: ${{ steps.extract-branch.outputs.target_branch }}
run: |
# Post single message to #backports, derive permalink from response
TEXT=$(printf '⚠️ Backport failed: <%s|#%s %s> → `%s` (author: %s) (🤖)' \
"$URL" "$PR" "$TITLE" "$BRANCH" "$AUTHOR")
RESP=$(curl -sS -X POST https://slack.com/api/chat.postMessage \
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
-H "Content-type: application/json" \
-d "$(jq -n --arg c "#backports" --arg t "$TEXT" '{channel:$c, text:$t}')")
echo "Slack response: $RESP"
TS=$(echo "$RESP" | jq -r '.ts // empty')
CHANNEL_ID=$(echo "$RESP" | jq -r '.channel // empty')
LINK=""
if [[ -n "$TS" && -n "$CHANNEL_ID" ]]; then
LINK="https://aztecprotocol.slack.com/archives/$CHANNEL_ID/p${TS//./}"
fi
gh workflow run claudebox.yml \
-f prompt="Backport PR #$PR ($TITLE) to $BRANCH. The automatic cherry-pick failed due to conflicts. Follow the backport skill (.claude/skills/backport/SKILL.md) to resolve conflicts and create a PR targeting $BRANCH." \
-f link="${LINK:-$URL}"