GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ci(pr-gate): add owner-gate + hold-gate + native auto-merge · ucloud/ucloud-cli@51ba075

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • pr-gate.yml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/pr-gate.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/pr-gate.yml
+88-37Lines changed: 88 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,118 @@
11
# PR Admission Gate
22
#
3-
# Required status checks (register ALL jobs in repo Settings → Branches → branch protection):
4-
# - scope-gate
5-
# - check-product
6-
# - test
7-
# - build-matrix (6 × platform)
3+
# Required status checks (repo Settings → Branches → branch protection):
4+
# - owner-gate (product-autonomous vs platform verdict; base-version owners)
5+
# - hold-gate (red while a do-not-merge/hold label is present)
6+
# - scope-gate (conventional commit title)
7+
# - check-product (rule1–8 boundary checks)
8+
# - test (build + vet + offline tests)
9+
# - build-matrix (6 × platform)
810
#
9-
# Merge Queue enablement: repo Settings → Merge Queue → "Require merge queue" (Task E9).
11+
# Plus repo Settings → General → "Allow auto-merge" ✓ (and "Allow squash merging"),
12+
# and a branch-protection rule requiring ≥1 approval (the platform-PR human gate).
1013
#
11-
# IMPORTANT: The `merge_group` trigger is required. Without it, required checks stay in
12-
# "Pending" state inside the GitHub Merge Queue and PRs can never be merged.
14+
# Auto-merge: when owner-gate判定 a PR product-autonomous & eligible, the
15+
# auto-merge job runs `gh pr merge --auto`. GitHub merges only once ALL required
16+
# checks above are green and required approvals are met — so a red hold-gate
17+
# (hold label) or a failing test keeps the PR un-merged (fail-closed).
18+
#
19+
# Merge-queue note: the `merge_group` trigger is kept so check-product/test/
20+
# build-matrix can report inside a queue if one is enabled later (ROADMAP §5).
1321

1422
name: PR Gate
1523

1624
on:
1725
pull_request:
18-
merge_group: # REQUIRED — without this, checks stay pending in the merge queue
26+
merge_group:
1927

2028
permissions:
2129
contents: read
22-
pull-requests: write # for the gate bot to comment
30+
pull-requests: write
2331

