Skip to content

[Doc] Align with Branch #73364

[Doc] Align with Branch

[Doc] Align with Branch #73364

Workflow file for this run

name: REVIEW CHECKER
on:
pull_request_review:
types:
- submitted
permissions:
checks: write
actions: write
contents: write
deployments: write
discussions: write
issues: write
packages: write
pages: write
pull-requests: write
repository-projects: write
security-events: write
statuses: write
jobs:
info:
if: >
(github.event.pull_request && github.event.requested_team) ||
(github.event.pull_request.requested_teams && github.event.review && github.event.review.state == 'approved') ||
github.event.review.state == 'approved'
runs-on: ubuntu-latest
env:
REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
PR_NUMBER: ${{ steps.pr.outputs.PR_NUMBER }}
HEAD_REF: ${{ steps.pr.outputs.HEAD_REF }}
BASE_REF: ${{ steps.pr.outputs.BASE_REF }}
TITLE: ${{ steps.pr_info.outputs.title }}
LABELS: ${{ steps.pr_info.outputs.labels }}
DIFF_LINES: ${{ steps.pr_info.outputs.diff_lines }}
SKIP_GLOBAL_REVIEW: ${{ steps.skip_rule.outputs.skip }}
SKIP_GLOBAL_REVIEW_REASON: ${{ steps.skip_rule.outputs.reason }}
steps:
- name: PR
id: pr
run: |
if [[ "${{ github.event.number }}" != "" ]]; then
echo "PR_NUMBER=${{ github.event.number }}" >> $GITHUB_OUTPUT
else
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
echo "HEAD_REF=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT
echo "BASE_REF=${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
fi
- name: INFO
id: pr_info
env:
PR_NUMBER: ${{ steps.pr.outputs.PR_NUMBER }}
run: |
pr_info=$(gh pr view ${PR_NUMBER} -R ${REPO} --json labels,title,files)
labels=$(echo ${pr_info} | jq -r '.labels[].name')
title=$(echo ${pr_info} | jq -r '.title')
diff_lines=$(echo ${pr_info} | jq -r '([.files[].additions, .files[].deletions] | add)')
echo "diff_lines=${diff_lines}" >> $GITHUB_OUTPUT
echo "labels<<EOF" >> $GITHUB_OUTPUT
echo "$labels" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "title<<EOF" >> $GITHUB_OUTPUT
echo "${title}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Compute skip rule
id: skip_rule
env:
PR: ${{ steps.pr.outputs.PR_NUMBER }}
TITLE: ${{ steps.pr_info.outputs.title }}
run: |
set -x
# Skip GLOBAL REVIEW gate for small/test-only PRs to reduce noise.
# Adjust BUGFIX_LINE_THRESHOLD as needed (non-test add+del lines).
BUGFIX_LINE_THRESHOLD=30
TEST_PATTERN='(Test\.(java|kt)$|_test\.(cpp|cc|h)$|/test/|^test/|^fe-test/|^regression-test/|/__test__/)'
skip=false
reason=""
# Rule 1: [UT] / [Doc] title prefix
if echo "$TITLE" | grep -qE '^\[(UT|Doc)\]'; then
skip=true
reason="title prefix [UT] or [Doc]"
fi
# Rule 2: all changed files match test pattern
# Fail-closed: if the metadata query errors out, do NOT apply skip —
# a transient API failure must not bypass the GLOBAL REVIEW gate.
if [ "$skip" = "false" ]; then
files=$(gh pr diff "$PR" -R "$REPO" --name-only 2>/dev/null)
query_status=$?
if [ "$query_status" -ne 0 ]; then
echo "WARN: 'gh pr diff' failed (exit=$query_status); not applying test-only rule"
else
total=$(echo "$files" | grep -cv '^$' || true)
non_test=$(echo "$files" | grep -v '^$' | grep -cvE "$TEST_PATTERN" || true)
if [ "$total" -gt 0 ] && [ "$non_test" -eq 0 ]; then
skip=true
reason="all $total changed files are tests"
fi
fi
fi
# Rule 3: [BugFix] with non-test add+del < threshold
# NOTE: jq's regex needs \\. for a literal dot (the pattern must match TEST_PATTERN above).
# Fail-closed: if the metadata query errors out or returns empty, do NOT apply skip —
# otherwise a transient gh API failure would silently bypass the GLOBAL REVIEW gate.
if [ "$skip" = "false" ] && echo "$TITLE" | grep -qE '^\[BugFix\]'; then
non_test_lines=$(gh pr view "$PR" -R "$REPO" --json files --jq '
[.files[]
| select(.path | test("(Test\\.(java|kt)$|_test\\.(cpp|cc|h)$|/test/|^test/|^fe-test/|^regression-test/|/__test__/)") | not)
| (.additions + .deletions)]
| add // 0
' 2>/dev/null)
query_status=$?
if [ "$query_status" -ne 0 ] || [ -z "$non_test_lines" ]; then
echo "WARN: 'gh pr view --json files' failed (exit=$query_status, output='$non_test_lines'); not applying [BugFix] rule"
elif [ "$non_test_lines" -lt "$BUGFIX_LINE_THRESHOLD" ]; then
skip=true
reason="[BugFix] non-test lines=$non_test_lines < $BUGFIX_LINE_THRESHOLD"
fi
fi
echo "skip=$skip" >> "$GITHUB_OUTPUT"
echo "reason=$reason" >> "$GITHUB_OUTPUT"
echo "=== gate result: skip=$skip, reason='$reason' ==="
meta-review:
needs: info
runs-on: [ self-hosted, normal ]
if: >
github.event_name == 'pull_request_review' &&
contains(needs.info.outputs.LABELS, 'META-REVIEW') &&
!contains(needs.info.outputs.LABELS, 'sync') &&
!startsWith(needs.info.outputs.HEAD_REF, 'mergify/')
name: META-REVIEW
env:
PR_NUMBER: ${{ needs.info.outputs.PR_NUMBER }}
REPO: ${{ github.repository }}
TEAM: meta-committer
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: META-REVIEW
run: |
rm -rf ./ci-tool && cp -rf /var/lib/ci-tool ./ci-tool && cd ci-tool && git pull >/dev/null
./scripts/check-approve.sh
proto-review:
needs: info
runs-on: [ self-hosted, normal ]
if: >
github.event_name == 'pull_request_review' &&
contains(needs.info.outputs.LABELS, 'PROTO-REVIEW') &&
!contains(needs.info.outputs.LABELS, 'sync') &&
!startsWith(needs.info.outputs.HEAD_REF, 'mergify/')
name: PROTO-REVIEW
env:
PR_NUMBER: ${{ needs.info.outputs.PR_NUMBER }}
REPO: ${{ github.repository }}
TEAM: proto-team
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: PROTO-REVIEW
run: |
rm -rf ./ci-tool && cp -rf /var/lib/ci-tool ./ci-tool && cd ci-tool && git pull >/dev/null
./scripts/check-approve.sh
global-review:
needs: info
runs-on: [ self-hosted, normal ]
if: >
github.event_name == 'pull_request_review' &&
needs.info.outputs.BASE_REF == 'main' &&
!contains(needs.info.outputs.LABELS, 'sync') &&
!startsWith(needs.info.outputs.HEAD_REF, 'mergify/')
name: GLOBAL REVIEW
env:
PR_NUMBER: ${{ needs.info.outputs.PR_NUMBER }}
REPO: ${{ github.repository }}
TEAM: global-reviewer
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: GLOBAL REVIEW
env:
SKIP_GLOBAL_REVIEW: ${{ needs.info.outputs.SKIP_GLOBAL_REVIEW }}
SKIP_GLOBAL_REVIEW_REASON: ${{ needs.info.outputs.SKIP_GLOBAL_REVIEW_REASON }}
run: |
if [[ "$SKIP_GLOBAL_REVIEW" == "true" ]]; then
echo "::notice::GLOBAL REVIEW skipped: $SKIP_GLOBAL_REVIEW_REASON"
exit 0
fi
rm -rf ./ci-tool && cp -rf /var/lib/ci-tool ./ci-tool && cd ci-tool && git pull >/dev/null
./scripts/check-approve.sh