mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-10-21 06:11:31 +08:00
70 lines
2.4 KiB
YAML
70 lines
2.4 KiB
YAML
name: PR Gate
|
|
description: >
|
|
Resolve PR metadata for a `pull-request/<N>` push from copy-pr-bot and decide
|
|
whether the workflow should run. Sets `should-run=true` only when the pushed
|
|
SHA still matches the PR head SHA. If `required_label` is provided, the PR
|
|
must also carry that label. For non-`push` events (e.g. `workflow_dispatch`
|
|
and `merge_group`), always sets `should-run=true`.
|
|
|
|
inputs:
|
|
required_label:
|
|
description: Optional PR label required to enable the run (e.g. "test:e2e").
|
|
required: false
|
|
default: ""
|
|
|
|
outputs:
|
|
should_run:
|
|
description: "true if the workflow should proceed, false otherwise"
|
|
value: ${{ steps.gate.outputs.should_run }}
|
|
labels_json:
|
|
description: "JSON array of PR label names for push-triggered mirror runs, or [] otherwise"
|
|
value: ${{ steps.gate.outputs.labels_json }}
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- id: get_pr_info
|
|
if: github.event_name == 'push'
|
|
continue-on-error: true
|
|
uses: nv-gha-runners/get-pr-info@090577647b8ddc4e06e809e264f7881650ecdccf # main
|
|
|
|
- id: gate
|
|
shell: bash
|
|
env:
|
|
EVENT_NAME: ${{ github.event_name }}
|
|
GITHUB_SHA_VALUE: ${{ github.sha }}
|
|
GET_PR_INFO_OUTCOME: ${{ steps.get_pr_info.outcome }}
|
|
PR_INFO: ${{ steps.get_pr_info.outputs.pr-info }}
|
|
REQUIRED_LABEL: ${{ inputs.required_label }}
|
|
run: |
|
|
if [ "$EVENT_NAME" != "push" ]; then
|
|
echo "labels_json=[]" >> "$GITHUB_OUTPUT"
|
|
echo "should_run=true" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$GET_PR_INFO_OUTCOME" != "success" ]; then
|
|
echo "labels_json=[]" >> "$GITHUB_OUTPUT"
|
|
echo "should_run=false" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
head_sha="$(jq -r '.head.sha' <<< "$PR_INFO")"
|
|
labels_json="$(jq -c '[.labels[].name]' <<< "$PR_INFO")"
|
|
if [ -z "$REQUIRED_LABEL" ]; then
|
|
has_label=true
|
|
else
|
|
has_label="$(jq -r --arg L "$REQUIRED_LABEL" 'index($L) != null' <<< "$labels_json")"
|
|
fi
|
|
|
|
# Only trust copied pull-request/* pushes that still match the PR head
|
|
# SHA and, when configured, carry the required label.
|
|
if [ "$head_sha" = "$GITHUB_SHA_VALUE" ] && [ "$has_label" = "true" ]; then
|
|
should_run=true
|
|
else
|
|
should_run=false
|
|
fi
|
|
|
|
echo "labels_json=$labels_json" >> "$GITHUB_OUTPUT"
|
|
echo "should_run=$should_run" >> "$GITHUB_OUTPUT"
|