2432
jobs:
2533
scope-gate:
26-
# Fast structural judgment. Only meaningful on pull_request events.
34+
# Conventional commit title only. Product/platform/cross-product/owner
35+
# routing now lives in owner-gate (Go, base-version aware).
2736
if: github.event_name == 'pull_request'
2837
runs-on: ubuntu-latest
2938
steps:
30-
- uses: actions/checkout@v4
31-
with: { fetch-depth: 0 }
32-
- name: Check scope, conventional title, protected paths
39+
- name: Conventional commit title
3340
env:
3441
PR_TITLE: ${{ github.event.pull_request.title }}
35-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
36-
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
3742
run: |
3843
set -euo pipefail
39-
FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
40-
echo "Changed files:"; echo "$FILES"
41-
42-
# Protected paths require platform review (cannot be auto-admitted).
43-
PROTECTED='^(\.github/workflows/|hack/|pkg/|go\.mod$|go\.sum$|\.goreleaser\.yaml$|\.svu\.yaml$)'
44-
touches_protected=$(echo "$FILES" | grep -E "$PROTECTED" || true)
45-
46-
# Product scope: all changed files under a single products/<name>/ ?
47-
products_touched=$(echo "$FILES" | grep -E '^products/' | sed -E 's#^products/([^/]+)/.*#\1#' | sort -u || true)
48-
n_products=$(echo "$products_touched" | grep -c . || true)
49-
50-
# Conventional commit title check (feat|fix|refactor|build|ci|docs|test|chore|perf, optional scope).
5144
if ! echo "$PR_TITLE" | grep -qE '^(feat|fix|refactor|build|ci|docs|test|chore|perf)(\([a-z0-9_-]+\))?!?: .+'; then
5245
echo "::error::PR title is not a conventional commit: $PR_TITLE"
5346
exit 1
5447
fi
48+
echo "scope-gate: conventional title OK"
5549
56-
if [ -n "$touches_protected" ]; then
57-
echo "::notice::PR touches protected/platform paths — requires platform review (not auto-admit)."
58-
elif [ "$n_products" -gt 1 ]; then
59-
echo "::error::PR touches multiple products ($products_touched) — split into per-product PRs."
60-
exit 1
50+
owner-gate:
51+
# Decides product-autonomous (auto-merge) vs platform (human approval) and
52+
# surfaces the reason to the PR. Green on a successful judgment — eligibility
53+
# is consumed by the auto-merge job; routing is not a failure.
54+
if: github.event_name == 'pull_request'
55+
runs-on: ubuntu-latest
56+
outputs:
57+
auto_merge: ${{ steps.gate.outputs.autoMergeEligible }}
58+
steps:
59+
- uses: actions/checkout@v4
60+
with: { fetch-depth: 0 } # need base+head for git diff / git show
61+
- uses: actions/setup-go@v5
62+
with: { go-version: '1.25' }
63+
- name: Judge admission
64+
id: gate
65+
env:
66+
OWNER_GATE_AUTHOR: ${{ github.event.pull_request.user.login }}
67+
OWNER_GATE_BASE_SHA: ${{ github.event.pull_request.base.sha }}
68+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
69+
GOPROXY: 'https://goproxy.cn,direct'
70+
run: |
71+
set -euo pipefail
72+
git diff --name-status "$OWNER_GATE_BASE_SHA" "$HEAD_SHA" \
73+
| go run ./hack/owner-gate
74+
- name: Post verdict to PR (sticky comment)
75+
env:
76+
GH_TOKEN: ${{ github.token }}
77+
REASON: ${{ steps.gate.outputs.reason }}
78+
PR: ${{ github.event.pull_request.number }}
79+
run: |
80+
set -euo pipefail
81+
MARKER='<!-- owner-gate-verdict -->'
82+
BODY="$MARKER"$'\n'"$REASON"
83+
ID=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" \
84+
--jq "map(select(.body|startswith(\"$MARKER\")))|.[0].id // empty")
85+
if [ -n "$ID" ]; then
86+
gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$ID" -f body="$BODY" >/dev/null
87+
else
88+
gh api -X POST "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -f body="$BODY" >/dev/null
6189
fi
90+
echo "$REASON"
91+
92+
hold-gate:
93+
# /hold emergency brake: red while the PR carries do-not-merge/hold, which
94+
# blocks auto-merge via branch protection without dropping approvals.
95+
if: github.event_name == 'pull_request'
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Fail if on hold
99+
if: contains(github.event.pull_request.labels.*.name, 'do-not-merge/hold')
100+
run: |
101+
echo "::error::PR is on hold (do-not-merge/hold label present) — remove the label to allow merge."
102+
exit 1
103+
- run: echo "hold-gate - not on hold"
62104

63-
echo "scope-gate passed"
105+
auto-merge:
106+
# Native GitHub auto-merge. Enabled only for product-autonomous eligible PRs;
107+
# GitHub enforces required checks + approval before the actual merge.
108+
if: github.event_name == 'pull_request' && needs.owner-gate.outputs.auto_merge == 'true'
109+
needs: [owner-gate]
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: Enable auto-merge
113+
env:
114+
GH_TOKEN: ${{ github.token }}
115+
run: gh pr merge --auto --squash "${{ github.event.pull_request.number }}" --repo "$GITHUB_REPOSITORY"
64116

65117
check-product:
66118
runs-on: ubuntu-latest
@@ -72,9 +124,8 @@ jobs:
72124
env: { GOPROXY: 'https://goproxy.cn,direct' }
73125

74126
test:
75-
# NOTE: Only OFFLINE-safe packages are tested here.
76-
# The `cmd` integration tests hit a live UCloud API and are excluded.
77-
# Run `go test ./cmd/...` manually or in a separate protected environment with credentials.
127+
# NOTE: Only OFFLINE-safe packages. The `cmd` integration tests hit a live
128+
# UCloud API and are excluded; run `go test ./cmd/...` separately with creds.
78129
runs-on: ubuntu-latest
79130
steps:
80131
- uses: actions/checkout@v4

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.