Repository navigation
Confine asset servlet paths to the resource root (#38590) #1
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
| # Copyright 2026 Collate | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # The queue ref is deleted on dequeue; its commit is not, so check runs are | |
| # read from the commit rather than the branch. | |
| # Must stay pull_request_target — pull_request gets a read-only token on fork | |
| # PRs and cannot comment. Safe only while nothing checks out PR code. | |
| # | |
| # Conflict labels. GitHub builds each entry on main + every entry ahead and | |
| # removes it with MERGE_CONFLICT if that fails, even when it applies cleanly to | |
| # main and the entry it hit is about to fail. So a MERGE_CONFLICT dequeue is | |
| # labelled by what it conflicts with: `merge conflict` (latest main — rebase) | |
| # or `queue conflict` (only an entry ahead — re-queue once that one leaves). | |
| # GitHub only builds the first few entries, so a QUEUED entry further back that | |
| # starts conflicting with main would wait its turn and burn a full CI run | |
| # before failing; evict-main-conflicts removes it on the merge that caused it. | |
| # Both labels clear when the PR is pushed to or re-queued. | |
| # ADR:2026-10-13-merge-queue-conflicts-are-labelled-and-main-conflicts-evicted | |
| name: Merge Queue Dequeue Report | |
| on: | |
| pull_request_target: | |
| types: [dequeued, enqueued, synchronize] | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| pr: | |
| description: PR number to report on | |
| required: true | |
| type: number | |
| dequeue: | |
| description: Which dequeue to report on, counted back from the latest (1) | |
| type: number | |
| default: 1 | |
| dry_run: | |
| description: Print to the job summary instead of commenting on the PR | |
| type: boolean | |
| default: true | |
| permissions: | |
| actions: read | |
| checks: read | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| report: | |
| name: Report dequeue cause | |
| if: ${{ github.event_name == 'workflow_dispatch' || (github.event.action == 'dequeued' && !github.event.pull_request.merged) }} | |
| runs-on: ubuntu-latest | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| OWNER: ${{ github.repository_owner }} | |
| REPO: ${{ github.event.repository.name }} | |
| PR: ${{ github.event.number || inputs.pr }} | |
| DEQUEUE: ${{ inputs.dequeue || 1 }} | |
| BASE_REF: ${{ github.event.repository.default_branch }} | |
| DRY_RUN: ${{ inputs.dry_run == true || vars.MQ_REPORT_DRY_RUN == 'true' }} | |
| SLACK_CHANNEL: C0AC5T013V1 # #ci-cleanup | |
| steps: | |
| # pull_request_target checks out the trusted base, never the PR head. | |
| - uses: actions/checkout@v7 | |
| with: | |
| persist-credentials: false | |
| - name: Resolve the dequeue event | |
| id: event | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| # Only a first-ever dequeue can return an empty list; a repeat dequeue | |
| # matches at once, and its createdAt in the comment exposes a stale read. | |
| # shellcheck disable=SC2016 # the GraphQL query and jq filter must not expand | |
| for _ in 1 2 3; do | |
| gh api graphql -f owner="$OWNER" -f repo="$REPO" -F pr="$PR" -F last="$DEQUEUE" -f query=' | |
| query($owner: String!, $repo: String!, $pr: Int!, $last: Int!) { | |
| repository(owner: $owner, name: $repo) { | |
| pullRequest(number: $pr) { | |
| timelineItems(last: $last, itemTypes: [REMOVED_FROM_MERGE_QUEUE_EVENT]) { | |
| nodes { | |
| ... on RemovedFromMergeQueueEvent { | |
| reason | |
| createdAt | |
| beforeCommit { oid } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }' --jq '.data.repository.pullRequest.timelineItems.nodes | |
| | select(length == ($ENV.DEQUEUE | tonumber)) | .[0] | |
| | select(.reason != null) | |
| | "\(.reason)\t\(.beforeCommit.oid // "")\t\(.createdAt)"' > event.tsv || true | |
| if [ -s event.tsv ]; then | |
| case "$(cut -f1 event.tsv)" in | |
| manual|MANUAL) | |
| echo "Manual removal; skipping notifications." | |
| exit 0 | |
| ;; | |
| esac | |
| { | |
| echo "reason=$(cut -f1 event.tsv)" | |
| echo "sha=$(cut -f2 event.tsv)" | |
| echo "created=$(cut -f3 event.tsv)" | |
| } >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| sleep 5 | |
| done | |
| # A dispatch replaying an older dequeue must find it, never report another. | |
| if [ "$DEQUEUE" != 1 ]; then | |
| echo "::error::PR #$PR has no dequeue $DEQUEUE back from the latest (1-100)." | |
| exit 1 | |
| fi | |
| echo "No RemovedFromMergeQueueEvent found for PR #$PR — nothing to report." | |
| - name: Label what the entry conflicts with | |
| if: ${{ steps.event.outputs.reason == 'MERGE_CONFLICT' }} | |
| # Labelling is extra; a failure here must not skip the comment and | |
| # the #ci-cleanup alert that follow. | |
| continue-on-error: true | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| # GitHub computes mergeability against the base lazily: the first | |
| # read can be UNKNOWN while it works it out in the background. | |
| state=UNKNOWN | |
| for _ in 1 2 3 4 5 6; do | |
| # shellcheck disable=SC2016 # the GraphQL query must not expand | |
| state=$(gh api graphql -f owner="$OWNER" -f repo="$REPO" -F pr="$PR" -f query=' | |
| query($owner: String!, $repo: String!, $pr: Int!) { | |
| repository(owner: $owner, name: $repo) { pullRequest(number: $pr) { mergeable } } | |
| }' --jq '.data.repository.pullRequest.mergeable') | |
| [ "$state" != "UNKNOWN" ] && break | |
| sleep 10 | |
| done | |
| case "$state" in | |
| CONFLICTING) | |
| label="merge conflict" | |
| echo "Conflicts with the latest \`$BASE_REF\` — rebase, then re-queue." > conflict.txt ;; | |
| MERGEABLE) | |
| label="queue conflict" | |
| echo "Applies cleanly to the latest \`$BASE_REF\`; it conflicted only with an entry ahead in the queue. Re-queue once that entry has merged or left the queue." > conflict.txt ;; | |
| *) | |
| echo "Mergeability against $BASE_REF still UNKNOWN; leaving the PR unlabelled." | |
| exit 0 ;; | |
| esac | |
| if [ "$DRY_RUN" = "true" ]; then | |
| echo "Would label PR #$PR: $label" >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| gh label create "merge conflict" --color B60205 --force \ | |
| --description "Conflicts with the latest main; removed from the merge queue" | |
| gh label create "queue conflict" --color FBCA04 --force \ | |
| --description "Conflicted only with an entry ahead in the merge queue" | |
| gh pr edit "$PR" --add-label "$label" | |
| fi | |
| - name: Comment the checks that caused the dequeue | |
| if: ${{ steps.event.outputs.reason != '' }} | |
| shell: bash | |
| env: | |
| REASON: ${{ steps.event.outputs.reason }} | |
| SHA: ${{ steps.event.outputs.sha }} | |
| CREATED: ${{ steps.event.outputs.created }} | |
| run: | | |
| set -euo pipefail | |
| : > tests.txt | |
| # The Playwright summary leaves its failed tests in one annotation rather | |
| # than alerting itself (a failed run does not always dequeue its PR), so | |
| # this report is the queue's only #ci-cleanup alert. | |
| if [ -n "$SHA" ]; then | |
| # shellcheck disable=SC2016 # the jq filter must not expand | |
| gh api "repos/$GH_REPO/commits/$SHA/check-runs?check_name=playwright-summary" \ | |
| --jq '.check_runs[].id' | while read -r id; do | |
| gh api "repos/$GH_REPO/check-runs/$id/annotations" \ | |
| --jq '.[] | select(.title == "Merge queue failed tests") | .message' | |
| done | sed '/^$/d' | sort -u > tests.txt || true | |
| fi | |
| # Only reads GitHub; writes the PR comment and the #ci-cleanup payload. | |
| python3 .github/scripts/merge_queue_dequeue.py \ | |
| --repo "$GH_REPO" --pr "$PR" --branch "$BASE_REF" \ | |
| --queue "merge queue" --reason "$REASON" \ | |
| --sha "$SHA" --created "$CREATED" --failed-tests tests.txt \ | |
| --channel "$SLACK_CHANNEL" --body body.md --slack slack.json | |
| # PR comment only: the #ci-cleanup message stays as it was. | |
| if [ -s conflict.txt ]; then | |
| { echo; cat conflict.txt; } >> body.md | |
| fi | |
| if [ "$DRY_RUN" = "true" ]; then | |
| cat body.md >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| gh pr comment "$PR" --body-file body.md | |
| fi | |
| # A dequeue holds up everyone behind it in the queue, so the channel gets | |
| # the same report the PR does. Slack must never fail the report, hence | |
| # continue-on-error; `errors: true` still surfaces the API error in the log. | |
| - name: "Ping #ci-cleanup" | |
| if: ${{ steps.event.outputs.reason != '' && env.DRY_RUN != 'true' }} | |
| continue-on-error: true | |
| uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0 | |
| with: | |
| method: chat.postMessage | |
| token: ${{ secrets.COLLATE_BOT_SLACK_TOKEN }} | |
| # Keep on — the action discards Slack API errors by default. | |
| errors: true | |
| payload-file-path: slack.json | |
| # Only reacts to PRs that carry a conflict label, so the frequent | |
| # synchronize events skip without taking a runner. | |
| clear-conflict-labels: | |
| if: >- | |
| ${{ (github.event.action == 'enqueued' || github.event.action == 'synchronize') | |
| && (contains(github.event.pull_request.labels.*.name, 'merge conflict') | |
| || contains(github.event.pull_request.labels.*.name, 'queue conflict')) }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| PR: ${{ github.event.number }} | |
| steps: | |
| - name: Clear conflict labels | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| gh pr edit "$PR" --remove-label "merge conflict" --remove-label "queue conflict" | |
| evict-main-conflicts: | |
| if: ${{ github.event_name == 'push' }} | |
| # A newer merge re-checks every entry anyway. | |
| concurrency: | |
| group: merge-queue-evict-main-conflicts | |
| cancel-in-progress: true | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| OWNER: ${{ github.repository_owner }} | |
| REPO: ${{ github.event.repository.name }} | |
| BASE_REF: ${{ github.event.repository.default_branch }} | |
| DRY_RUN: ${{ vars.MQ_REPORT_DRY_RUN == 'true' }} | |
| MERGED_SHA: ${{ github.sha }} | |
| steps: | |
| - name: Remove queue entries that conflict with main | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| # Only QUEUED entries: GitHub builds the rest on main + entries ahead | |
| # and removes them itself on a conflict (it also reports them | |
| # UNKNOWN while building). Mergeability is computed lazily after main | |
| # moves; re-read until none is UNKNOWN, leave any still UNKNOWN for | |
| # the next merge. | |
| for _ in 1 2 3 4 5 6; do | |
| # shellcheck disable=SC2016 # the GraphQL query must not expand | |
| gh api graphql -f owner="$OWNER" -f repo="$REPO" -f branch="$BASE_REF" -f query=' | |
| query($owner: String!, $repo: String!, $branch: String!) { | |
| repository(owner: $owner, name: $repo) { | |
| mergeQueue(branch: $branch) { | |
| entries(first: 100) { | |
| nodes { position state pullRequest { id number mergeable } } | |
| } | |
| } | |
| } | |
| }' --jq '.data.repository.mergeQueue.entries.nodes[] | |
| | select(.state == "QUEUED") | |
| | [.pullRequest.id, .pullRequest.number, .pullRequest.mergeable, .position] | |
| | @tsv' > entries.tsv | |
| grep -q $'\tUNKNOWN\t' entries.tsv || break | |
| sleep 10 | |
| done | |
| echo "queued entries (id, pr, mergeable, position):" | |
| cat entries.tsv | |
| evicted=0 | |
| while IFS=$'\t' read -r id pr state position; do | |
| [ "$state" = "CONFLICTING" ] || continue | |
| evicted=$((evicted + 1)) | |
| echo "evict #$pr (position $position)" | |
| if [ "$DRY_RUN" = "true" ]; then | |
| continue | |
| fi | |
| # shellcheck disable=SC2016 # the GraphQL mutation must not expand | |
| gh api graphql -f id="$id" -f query=' | |
| mutation($id: ID!) { dequeuePullRequest(input: {id: $id}) { clientMutationId } }' \ | |
| --silent || { echo "::warning::could not dequeue #$pr"; continue; } | |
| # The dequeue already happened; a label or comment failure must not | |
| # stop the loop before the remaining entries. | |
| gh label create "merge conflict" --color B60205 --force \ | |
| --description "Conflicts with the latest main; removed from the merge queue" \ | |
| || echo "::warning::could not create the merge conflict label" | |
| gh pr edit "$pr" --add-label "merge conflict" \ | |
| || echo "::warning::could not label #$pr" | |
| gh pr comment "$pr" --body "### 🚦 Removed from the merge queue — conflicts with \`$BASE_REF\` | |
| This PR (queue position $position) stopped merging cleanly into \`$BASE_REF\` at ${MERGED_SHA:0:7}, so it was removed before it was built. Rebase on \`$BASE_REF\`, then re-queue." \ | |
| || echo "::warning::could not comment on #$pr" | |
| done < entries.tsv | |
| { | |
| echo "### Merge-queue entries conflicting with \`$BASE_REF\`" | |
| echo | |
| echo "| | |" | |
| echo "|---|---|" | |
| echo "| dry run | \`${DRY_RUN}\` |" | |
| echo "| queued entries checked | $(wc -l < entries.tsv | tr -d ' ') |" | |
| echo "| evicted | ${evicted} |" | |
| } >> "$GITHUB_STEP_SUMMARY" |