mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
b74867be73
Use the maintainer label event for the checked PR snapshot and verify it against live metadata. Keep the regular smoke requirement for later revisions and preserve the description and asset checks.
69 lines
3.5 KiB
YAML
69 lines
3.5 KiB
YAML
# What a pull request needs before it can be merged (CONTRIBUTING.md, "What a PR needs to be
|
||
# merged"), checked by scripts/pr_check.py from the PR's description and files: the Tested / Not
|
||
# tested / AI use sections, no small / open-weight model named in AI use, no game data or
|
||
# binaries, and – when it changes the runtime – `xcl-smoke` runs on main and on the PR's head.
|
||
#
|
||
# pull_request_target: the workflow and the checker are main's (a PR cannot change what checks
|
||
# it). Nothing of the PR is checked out or run – only its description and file list are read
|
||
# through the API – so its code never runs with this token.
|
||
name: PR checks
|
||
|
||
on:
|
||
pull_request_target:
|
||
types: [opened, edited, synchronize, reopened, ready_for_review, labeled, unlabeled]
|
||
|
||
permissions:
|
||
contents: read
|
||
pull-requests: read
|
||
|
||
jobs:
|
||
description:
|
||
# A skipped step in a job named PR description would still publish a green
|
||
# result under that name. Give unrelated label events their own check name.
|
||
name: >-
|
||
${{ ((github.event.action == 'labeled' || github.event.action == 'unlabeled') &&
|
||
github.event.label.name != 'test-only') && 'Unrelated label event' || 'PR description' }}
|
||
runs-on: ubuntu-latest
|
||
env:
|
||
UNRELATED_LABEL: >-
|
||
${{ (github.event.action == 'labeled' || github.event.action == 'unlabeled') &&
|
||
github.event.label.name != 'test-only' }}
|
||
steps:
|
||
- name: Record unrelated label event
|
||
if: env.UNRELATED_LABEL == 'true'
|
||
run: echo 'This label does not affect the PR description check.'
|
||
- uses: actions/checkout@v4
|
||
if: env.UNRELATED_LABEL != 'true'
|
||
with:
|
||
ref: ${{ github.event.pull_request.base.sha }}
|
||
sparse-checkout: scripts/pr_check.py
|
||
sparse-checkout-cone-mode: false
|
||
- name: Check the description and files
|
||
if: env.UNRELATED_LABEL != 'true'
|
||
env:
|
||
GH_TOKEN: ${{ github.token }}
|
||
BODY: ${{ github.event.pull_request.body }}
|
||
HEAD: ${{ github.event.pull_request.head.sha }}
|
||
BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||
NUMBER: ${{ github.event.pull_request.number }}
|
||
REPO: ${{ github.repository }}
|
||
TEST_ONLY_APPROVAL: ${{ github.event.action == 'labeled' && github.event.label.name == 'test-only' }}
|
||
run: |
|
||
printf '%s' "$BODY" > body.md
|
||
gh api "repos/$REPO/pulls/$NUMBER/files" --paginate \
|
||
--jq '.[] | [.filename, .status, ((.patch == null) and (.changes == 0)), .sha] | @tsv' > files.tsv
|
||
approval_args=()
|
||
# A retained label does not approve a new revision. Check that the approval
|
||
# still matches the live PR head, target and description on reruns.
|
||
if [ "$TEST_ONLY_APPROVAL" = true ]; then
|
||
current=$(gh api "repos/$REPO/pulls/$NUMBER" \
|
||
--jq '[.head.sha, .base.ref, any(.labels[]; .name == "test-only"), ((.body // "") | @base64)] | @tsv')
|
||
IFS=$'\t' read -r current_head current_base current_label current_body <<< "$current"
|
||
if [ "$current_head" = "$HEAD" ] && [ "$current_base" = "$BASE_REF" ] && \
|
||
[ "$current_label" = true ] && [ "$current_body" = "$(printf '%s' "$BODY" | base64 -w 0)" ]; then
|
||
echo 'Retail smoke check waived for the labeled test-only revision.'
|
||
approval_args=(--test-only)
|
||
fi
|
||
fi
|
||
python3 scripts/pr_check.py --body body.md --head "$HEAD" --files files.tsv --repo "$REPO" "${approval_args[@]}"
|