Files
carbon-lang/.github/workflows/check_dependent_pr.yaml
T
Chandler Carruth b7ea32c3a4 Support re-checking, overriding, and requiring the PR dependency check (#8120)
There are a world of reasons why the dependent state check can be wrong
or get stuck. We need ways to manually override inaccurate findings or
trigger a re-check when things change.

Overriding: removing the `dependent` label causes the job to run and
immediately report success to unblock merging. The `workflow_dispatch`
can also run with an `override` mode. This requires adding more tracked
state in the form of _ignored_ PRs that would otherwise be considered
dependencies.

Re-checking: the job now makes the status have a `Details` link that can
be used to re-run it, and editing the PR description also re-runs it.
However, adding the `dependent` label or doing an explicit
`workflow_dispatch` with mode `recheck` goes further: it drops any
overrides and recomputes the open dependencies from the current commits,
keeping the record of merged dependencies.

Hiding the comment still clears _all_ of the tracked state for the PR,
so the next check starts completely from scratch.

Lastly, this extends the workflow to support being marked as required by
letting it run in the merge queue and report success.

Works to keep the changes to `_process_pr` organized so that we first
collect and analyze the state, and only at the end mutate the PR's state
to the new configuration. Adds relevant unit tests for the new features.
Also added some basic documentation of this so that folks have a
reference when it has issues.

I considered the alternative of parsing mentions out of comments
(dependabot-style), but it ended up significantly more complicated and
brittle, so instead went with basing each change on an operation on the
PR that is already mechanically available.

Assisted-by: Antigravity with Opus
2026-11-13 05:19:44 +00:00

131 lines
4.8 KiB
YAML

# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
name: 'Check Dependent PRs'
on:
# zizmor: ignore[dangerous-triggers] - {necessary to mutate the PR}
pull_request_target:
# Beyond code pushes and PR closes:
# - `reopened` refreshes status when a closed PR is reopened.
# - `edited` lets authors trigger a re-check by editing the PR description.
# - `labeled` / `unlabeled` let contributors with write access force a
# re-check (by adding `dependent`) or override a stale check (by removing
# `dependent`).
types:
- opened
- reopened
- synchronize
- ready_for_review
- edited
- labeled
- unlabeled
- closed
# Required checks on `trunk` must also report `success` on merge queue
# commits; PR dependencies are already verified prior to queueing.
merge_group:
# Allow manually checking, re-checking, overriding, or scanning from Actions.
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to check (empty to scan dependent PRs)'
required: false
type: number
mode:
description: 'Mode when pr_number is provided'
required: false
type: choice
default: check
options: [check, recheck, override]
# Isolate concurrency by merge_group commit, closed-PR scan, or PR number, and
# avoid cancelling in-progress runs so rapid events (such as toggling labels or
# landing stacked PRs) cannot leave a required check unset or skip a scan.
concurrency:
group: >-
${{ github.workflow }}-${{
github.event.merge_group.head_sha ||
(github.event.action == 'closed' && 'scan') ||
github.event.pull_request.number ||
inputs.pr_number ||
'scan'
}}
cancel-in-progress: false
permissions:
contents: read
pull-requests: write
statuses: write
jobs:
check_dependent_prs:
# Ignore label events for labels other than `dependent`, and ignore label
# changes made by this workflow itself to prevent self-triggering loops.
if: |
!contains(fromJSON('["labeled", "unlabeled"]'), github.event.action) ||
(
github.event.label.name == 'dependent' &&
github.actor != 'github-actions[bot]'
)
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
disable-sudo: true
egress-policy: block
# prettier-ignore
allowed-endpoints: >
api.github.com:443
files.pythonhosted.org:443
github.com:443
pypi.org:443
raw.githubusercontent.com:443
releases.astral.sh:443
- name: Report success for merge queue
if: github.event_name == 'merge_group'
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.merge_group.head_sha }}
run: |
run_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
gh api "repos/$GITHUB_REPOSITORY/statuses/$HEAD_SHA" \
-f state=success \
-f context='PR dependencies check' \
-f description='Checked prior to merge queue' \
-f target_url="$run_url"
# Note: pull_request_target checks out the base branch by default.
# This is safe as it avoids running untrusted code from the PR branch.
- name: Checkout code
if: github.event_name != 'merge_group'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up uv
if: github.event_name != 'merge_group'
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
enable-cache: true
version: '0.11.15'
- name: Check Dependent PR
if: github.event_name != 'merge_group'
env:
DISPATCH_MODE: ${{ inputs.mode }}
EVENT_ACTION: ${{ github.event.action }}
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}
run: |
if [ "$EVENT_ACTION" = "closed" ] || [ -z "$PR_NUMBER" ]; then
./github_tools/check_dependent_pr.py --scan
elif [ "$EVENT_ACTION" = "unlabeled" ] || [ "$DISPATCH_MODE" = "override" ]; then
./github_tools/check_dependent_pr.py --pr-number "${PR_NUMBER}" --override
elif [ "$EVENT_ACTION" = "labeled" ] || [ "$DISPATCH_MODE" = "recheck" ]; then
./github_tools/check_dependent_pr.py --pr-number "${PR_NUMBER}" --recheck
else
./github_tools/check_dependent_pr.py --pr-number "${PR_NUMBER}"
fi