blueprint-shared-templates 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/.github/version-control.md +2 -2
- package/base/scripts/merge/decide.mjs +2 -2
- package/base/scripts/setup/git-hooks.sh +77 -7
- package/ops/scripts/deploy/healthz.sh +1 -1
- package/org/README.md +2 -2
- package/package.json +1 -1
- package/release/.github/workflows/release-please.yml +10 -4
- package/release/scripts/lib/release-stages.sh +81 -63
- package/release/scripts/release/finalize-release.sh +1 -1
- package/release/scripts/release/merge-back-ready.sh +4 -3
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
| `.github/ISSUE_TEMPLATE/*.yml` | bug、feature、hotfix 三種 Issue |
|
|
9
9
|
| `releases/release-plan.md` | 一版一份的發布規劃範本,複製成主檔的 `releases/release-plan-v{X.Y.Z}.md`。維護型發布規劃由 `scripts/release/plan.sh maintenance` 寫出,不從這份範本複製 |
|
|
10
10
|
| `.github/CODEOWNERS.example` | 複製成 `.github/CODEOWNERS`,列出版號與發布相關檔案的審查者。`scripts/hooks/pre-push` 也讀它,推上 main 的變更碰到這些路徑時擋下,改走 PR |
|
|
11
|
-
| `scripts/hooks/commit-msg`、`scripts/hooks/pre-push` | 訊息格式與 AI
|
|
11
|
+
| `scripts/hooks/commit-msg`、`scripts/hooks/pre-push` | 訊息格式與 AI 平台署名的檢查,推送預設分支前再查一次推送範圍的訊息並跑建置測試。`scripts/setup/git-hooks.sh` 在 `.git/hooks/` 放兩個轉呼叫檔交給它們,不設倉內的 `core.hooksPath`,所以機器的全域 hook 照常跑。它由 `pnpm install` 的 `prepare` 執行,使用者在自己的終端機執行(代理執行會被權限規則擋下) |
|
|
12
12
|
| `.github/workflows/main-commit-check.yml` | 每天核對預設分支前一天的 commit 訊息格式與 AI 平台署名,呼叫 `scripts/ci/check-main-commits.sh` |
|
|
13
13
|
| `.github/workflows/pr-message.yml` | PR 標題與內文的同一組檢查,squash 後標題與內文就是 commit 訊息 |
|
|
14
14
|
| `scripts/setup/github-repo-settings.sh`、`scripts/setup/github-repo-settings.json` | 把倉庫鎖定成只允許 squash 合併、合併後刪分支,並設定 Actions 產物與 log 的保留天數。值寫在旁邊的 JSON。可以一次指定多個倉。`--dry-run` 只印要送的請求,套用前先讀現值,已相同的設定不送 |
|
|
15
15
|
|
|
16
16
|
訊息檢查的腳本在 `scripts/ci/`:`check-pr-title.sh`、`check-commit-body.sh`、`check-main-commits.sh` 與 `ai-attribution-list.txt`。
|
|
17
17
|
|
|
18
|
-
`pre-push` 檢查推上 main 的 commit:訊息格式與 AI 平台署名、每個 commit 只動一個發布單元、不碰 `.github/CODEOWNERS` 列的治理路徑、沒有破壞性變更,通過後跑 `scripts/ci/run-affected.sh` 的 lint、build、test
|
|
18
|
+
`pre-push` 檢查推上 main 的 commit:訊息格式與 AI 平台署名、每個 commit 只動一個發布單元、不碰 `.github/CODEOWNERS` 列的治理路徑、沒有破壞性變更,通過後跑 `scripts/ci/run-affected.sh` 的 lint、build、test。轉呼叫檔交給所在工作樹根的 `scripts/hooks/<name>`,所以在 linked worktree 裡跑的是那個 worktree 自己的 hook。機器設了全域 `core.hooksPath` 時,git 只跑全域那組,那組會轉給 `.git/hooks/<name>` 時,倉的 hook 才會跑。
|
|
19
19
|
|
|
20
20
|
每日核對 workflow 的 runner 讀倉庫變數 `LINUX_RUNNER`,沒設時用 self-hosted 的 `self-hosted-linux`。改用其他 runner 時,只要有 git 與 bash 4 就能跑。倉庫沒有 self-hosted runner 時,把 `LINUX_RUNNER` 設成 `ubuntu-latest`。
|
|
21
21
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// has a path filter: when none of the changed files matches, that workflow did not run and the check
|
|
15
15
|
// counts as skipped. reviewPaths are the CODEOWNERS style paths (blueprint-shared.git-flow.review-paths) that need
|
|
16
16
|
// a review; empty or missing means no pull request needs one here. syncPr is { author, branch }: the
|
|
17
|
-
// pull request that
|
|
17
|
+
// pull request that the repository that holds the templates opens in a demonstration repository to bring it up to date, which needs no review.
|
|
18
18
|
// pr also needs author ({ login, is_bot }) and latestReviews ([{ state }]) from `gh pr view --json`.
|
|
19
19
|
// Output: one JSON line { action, reason, ... }. action is "merge", "merge-release-pr" or "skip". A skip because a
|
|
20
20
|
// required check failed also lists those checks in failed.
|
|
@@ -96,7 +96,7 @@ export function decide({ pr, checkedSha, checks = [], changedFiles = [] }, confi
|
|
|
96
96
|
if (missing.length > 0) return skip(`required check has not run: ${missing.join(", ")}`, { pr: number });
|
|
97
97
|
|
|
98
98
|
const release = pr.headRefName.startsWith(RELEASE_PR_HEAD);
|
|
99
|
-
// A change to a review path needs an approving review, except a sync pull request (
|
|
99
|
+
// A change to a review path needs an approving review, except a sync pull request (the pull request that brings a demonstration repository up to date)
|
|
100
100
|
// and a Release PR, which merge-release-pr.sh merges on a machine. The required checks above still have to pass for all of them.
|
|
101
101
|
if (!release && !isSyncPr(pr, config.syncPr) && touchesReviewPath(changedFiles, config.reviewPaths)) {
|
|
102
102
|
const states = (pr.latestReviews ?? []).map((r) => r.state);
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
2
|
+
# Puts forwarding files for commit-msg and pre-push into the repository's common hooks directory
|
|
3
|
+
# ($(git rev-parse --git-common-dir)/hooks, which linked worktrees share). Each one hands its arguments and
|
|
4
|
+
# stdin to scripts/hooks/<name> of the working tree it runs in, which guard the local lane into main, and
|
|
5
|
+
# exits 0 when that file is missing or not executable. Runs from pnpm's prepare on every install, so a fresh
|
|
6
|
+
# clone is guarded without a separate step.
|
|
7
|
+
#
|
|
8
|
+
# The repository's core.hooksPath stays unset: a value there overrides a hooksPath the machine set globally,
|
|
9
|
+
# and the machine's hooks would stop running. A machine that sets a global hooksPath runs only those hooks;
|
|
10
|
+
# the repository's hooks run when those hand over to .git/hooks/<name>. An older version of this script set
|
|
11
|
+
# core.hooksPath to scripts/hooks in the shared config; that exact value is removed, any other value (or one
|
|
12
|
+
# in a worktree's own config) stays and is reported, since it hides the forwarding files. A file of the same
|
|
13
|
+
# name in the hooks directory that this script did not write (no marker on line 2) is left alone and the
|
|
14
|
+
# script exits non-zero. Outside a working tree (a bare repository, an unpacked tarball) it does nothing.
|
|
15
|
+
#
|
|
16
|
+
# A repository that only takes changes through PRs drops the prepare script from package.json and deletes
|
|
17
|
+
# .git/hooks/commit-msg and .git/hooks/pre-push.
|
|
6
18
|
#
|
|
7
19
|
# Also sets commit.cleanup scissors. Messages use "## " section headings (docs/git-flow.md, commit 與 PR
|
|
8
20
|
# 訊息格式); when a message is written in the editor, git's default cleanup (strip) deletes every line
|
|
@@ -10,7 +22,65 @@
|
|
|
10
22
|
# places below a scissors line. Messages given with -m or -F are not edited and keep "#" lines either way.
|
|
11
23
|
# usage: git-hooks.sh
|
|
12
24
|
set -euo pipefail
|
|
13
|
-
|
|
14
|
-
git
|
|
25
|
+
# A bare repository prints false with status 0, so compare the output.
|
|
26
|
+
[[ "$(git rev-parse --is-inside-work-tree 2>/dev/null || true)" == true ]] || exit 0
|
|
27
|
+
|
|
28
|
+
marker='# managed by scripts/setup/git-hooks.sh'
|
|
29
|
+
names="commit-msg pre-push"
|
|
30
|
+
common="$(git rev-parse --path-format=absolute --git-common-dir)"
|
|
31
|
+
hooks="$common/hooks"
|
|
32
|
+
|
|
33
|
+
foreign=""
|
|
34
|
+
for name in $names; do
|
|
35
|
+
file="$hooks/$name"
|
|
36
|
+
if [[ -e "$file" || -L "$file" ]] && [[ "$(sed -n 2p "$file" 2>/dev/null)" != "$marker"* ]]; then
|
|
37
|
+
foreign="$foreign $file"$'\n'
|
|
38
|
+
fi
|
|
39
|
+
done
|
|
40
|
+
if [[ -n "$foreign" ]]; then
|
|
41
|
+
{
|
|
42
|
+
printf '%s\n' "git-hooks.sh:下列檔不是這支腳本放的,沒有覆寫:"
|
|
43
|
+
printf '%s' "$foreign"
|
|
44
|
+
printf '%s\n' "處理方式:確認它的用途,把要保留的檢查併進 scripts/hooks/ 的同名檔後刪掉它,或改由那支檔呼叫 scripts/hooks/<name>,再跑一次 pnpm install。"
|
|
45
|
+
} >&2
|
|
46
|
+
exit 1
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
if [[ "$(git config --file "$common/config" --get core.hooksPath || true)" == scripts/hooks ]]; then
|
|
50
|
+
git config --file "$common/config" --unset core.hooksPath
|
|
51
|
+
printf '%s\n' "git-hooks.sh:移除舊版設的 core.hooksPath=scripts/hooks,改用 ${hooks} 的轉呼叫檔"
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
mkdir -p "$hooks"
|
|
55
|
+
for name in $names; do
|
|
56
|
+
tmp="$hooks/.$name.tmp.$$"
|
|
57
|
+
cat >"$tmp" <<EOF
|
|
58
|
+
#!/bin/sh
|
|
59
|
+
$marker: hands over to scripts/hooks/<name> of the working tree
|
|
60
|
+
top="\$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
|
|
61
|
+
hook="\$top/scripts/hooks/\${0##*/}"
|
|
62
|
+
[ -x "\$hook" ] || exit 0
|
|
63
|
+
exec "\$hook" "\$@"
|
|
64
|
+
EOF
|
|
65
|
+
chmod +x "$tmp"
|
|
66
|
+
mv -f "$tmp" "$hooks/$name"
|
|
67
|
+
done
|
|
68
|
+
|
|
15
69
|
git config commit.cleanup scissors
|
|
16
|
-
|
|
70
|
+
|
|
71
|
+
found="$(git config --show-scope --get core.hooksPath || true)"
|
|
72
|
+
if [[ -n "$found" ]]; then
|
|
73
|
+
tab=$'\t'
|
|
74
|
+
scope="${found%%"$tab"*}"
|
|
75
|
+
value="${found#*"$tab"}"
|
|
76
|
+
case "$scope" in
|
|
77
|
+
global | system)
|
|
78
|
+
printf '%s\n' "這台機器的 ${scope} 設定有 core.hooksPath=${value},git 只跑那裡的 hook。那組 hook 會轉給 .git/hooks/<name> 時,倉的 hook 才會跑。"
|
|
79
|
+
;;
|
|
80
|
+
*)
|
|
81
|
+
printf '%s\n' "git-hooks.sh:${scope} 設定有 core.hooksPath=${value},git 只跑那裡的 hook,${hooks} 的轉呼叫檔不會被執行。要讓倉的 hook 跑,移除那筆設定:git config --$scope --unset core.hooksPath" >&2
|
|
82
|
+
exit 0
|
|
83
|
+
;;
|
|
84
|
+
esac
|
|
85
|
+
fi
|
|
86
|
+
printf '%s\n' "git hooks → ${hooks}(commit-msg、pre-push 轉給 scripts/hooks);commit.cleanup → scissors"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
#
|
|
4
4
|
# usage: healthz.sh <worker> <env> <worker> is <unit>-<env>, the name wrangler.toml gives the environment
|
|
5
5
|
# reads: ops/urls.json { "<env>": "<base URL of a Worker, with {worker} where its name goes>" }
|
|
6
|
-
# compose writes the file from the URL patterns that the ops unit of the repository publishes (
|
|
6
|
+
# compose writes the file from the URL patterns that the ops unit of the repository publishes (the
|
|
7
7
|
# interface of the unit), so the patterns are not a repository variable.
|
|
8
8
|
set -euo pipefail
|
|
9
9
|
worker="${1:?usage: healthz.sh <worker> <env>}"
|
package/org/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @@repoName@@
|
|
2
2
|
|
|
3
|
-
`@@organization@@` 組織在組織層的 `@@repoName@@`
|
|
3
|
+
`@@organization@@` 組織在組織層的 `@@repoName@@` 倉。它是導入方的組織層倉,放這個組織的組織值與組織層的倉清單,也可以放組織自己的規則,不放持有範本的倉的職責。共用套件、範本與組織層倉範本由管理中樞發布,這個倉只放組織層倉該有的東西。
|
|
4
4
|
|
|
5
5
|
## 放什麼
|
|
6
6
|
|
|
7
|
-
- `facts/` 是 `@@aggregatePackageName
|
|
7
|
+
- `facts/` 是 `@@aggregatePackageName@@`。它至少有兩筆 fact:組織值(`@@repoName@@.org-values`,欄位定義在共用 fact `blueprint-shared.org-values`,fact-kit 依那份 schema 驗證),以及組織層的倉清單(`@@repoName@@.org-layout.repos`)。組織可以另放自己的規則。
|
|
8
8
|
- `docs/` 是 `@@scope@@/@@repoName@@-docs`。它放組織層的文件,並引用上面的 fact 與共用 fact。`docs/@@repoName@@-docs/@@repoName@@/layer-names.doc.ts` 寫出各倉的 facts、docs 套件名怎麼從這一層推出。
|
|
9
9
|
- `scripts/ci/check-org-values.mjs` 逐欄位核對組織值,缺欄位、多欄位或型別不對時印出欄位名。
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ name: release-please
|
|
|
15
15
|
# - pin: this run wrote or updated the Release PR (prs_created, or a re-run of the job, which finds nothing to update after a
|
|
16
16
|
# pin that failed half way) and created no tag → scripts/release/pin-release-pr.sh pins the "next" of facts and docs to the
|
|
17
17
|
# versions of the Release PR and pushes. The push makes release-please run again; the second run has nothing to change.
|
|
18
|
-
# - merge-back: the line is at ga and every final tag
|
|
18
|
+
# - merge-back: the line is at ga, has no open Release PR and every bumped unit has its final tag → the next job runs finalize-release.sh --phase merge-back.
|
|
19
19
|
# The pushes use the token of the App, because a push made with GITHUB_TOKEN raises no workflow run and the merge-back PR would get
|
|
20
20
|
# no checks. The fallbacks by hand are the merge-release-pr and merge-back workflows. This file has no manual trigger.
|
|
21
21
|
# Two other workflows are started by events and work on the same lines: sync-release-tools.yml (main changes the tooling, the open
|
|
@@ -41,6 +41,9 @@ on:
|
|
|
41
41
|
- "infra/**"
|
|
42
42
|
- "ops/**"
|
|
43
43
|
- "docs/**"
|
|
44
|
+
# 合回就緒是這支 workflow 用 scripts/ 下的腳本算出來的輸出,sync-release-tools.yml 把腳本同步到發布分支的 commit
|
|
45
|
+
# 只動 scripts/ 與 .github/,沒有這一行就不會重算,上一次失敗的 run 會一直是最新一筆。
|
|
46
|
+
- "scripts/**"
|
|
44
47
|
- "release-please-config.json"
|
|
45
48
|
- ".release-please-manifest.json"
|
|
46
49
|
# no workflow_dispatch: run by hand on main it would open a version PR against main, breaking
|
|
@@ -175,13 +178,16 @@ jobs:
|
|
|
175
178
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
176
179
|
bash scripts/release/pin-release-pr.sh --line "${BRANCH#release/v}" --yes
|
|
177
180
|
|
|
178
|
-
# 合回:階段是 ga
|
|
179
|
-
#
|
|
181
|
+
# 合回:階段是 ga、這條線沒有開著的 Release PR(腳本用 GH_TOKEN 查),而且 manifest 對預設分支有升版的單元至少一個、
|
|
182
|
+
# 各自的最終 tag 都齊了才輸出 true,下一個 job 以它為條件。tag 是上面 release-please 這次 run 才建的,所以腳本先取回 tag。
|
|
183
|
+
# 沒有單元升版的線不輸出 true(剛開線時也是這樣),那條線靠手動的 merge-back workflow 補。
|
|
180
184
|
- id: ready
|
|
181
185
|
if: steps.branch.outputs.exists == 'true' && vars.@@clientIdVariable@@ != ''
|
|
186
|
+
env:
|
|
187
|
+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
|
182
188
|
run: bash scripts/release/merge-back-ready.sh >> "$GITHUB_OUTPUT"
|
|
183
189
|
|
|
184
|
-
# GA 之後開合回 PR:上一個 job
|
|
190
|
+
# GA 之後開合回 PR:上一個 job 算出合回就緒(階段是 ga、沒有開著的 Release PR、升版單元的最終 tag 都齊了)才啟動,條件沒成立時這個 job 不啟動,不佔 runner。
|
|
185
191
|
# 推送與開 PR 用 App 的權杖,不然合回 PR 的檢查不會跑。需要 App,所以沒有 App 的倉略過。
|
|
186
192
|
merge-back:
|
|
187
193
|
needs: release-please
|
|
@@ -137,25 +137,30 @@ aggregate_unit() {
|
|
|
137
137
|
# release_start_point <base> <unit>... → sets RELEASE_START to the commit on main a train over these units counts
|
|
138
138
|
# its commits from, and RELEASE_SKIPPED to the cuts it passed over. Set as globals, not printed, because
|
|
139
139
|
# unit_released stops the script on a failed lookup and must run in the shell itself, not in $(...).
|
|
140
|
-
#
|
|
141
|
-
#
|
|
142
|
-
#
|
|
143
|
-
#
|
|
144
|
-
#
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
151
|
-
#
|
|
140
|
+
# release-please reads one last-release-sha for every unit of the line, so the start point has to suit all of them:
|
|
141
|
+
# a cut too new hides commits a unit still has to release, a cut too old counts again commits the newer releases
|
|
142
|
+
# already shipped. The result is the newest cut that hides nothing:
|
|
143
|
+
# - The candidates are the cuts on main, newest first. The merge-back commit of each release carries
|
|
144
|
+
# Release-Train-Base (the cut of that release) and Release-Train-Units (the units of that train). A cut that is
|
|
145
|
+
# not an ancestor of <base> (a patch train rebuilt from a tag) is skipped. A merge-back with no
|
|
146
|
+
# Release-Train-Units covers every unit and ends the candidates.
|
|
147
|
+
# - A released unit (unit_released) counts from the newest cut that lists it (its cut). A candidate newer than
|
|
148
|
+
# that cut suits the unit when the unit has no commit release-please would release (releasable_commits_in on its
|
|
149
|
+
# path) between its cut and the candidate, because then nothing of it is hidden. A unit no cut lists counts from
|
|
150
|
+
# the oldest candidate.
|
|
151
|
+
# - No release lists a unit that has never been released, so a candidate suits such a unit when it is strictly
|
|
152
|
+
# older than the unit's first commit: every commit of the unit then comes after the cut and counts toward its
|
|
153
|
+
# first version.
|
|
154
|
+
# When no candidate suits every unit it is the oldest candidate; with no cut at all it is empty (no previous
|
|
155
|
+
# release). The walk has no depth limit: the cut is a fact of an earlier release, however far back.
|
|
152
156
|
release_start_point() {
|
|
153
|
-
local base="$1" u c b us row first
|
|
154
|
-
local -a
|
|
157
|
+
local base="$1" u c b us row first i k n p
|
|
158
|
+
local -a released=() firsts=() cuts=() listed=() skipped_at=() skipped=()
|
|
159
|
+
local -A covered_at=()
|
|
155
160
|
shift
|
|
156
161
|
RELEASE_START=""; RELEASE_SKIPPED=()
|
|
157
162
|
for u in "$@"; do
|
|
158
|
-
if unit_released "$u"; then
|
|
163
|
+
if unit_released "$u"; then released+=("$u"); continue; fi
|
|
159
164
|
first="$(git rev-list --reverse "$base" -- "$(unit_path "$u")" | sed -n 1p)"
|
|
160
165
|
[[ -z "$first" ]] || firsts+=("$first")
|
|
161
166
|
done
|
|
@@ -163,21 +168,37 @@ release_start_point() {
|
|
|
163
168
|
b="${row%%$'\x1f'*}"; us="${row#*$'\x1f'}"
|
|
164
169
|
[[ "$b" =~ ^[0-9a-f]{7,40}$ ]] || continue
|
|
165
170
|
c="$b"
|
|
166
|
-
if ! git merge-base --is-ancestor "$c" "$base" 2>/dev/null; then
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
171
|
+
if ! git merge-base --is-ancestor "$c" "$base" 2>/dev/null; then skipped+=("$c"); skipped_at+=("${#cuts[@]}"); continue; fi
|
|
172
|
+
cuts+=("$c")
|
|
173
|
+
if [[ -z "$us" ]]; then
|
|
174
|
+
for u in "${released[@]+"${released[@]}"}"; do [[ -n "${covered_at[$u]:-}" ]] || covered_at[$u]=$(( ${#cuts[@]} - 1 )); done
|
|
175
|
+
break
|
|
176
|
+
fi
|
|
170
177
|
read -r -a listed <<<"$us"
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
for u in "${listed[@]}"; do [[ -n "${covered_at[$u]:-}" ]] || covered_at[$u]=$(( ${#cuts[@]} - 1 )); done
|
|
179
|
+
done < <(git log origin/main --format='%(trailers:key=Release-Train-Base,valueonly,unfold,separator=%x20)%x1f%(trailers:key=Release-Train-Units,valueonly,unfold,separator=%x20)' 2>/dev/null || true)
|
|
180
|
+
n=${#cuts[@]}
|
|
181
|
+
(( n )) || return 0
|
|
182
|
+
k=$(( n - 1 ))
|
|
183
|
+
for (( i = 0; i < n; i++ )); do
|
|
184
|
+
c="${cuts[$i]}"
|
|
185
|
+
for u in "${released[@]+"${released[@]}"}"; do
|
|
186
|
+
p="${covered_at[$u]:-$(( n - 1 ))}"
|
|
187
|
+
(( i < p )) || continue
|
|
188
|
+
releasable_commits_in "${cuts[$p]}..$c" "$(unit_path "$u")" && continue 2
|
|
189
|
+
done
|
|
175
190
|
for first in "${firsts[@]+"${firsts[@]}"}"; do
|
|
176
|
-
if [[ "$c" == "$first" ]] || ! git merge-base --is-ancestor "$c" "$first"; then
|
|
191
|
+
if [[ "$c" == "$first" ]] || ! git merge-base --is-ancestor "$c" "$first"; then continue 2; fi
|
|
177
192
|
done
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
193
|
+
k=$i; break
|
|
194
|
+
done
|
|
195
|
+
# shellcheck disable=SC2034 # read by cut-release.sh, which sources this file
|
|
196
|
+
RELEASE_START="${cuts[$k]}"
|
|
197
|
+
for (( i = 0; i < ${#skipped[@]}; i++ )); do
|
|
198
|
+
# shellcheck disable=SC2034 # read by cut-release.sh, which sources this file
|
|
199
|
+
(( skipped_at[i] <= k )) && RELEASE_SKIPPED+=("${skipped[$i]}")
|
|
200
|
+
done
|
|
201
|
+
return 0
|
|
181
202
|
}
|
|
182
203
|
|
|
183
204
|
# train_units_of <ref> → the units the train was opened with, space separated, from the newest
|
|
@@ -367,7 +388,7 @@ train_assign_stages() {
|
|
|
367
388
|
|
|
368
389
|
# releasable_commits_in <range> [<path>...] → success when <range> has a commit release-please would release: a feat, fix,
|
|
369
390
|
# perf, deps or revert commit or a breaking change that touches one of the paths (any path when none is given). The one rule
|
|
370
|
-
# behind unit_changed
|
|
391
|
+
# behind unit_changed and the pin base check (release_pin_open_pr).
|
|
371
392
|
releasable_commits_in() {
|
|
372
393
|
local range="$1"; shift
|
|
373
394
|
[[ -z "$(git log -1 --format=%H -E \
|
|
@@ -418,59 +439,56 @@ train_stage() {
|
|
|
418
439
|
printf '%s\n' "$stage"
|
|
419
440
|
}
|
|
420
441
|
|
|
421
|
-
#
|
|
422
|
-
#
|
|
423
|
-
#
|
|
424
|
-
#
|
|
425
|
-
# line is opened no unit has been bumped yet, and a manifest-based list is empty and looks complete. Without a Release-Train-Units
|
|
426
|
-
# trailer the units of the config count.
|
|
427
|
-
train_units_to_ship() {
|
|
428
|
-
local ref="${1:-HEAD}" anchor u list
|
|
429
|
-
list="$(train_units_of "$ref")"
|
|
430
|
-
if [[ -z "$list" ]]; then list="$(config_units | tr '\n' ' ')"; fi
|
|
431
|
-
[[ -n "$list" ]] || return 0
|
|
432
|
-
anchor="$(git show "$ref:$CONFIG" 2>/dev/null | jq -r '."last-release-sha" // empty' 2>/dev/null || true)"
|
|
433
|
-
for u in $list; do
|
|
434
|
-
unit_changed "$u" "$anchor" "$ref" || continue
|
|
435
|
-
printf '%s\n' "$u"
|
|
436
|
-
done
|
|
437
|
-
return 0
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
# train_final_tags_missing [<ref>] → one line per unit the train ships (train_units_to_ship) whose final tag is not there yet, nothing
|
|
441
|
-
# when all are. A unit still on a prerelease version has not been through the GA Release PR; a unit whose manifest version is still
|
|
442
|
-
# the one origin/main has was not bumped yet (the line was just opened, and the tag of that old version exists); a unit on a new
|
|
443
|
-
# stable version needs its <component>/v<version> tag, which release-please makes when that PR is merged. Reads the local tags:
|
|
444
|
-
# fetch them first. A train that ships no unit has nothing missing.
|
|
442
|
+
# train_final_tags_missing → one line per unit the train shipped (train_units_by_manifest: the manifest entries that differ from
|
|
443
|
+
# origin/main's) whose final tag is not there yet, nothing when all are. A unit still on a prerelease version has not been through
|
|
444
|
+
# the GA Release PR; a unit on a stable version needs its <component>/v<version> tag, which release-please makes when that PR is
|
|
445
|
+
# merged. Reads the local tags: fetch them first. A train whose manifest has no difference has nothing missing here.
|
|
445
446
|
train_final_tags_missing() {
|
|
446
|
-
local u p v
|
|
447
|
+
local u p v
|
|
447
448
|
git rev-parse -q --verify origin/main >/dev/null || { printf '%s\n' "找不到 origin/main,無法判斷單元升版了沒"; return 0; }
|
|
448
449
|
while IFS= read -r u; do
|
|
449
450
|
[[ -n "$u" ]] || continue
|
|
450
451
|
p="$(unit_path "$u")" || { printf '%s\n' "$u 在設定裡找不到目錄"; continue; }
|
|
451
452
|
v="$(manifest_version "$p")"
|
|
452
453
|
if [[ "$v" == *-* ]]; then printf '%s\n' "$u 仍是 prerelease $v"; continue; fi
|
|
453
|
-
mv="$(git show "origin/main:$MANIFEST" | jq -r --arg p "$p" '.[$p] // empty')"
|
|
454
|
-
if [[ -n "$mv" && "$mv" == "$v" ]]; then printf '%s\n' "${u} 尚未升版(manifest 仍是 main 的 ${v})"; continue; fi
|
|
455
454
|
git rev-parse -q --verify "refs/tags/$u/v$v" >/dev/null || printf '%s\n' "$u/v$v"
|
|
456
|
-
done < <(
|
|
455
|
+
done < <(train_units_by_manifest)
|
|
457
456
|
return 0
|
|
458
457
|
}
|
|
459
458
|
|
|
460
|
-
# train_merge_back_ready
|
|
461
|
-
#
|
|
462
|
-
#
|
|
459
|
+
# train_merge_back_ready → 0 when the merge-back of the line can be opened, judged on what release-please has already produced and not
|
|
460
|
+
# by recounting its commits: (1) the line stage on HEAD is ga, (2) the line has no open Release PR, (3) the manifest differs from
|
|
461
|
+
# origin/main for at least one unit (an empty difference is a line just opened, before any Release PR) and every such unit is on a
|
|
462
|
+
# stable version with its <component>/v<version> tag. Otherwise 1, with TRAIN_MERGE_BACK_WAITING set to what is still missing. The
|
|
463
|
+
# release-please job asks it after every run, so it only looks and never waits. The open Release PR is asked here with its own exit
|
|
464
|
+
# code, not through release_pr_open_number, because that function stops with die inside a command substitution and the caller would
|
|
465
|
+
# read the empty output as "no PR". A failed query counts as not ready.
|
|
463
466
|
TRAIN_MERGE_BACK_WAITING=""
|
|
464
467
|
# shellcheck disable=SC2034 # TRAIN_MERGE_BACK_WAITING is read by merge-back-ready.sh, which sources this file
|
|
465
468
|
train_merge_back_ready() {
|
|
466
|
-
local stage missing
|
|
469
|
+
local stage branch open missing units
|
|
467
470
|
TRAIN_MERGE_BACK_WAITING=""
|
|
468
|
-
stage="$(train_stage
|
|
471
|
+
stage="$(train_stage HEAD)"
|
|
469
472
|
if [[ "$stage" != ga ]]; then
|
|
470
473
|
TRAIN_MERGE_BACK_WAITING="發布線的階段是 ${stage},不是 ga"
|
|
471
474
|
return 1
|
|
472
475
|
fi
|
|
473
|
-
|
|
476
|
+
branch="$(current_branch)"
|
|
477
|
+
if ! open="$(read_retry gh pr list --base "$branch" --head "release-please--branches--$branch" --state open --json number --jq '.[0].number // empty')"; then
|
|
478
|
+
TRAIN_MERGE_BACK_WAITING="查不到 ${branch} 的 Release PR(gh pr list 失敗),不當成沒有"
|
|
479
|
+
return 1
|
|
480
|
+
fi
|
|
481
|
+
if [[ -n "$open" ]]; then
|
|
482
|
+
TRAIN_MERGE_BACK_WAITING="${branch} 還有開著的 Release PR #${open},GA 尚未完成"
|
|
483
|
+
return 1
|
|
484
|
+
fi
|
|
485
|
+
git rev-parse -q --verify origin/main >/dev/null || { TRAIN_MERGE_BACK_WAITING="找不到 origin/main,無法判斷單元升版了沒"; return 1; }
|
|
486
|
+
units="$(train_units_by_manifest)"
|
|
487
|
+
if [[ -z "$units" ]]; then
|
|
488
|
+
TRAIN_MERGE_BACK_WAITING="manifest 和 origin/main 沒有差異,沒有單元升版"
|
|
489
|
+
return 1
|
|
490
|
+
fi
|
|
491
|
+
missing="$(train_final_tags_missing)"
|
|
474
492
|
if [[ -n "$missing" ]]; then
|
|
475
493
|
TRAIN_MERGE_BACK_WAITING="GA 尚未完成,缺:$(tr '\n' ' ' <<<"$missing")"
|
|
476
494
|
return 1
|
|
@@ -774,7 +792,7 @@ train_gates() { # train_gates <branch> <line> <stage>
|
|
|
774
792
|
# all stop the gate. A repository with no such unit passes without a query. It queries once and never waits; whoever calls it waits for the deploy and runs it again.
|
|
775
793
|
# Whether the repository deploys is decided by its deploy-prerelease.yml. When that file reads
|
|
776
794
|
# vars.DEPLOY_ENABLED outside a comment (the condition the templates keep for the demo repositories), a repository whose variable DEPLOY_ENABLED is not
|
|
777
|
-
# true (
|
|
795
|
+
# true (the demonstration repository's own value first, the organization's only when the repository has none)
|
|
778
796
|
# deploys nothing, so there is no run to look for and its units pass with the reason printed. A variable list that cannot be read stops
|
|
779
797
|
# the gate, because it must not be taken for "not enabled". When the file has no such line, or does not exist, the repository removed the
|
|
780
798
|
# condition and deploys whenever the workflow runs: the variable is not read and the gate checks the run as usual.
|
|
@@ -119,7 +119,7 @@ case "$phase" in
|
|
|
119
119
|
declare -a paths=() missing=()
|
|
120
120
|
for u in ${units[@]+"${units[@]}"}; do p="$(unit_path "$u")"; paths+=("$p"); done
|
|
121
121
|
# 最終 tag 齊了沒的判斷(train_final_tags_missing)和 release-please 的 job 決定要不要開合回共用同一個函式。
|
|
122
|
-
#
|
|
122
|
+
# 清單是 manifest 對 origin/main 有差異的單元(train_units_by_manifest),沒有差異就沒有要等的 tag
|
|
123
123
|
while IFS= read -r m; do [[ -n "$m" ]] && missing+=("$m"); done < <(train_final_tags_missing)
|
|
124
124
|
(( ${#missing[@]} == 0 )) || die "GA 尚未完成:${missing[*]}(先合併 Release PR 並等 tag 建立)"
|
|
125
125
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Whether the merge-back of the release line on the current branch can be opened: the line stage is ga
|
|
3
|
-
#
|
|
2
|
+
# Whether the merge-back of the release line on the current branch can be opened: the line stage is ga, the line has no open
|
|
3
|
+
# Release PR, and every unit whose manifest version differs from origin/main's has its final tag.
|
|
4
|
+
# Prints GitHub Actions outputs on stdout (append to $GITHUB_OUTPUT) and the reason on stderr. It looks once
|
|
4
5
|
# and always exits 0, because a condition that does not hold yet is the normal case for most runs of release-please.
|
|
5
6
|
#
|
|
6
7
|
# usage: merge-back-ready.sh
|
|
7
8
|
# ready=true|false
|
|
8
9
|
#
|
|
9
|
-
# The decision is train_merge_back_ready (scripts/lib/release-stages.sh), the same check finalize-release.sh --phase merge-back
|
|
10
|
+
# The decision is train_merge_back_ready (scripts/lib/release-stages.sh), the same tag check finalize-release.sh --phase merge-back
|
|
10
11
|
# stops on. Fetches the tags first: release-please makes the tags of the GA Release PR in the run that asks.
|
|
11
12
|
set -euo pipefail
|
|
12
13
|
source "$(dirname "$0")/../lib/common.sh"
|