fast send first shred #403
Workflow file for this run
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
| name: Trigger Buildkite Pipeline (Pull Request) | ||
|
Check warning on line 1 in .github/workflows/trigger-buildkite-pipeline.yml
|
||
| on: | ||
| pull_request_target: | ||
| branches: | ||
| - master | ||
| types: | ||
| - opened | ||
| - synchronize | ||
| - reopened | ||
| - labeled | ||
| permissions: | ||
| contents: read | ||
| concurrency: | ||
| group: ${{ github.workflow }}-pr-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| member_check: | ||
| runs-on: ubuntu-24.04 | ||
| if: github.repository_owner == 'anza-xyz' && github.event.action != 'labeled' | ||
| outputs: | ||
| should_trigger: ${{ steps.check.outputs.should_trigger }} | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Check permission | ||
| id: check | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| USERNAME: ${{ github.event.sender.login }} | ||
| run: | | ||
| ROLE_NAME=$(curl -sS -L \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer $GH_TOKEN" \ | ||
| -H "X-GitHub-Api-Version: 2026-03-10" \ | ||
| https://api.github.com/repos/$REPO/collaborators/$USERNAME/permission | jq -r ".role_name") | ||
| case "$ROLE_NAME" in | ||
| admin|maintain|write|triage) | ||
| echo "should_trigger=true" >> $GITHUB_OUTPUT | ||
| ;; | ||
| *) | ||
| echo "should_trigger=false" >> $GITHUB_OUTPUT | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| label_check: | ||
| runs-on: ubuntu-24.04 | ||
| if: github.repository_owner == 'anza-xyz' && github.event.action == 'labeled' && github.event.label.name == 'CI' | ||
| outputs: | ||
| should_trigger: ${{ steps.check.outputs.should_trigger }} | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| steps: | ||
| - name: Remove CI label | ||
| id: check | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| echo "should_trigger=true" >> $GITHUB_OUTPUT | ||
| curl -sS -X DELETE \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer $GH_TOKEN" \ | ||
| "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/CI" \ | ||
| || echo "CI label was already removed." | ||
| trigger: | ||
| runs-on: ubuntu-24.04 | ||
| needs: | ||
| - member_check | ||
| - label_check | ||
| if: >- | ||
| always() && | ||
| (needs.member_check.outputs.should_trigger == 'true' || needs.label_check.outputs.should_trigger == 'true') | ||
| permissions: {} | ||
| steps: | ||
| - name: Prepare Buildkite pipeline info | ||
| id: prepare | ||
| env: | ||
| COMMIT: ${{ github.event.pull_request.head.sha }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| COMMIT_SHORT="${COMMIT:0:8}" | ||
| BRANCH="pull/${PR_NUMBER}/head" | ||
| MESSAGE="PR#${PR_NUMBER} - ${COMMIT_SHORT}" | ||
| echo "branch=$BRANCH" | tee -a $GITHUB_OUTPUT | ||
| echo "commit=$COMMIT" | tee -a $GITHUB_OUTPUT | ||
| echo "message=$MESSAGE" | tee -a $GITHUB_OUTPUT | ||
| echo "pr_number=$PR_NUMBER" | tee -a $GITHUB_OUTPUT | ||
| - name: Trigger a Buildkite Build | ||
| id: trigger | ||
| env: | ||
| PORTAL_URL: ${{ secrets.BUILDKITE_PORTAL_URL }} | ||
| PORTAL_TOKEN: ${{ secrets.BUILDKITE_PORTAL_TOKEN }} | ||
| BRANCH: ${{ steps.prepare.outputs.branch }} | ||
| BASE_BRANCH: ${{ github.event.pull_request.base.ref }} | ||
| COMMIT: ${{ steps.prepare.outputs.commit }} | ||
| MESSAGE: ${{ steps.prepare.outputs.message }} | ||
| PR_NUMBER: ${{ steps.prepare.outputs.pr_number }} | ||
| run: | | ||
| PAYLOAD=$(jq -n \ | ||
| --arg commit "$COMMIT" \ | ||
| --arg branch "$BRANCH" \ | ||
| --arg message "$MESSAGE" \ | ||
| --arg prNumber "$PR_NUMBER" \ | ||
| --arg baseEnv "BUILDKITE_PULL_REQUEST_BASE_BRANCH=${BASE_BRANCH}" \ | ||
| '{commit: $commit, branch: $branch, message: $message, prNumber: $prNumber, baseEnv: $baseEnv}') | ||
| HTTP_OK=true | ||
| RESPONSE=$(curl -sS --fail-with-body -X POST "$PORTAL_URL" \ | ||
| -H "Authorization: Bearer $PORTAL_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "$PAYLOAD") || HTTP_OK=false | ||
| echo "$RESPONSE" | jq . || echo "$RESPONSE" | ||
| if [ "$HTTP_OK" != "true" ]; then | ||
| echo "::error::Buildkite portal request failed" | ||
| exit 1 | ||
| fi | ||
| if [ "$(echo "$RESPONSE" | jq 'has("errors")')" = "true" ]; then | ||
| echo "::error::Buildkite portal returned errors" | ||
| exit 1 | ||
| fi | ||
| BUILD_URL=$(echo "$RESPONSE" | jq -r '.data.buildCreate.build.url // empty') | ||
| if [ -z "$BUILD_URL" ]; then | ||
| echo "::error::Buildkite portal response contained no build URL" | ||
| exit 1 | ||
| fi | ||
| echo "build_url=$BUILD_URL" >> $GITHUB_OUTPUT | ||
| - name: Summary | ||
| env: | ||
| BRANCH: ${{ steps.prepare.outputs.branch }} | ||
| BUILD_URL: ${{ steps.trigger.outputs.build_url }} | ||
| COMMIT: ${{ github.event.pull_request.head.sha }} | ||
| MESSAGE: ${{ steps.prepare.outputs.message }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| { | ||
| echo "## Buildkite Pipeline Info" | ||
| echo "" | ||
| echo "| Key | Value |" | ||
| echo "|-----|-------|" | ||
| echo "| Branch | \`$BRANCH\` |" | ||
| echo "| Commit | \`$COMMIT\` |" | ||
| echo "| PR Number | #$PR_NUMBER |" | ||
| echo "| Message | $MESSAGE |" | ||
| echo "| Build | $BUILD_URL |" | ||
| } >> $GITHUB_STEP_SUMMARY | ||