blueprint-shared-templates 0.1.0 → 0.3.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/ISSUE_TEMPLATE/bug.yml +2 -2
- package/base/.github/ISSUE_TEMPLATE/hotfix.yml +1 -1
- package/base/.github/actions/setup-workspace/action.yml +2 -2
- package/base/.github/workflows/auto-merge.yml +4 -0
- package/base/.github/workflows/ci.yml +17 -1
- package/base/scripts/ci/run-affected.sh +6 -0
- package/base/scripts/lib/common.sh +1 -1
- package/base/scripts/lib/retry.mjs +36 -6
- package/base/scripts/merge/decide.mjs +32 -17
- package/base/scripts/setup/github-repo-settings.sh +1 -1
- package/deploy/.github/workflows/deploy-prerelease.yml +6 -50
- package/deploy/.github/workflows/deploy-prod.yml +103 -0
- package/deploy/scripts/deploy/plan-prod.sh +57 -0
- package/deploy/scripts/deploy/promote.sh +23 -7
- package/deploy/scripts/deploy/publish-bundle.sh +10 -1
- package/deploy/scripts/deploy/route-tag.sh +10 -12
- package/deploy/scripts/deploy/run-prerelease.sh +4 -7
- package/deploy/scripts/deploy/{run-production.sh → run-prod.sh} +15 -17
- package/deploy/scripts/deploy/writeback-ops.sh +71 -40
- package/facts-skeleton.mjs +1 -1
- package/hub/scripts/release/dispatch-release-lines.sh +25 -2
- package/hub/scripts/release/snapshot-members.sh +1 -1
- package/ops/.github/workflows/ops-deploy.yml +92 -11
- package/ops/schemas/targets.schema.json +209 -0
- package/ops/scripts/ci/check-targets.mjs +291 -0
- package/ops/scripts/deploy/apply-iac.sh +89 -0
- package/ops/scripts/deploy/apply-ops.sh +101 -48
- package/ops/scripts/deploy/ops-run.sh +50 -12
- package/ops/scripts/deploy/smoke.sh +35 -16
- package/ops/scripts/lib/ops-steps.sh +75 -0
- package/org/scripts/ci/check-org-values.mjs +91 -0
- package/package.json +2 -2
- package/publish/.github/workflows/publish.yml +12 -3
- package/publish/scripts/release/cleanup-private-packages.mjs +1 -1
- package/publish/scripts/release/mirror-units.sh +45 -5
- package/publish/scripts/release/publish-units.sh +28 -4
- package/release/.github/workflows/advance-release.yml +107 -0
- package/release/.github/workflows/close-release.yml +133 -0
- package/release/.github/workflows/merge-back.yml +82 -0
- package/release/.github/workflows/merge-release-pr.yml +82 -0
- package/release/.github/workflows/open-release-line.yml +14 -5
- package/release/.github/workflows/release-line-finalize.yml +5 -3
- package/release/.github/workflows/release-please.yml +99 -15
- package/release/.github/workflows/sync-release-tools.yml +91 -0
- package/release/release-policy.json +1 -1
- package/release/schemas/release-policy.schema.json +13 -3
- package/release/scripts/ci/branch-exists.sh +27 -0
- package/release/scripts/ci/check-release-policy.sh +13 -2
- package/release/scripts/ci/pin-train.sh +5 -3
- package/release/scripts/ci/release-train.sh +22 -3
- package/release/scripts/lib/release-plan.sh +3 -1
- package/release/scripts/lib/release-pr.sh +275 -11
- package/release/scripts/lib/release-stages.sh +265 -36
- package/release/scripts/release/check-trigger-actor.sh +32 -0
- package/release/scripts/release/close-ready.mjs +72 -0
- package/release/scripts/release/close-ready.sh +70 -0
- package/release/scripts/release/cut-release.sh +35 -4
- package/release/scripts/release/ensure-stage-deploys.sh +3 -3
- package/release/scripts/release/finalize-release.sh +47 -15
- package/release/scripts/release/merge-back-ready.sh +27 -0
- package/release/scripts/release/merge-release-pr.sh +34 -107
- package/release/scripts/release/open-release-line.sh +28 -8
- package/release/scripts/release/pin-release-pr.sh +53 -0
- package/release/scripts/release/product-release-notes.sh +28 -0
- package/release/scripts/release/sync-release-tools.sh +137 -0
- package/release/scripts/release/{verify-production.sh → verify-prod.sh} +11 -10
- package/transform.mjs +3 -4
- package/verify/.github/workflows/{verify-production.yml → verify-prod.yml} +7 -7
- package/verify/scripts/release/verify-ops.sh +4 -4
- package/deploy/.github/workflows/deploy-production.yml +0 -173
- package/deploy/scripts/deploy/plan-production.sh +0 -43
- package/infra/.github/workflows/deploy-prerelease.yml +0 -157
- package/infra/.github/workflows/deploy-production.yml +0 -173
- package/infra/scripts/deploy/apply-infra.sh +0 -46
- package/infra/scripts/deploy/apply-prerelease.sh +0 -22
- package/infra/scripts/deploy/apply-production.sh +0 -33
- package/infra/scripts/deploy/route-tag.sh +0 -65
|
@@ -23,15 +23,92 @@ wait_release_pr() {
|
|
|
23
23
|
return 1
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
26
|
+
# release_please_paths → the paths release-please.yml filters its push trigger by (on.push.paths), one per line, "dir/**"
|
|
27
|
+
# written as "dir" because that is how git's pathspec reads it. Reads RELEASE_PLEASE_WORKFLOW (default
|
|
28
|
+
# .github/workflows/release-please.yml). Fails when the file is missing or lists no path, so a caller never mistakes
|
|
29
|
+
# "could not read the filter" for "nothing to look at".
|
|
30
|
+
release_please_paths() {
|
|
31
|
+
local file="${RELEASE_PLEASE_WORKFLOW:-.github/workflows/release-please.yml}" out
|
|
32
|
+
[[ -f "$file" ]] || return 1
|
|
33
|
+
out="$(awk '
|
|
34
|
+
/^ paths:[[:space:]]*$/ { in_paths = 1; next }
|
|
35
|
+
in_paths && /^[[:space:]]*#/ { next }
|
|
36
|
+
in_paths && /^ -[[:space:]]/ { v = $0; sub(/^ -[[:space:]]+/, "", v); gsub(/["\047]/, "", v); sub(/[[:space:]]+#.*$/, "", v); sub(/\/\*\*$/, "", v); print v; next }
|
|
37
|
+
in_paths { exit }
|
|
38
|
+
' "$file")"
|
|
39
|
+
[[ -n "$out" ]] || return 1
|
|
40
|
+
printf '%s\n' "$out"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# release_please_settled <branch> [<sha>] → looks once, never waits. Returns 0 when release-please has processed the branch,
|
|
44
|
+
# otherwise 1 with RELEASE_PLEASE_WAITING set to what it is still waiting for. Both of these have to hold:
|
|
45
|
+
# 1. no release-please run on <branch> is queued or in progress
|
|
46
|
+
# 2. the newest finished run's commit and the tip of origin/<branch> differ in none of the paths release-please.yml
|
|
47
|
+
# filters by. "The tip has a finished run" would not do: a commit that only touches tooling starts no run at all.
|
|
48
|
+
# The newest finished run must also have concluded success: after a failed or cancelled run the versions were not recomputed,
|
|
49
|
+
# and the message names the conclusion and the link of that run.
|
|
50
|
+
# With <sha>, the commit this script just pushed, the newest finished run must be the run of <sha> itself: right after a push
|
|
51
|
+
# the run for that commit may not have started yet, and the finished runs of older commits make the branch look settled.
|
|
52
|
+
# A branch with no run at all counts as settled; the caller goes on to look for the Release PR, which does not exist yet then.
|
|
53
|
+
# Fetch origin/<branch> first: the comparison reads it. Call it in the shell itself, not in $(...), to keep the variable.
|
|
54
|
+
RELEASE_PLEASE_WAITING=""
|
|
55
|
+
release_please_settled() {
|
|
56
|
+
local branch="$1" sha="${2:-}" runs open latest conclusion paths
|
|
57
|
+
RELEASE_PLEASE_WAITING=""
|
|
58
|
+
# a failed gh call is not "no runs": it leaves the branch unsettled and the caller asks again
|
|
59
|
+
if ! runs="$(gh run list --workflow release-please.yml --branch "$branch" --limit 20 --json status,headSha,conclusion,url --jq '.[] | "\(.status) \(.headSha) \(.conclusion // "-") \(.url // "-")"' 2>/dev/null)"; then
|
|
60
|
+
RELEASE_PLEASE_WAITING="release-please 的 run 清單查不到(gh run list 失敗)"
|
|
61
|
+
return 1
|
|
62
|
+
fi
|
|
63
|
+
open="$(grep -v '^completed ' <<<"$runs" || true)"
|
|
64
|
+
if [[ -n "$open" ]]; then
|
|
65
|
+
RELEASE_PLEASE_WAITING="release-please 仍在執行或排隊($(head -1 <<<"$open" | cut -d' ' -f1))"
|
|
66
|
+
return 1
|
|
67
|
+
fi
|
|
68
|
+
latest="$(head -1 <<<"$runs" | cut -d' ' -f2)"
|
|
69
|
+
# the newest finished run did not succeed: the versions were not recomputed, whatever the paths say
|
|
70
|
+
conclusion="$(head -1 <<<"$runs" | cut -d' ' -f3)"
|
|
71
|
+
if [[ -n "$latest" && "$conclusion" != success ]]; then
|
|
72
|
+
RELEASE_PLEASE_WAITING="release-please 最新一筆 run 的結論是 ${conclusion}($(head -1 <<<"$runs" | cut -d' ' -f4)),版號沒有算完。處理後再觸發"
|
|
73
|
+
return 1
|
|
74
|
+
fi
|
|
75
|
+
if [[ -n "$sha" ]]; then
|
|
76
|
+
grep -q "^completed ${sha} " <<<"$runs" && return 0
|
|
77
|
+
RELEASE_PLEASE_WAITING="release-please 仍在執行:還沒有 ${sha:0:7} 的 run 跑完"
|
|
78
|
+
return 1
|
|
79
|
+
fi
|
|
80
|
+
[[ -n "$latest" ]] || return 0
|
|
81
|
+
if ! paths="$(release_please_paths)"; then
|
|
82
|
+
RELEASE_PLEASE_WAITING="讀不到 release-please.yml 的 on.push.paths,無法判斷 run 之後有沒有新的變更"
|
|
83
|
+
return 1
|
|
84
|
+
fi
|
|
85
|
+
if ! git cat-file -e "${latest}^{commit}" 2>/dev/null; then
|
|
86
|
+
RELEASE_PLEASE_WAITING="release-please 仍在處理:最新的 run 的 commit ${latest:0:7} 不在本機"
|
|
87
|
+
return 1
|
|
88
|
+
fi
|
|
89
|
+
local -a specs=()
|
|
90
|
+
mapfile -t specs <<<"$paths"
|
|
91
|
+
if ! git diff --quiet "$latest" "origin/$branch" -- "${specs[@]}"; then
|
|
92
|
+
RELEASE_PLEASE_WAITING="release-please 仍在處理:最新的 run(${latest:0:7})之後,分支上 release-please 會看的路徑還有變更"
|
|
93
|
+
return 1
|
|
94
|
+
fi
|
|
95
|
+
return 0
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
# wait_release_please_idle <branch> [<sha>]
|
|
99
|
+
# Ask release_please_settled up to POLL_TRIES times, POLL_SLEEP apart. A Release PR that predates the commit we just pushed
|
|
100
|
+
# would release the wrong version (observed 2026-09-07: merged a stale PR). Returns 1 when it is still not settled after the
|
|
101
|
+
# last round, with the reason printed: a caller must not merge on a Release PR release-please has not recomputed. It does
|
|
102
|
+
# not go on with a warning, on a machine as little as in a workflow.
|
|
28
103
|
wait_release_please_idle() {
|
|
29
|
-
local branch="$1" i
|
|
104
|
+
local branch="$1" sha="${2:-}" i
|
|
30
105
|
for ((i=1; i<=POLL_TRIES; i++)); do
|
|
31
|
-
|
|
106
|
+
git fetch -q origin "$branch" 2>/dev/null || true
|
|
107
|
+
release_please_settled "$branch" "$sha" && return 0
|
|
32
108
|
sleep "$POLL_SLEEP"
|
|
33
109
|
done
|
|
34
|
-
warn "
|
|
110
|
+
warn "$RELEASE_PLEASE_WAITING"
|
|
111
|
+
return 1
|
|
35
112
|
}
|
|
36
113
|
|
|
37
114
|
# manifest as it stands on the Release PR's head branch, i.e. the content a merge would land
|
|
@@ -53,29 +130,37 @@ release_pr_units() {
|
|
|
53
130
|
<(git show "origin/$base:$MANIFEST") <(printf '%s\n' "$mf"))
|
|
54
131
|
}
|
|
55
132
|
|
|
56
|
-
# release_pr_settle <base-branch> [--optional] [--expect-stable]
|
|
133
|
+
# release_pr_settle <base-branch> [--optional] [--expect-stable] [--sha <commit>]
|
|
57
134
|
# Sets RELEASE_PR_NUMBER and RELEASE_PR_SHA once the Release PR's head has stopped moving.
|
|
58
135
|
# --optional:沒有 Release PR 時回傳 1 而不中止。切自產品 tag 的修補發布在 hotfix 合入前本來就無版可發。
|
|
59
136
|
# --expect-stable:GA 用。只在 PR 內容已無 prerelease 版號時才算穩定。
|
|
137
|
+
# --sha:剛推送到 <base-branch> 的 commit。release-please 對這個 commit 的 run 跑完才算閒置,
|
|
138
|
+
# 不然推送後 run 還沒開始時,舊 commit 的 run 都已完成,會被當成已經停下(wait_release_please_idle)。
|
|
60
139
|
#
|
|
61
140
|
# 「現在沒有執行中的 run」不足以判定 PR 是最新的:release-please 每跑一次就重寫該 PR,閒置檢查通過
|
|
62
141
|
# 之後才啟動的 run 會把內容換掉,於是合併到的是舊版本(實測 2026-09-08:GA 合併到仍帶預發布版號的
|
|
63
142
|
# PR,發布分支因此停在 prerelease)。改為等 head SHA 在一次重查後仍相同,必要時再核對內容。
|
|
64
143
|
release_pr_settle() {
|
|
65
|
-
local base="$1" n optional=0 expect_stable=0
|
|
144
|
+
local base="$1" n optional=0 expect_stable=0 i sha prev="" mf pushed=""
|
|
66
145
|
RELEASE_PR_NUMBER="" RELEASE_PR_SHA=""
|
|
67
|
-
|
|
68
|
-
|
|
146
|
+
shift
|
|
147
|
+
while [[ $# -gt 0 ]]; do
|
|
148
|
+
case "$1" in
|
|
149
|
+
--optional) optional=1 ;;
|
|
150
|
+
--expect-stable) expect_stable=1 ;;
|
|
151
|
+
--sha) pushed="${2:-}"; [[ -n "$pushed" ]] || die "release_pr_settle: --sha 需要一個 commit"; shift ;;
|
|
152
|
+
esac
|
|
153
|
+
shift
|
|
69
154
|
done
|
|
70
155
|
log "等待 $base 上的 release-please 執行完畢(避免合併過期的 Release PR)…"
|
|
71
|
-
wait_release_please_idle "$base"
|
|
156
|
+
wait_release_please_idle "$base" "$pushed" || die "release-please 還沒處理完 ${base},不繼續。等它處理完再重跑"
|
|
72
157
|
log "等待 release-please 在 $base 開 Release PR…"
|
|
73
158
|
if ! n="$(wait_release_pr "$base")"; then
|
|
74
159
|
(( optional )) && { info "$base 目前沒有可發版的變更,略過"; return 1; }
|
|
75
160
|
die "逾時:$base 上沒有 Release PR(查 gh run list --workflow release-please.yml)"
|
|
76
161
|
fi
|
|
77
162
|
for ((i=1; i<=POLL_TRIES; i++)); do
|
|
78
|
-
wait_release_please_idle "$base"
|
|
163
|
+
wait_release_please_idle "$base" "$pushed" || die "release-please 還沒處理完 ${base},不繼續。等它處理完再重跑"
|
|
79
164
|
sha="$(gh pr view "$n" --json headRefOid --jq .headRefOid 2>/dev/null || true)"
|
|
80
165
|
if [[ -n "$sha" && "$sha" == "$prev" ]]; then
|
|
81
166
|
(( expect_stable )) || break
|
|
@@ -90,6 +175,185 @@ release_pr_settle() {
|
|
|
90
175
|
info "Release PR #${n}:$(gh pr view "$n" --json title --jq .title)"
|
|
91
176
|
}
|
|
92
177
|
|
|
178
|
+
# --- version check and pin, shared by scripts/release/merge-release-pr.sh and scripts/release/pin-release-pr.sh ---
|
|
179
|
+
|
|
180
|
+
# release_pr_open_number <branch> → the number of the open Release PR of <branch>, empty when there is none. Looks once.
|
|
181
|
+
# Found by its head branch, as wait_release_pr does. A failed gh call stops the script: it is not "no PR".
|
|
182
|
+
release_pr_open_number() {
|
|
183
|
+
local base="$1" out
|
|
184
|
+
out="$(gh pr list --base "$base" --head "release-please--branches--$base" --state open --json number --jq '.[0].number // empty')" \
|
|
185
|
+
|| die "查不到 ${base} 的 Release PR(gh pr list 失敗)"
|
|
186
|
+
printf '%s\n' "$out"
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
# train_open_release_pr_check <branch> → fails with the reason on stderr when <branch> still has an open Release PR. merge-back and close
|
|
190
|
+
# act on a line whose GA Release PR is merged; an open one means GA is not done, and what they would write is not final.
|
|
191
|
+
train_open_release_pr_check() {
|
|
192
|
+
local branch="$1" n
|
|
193
|
+
n="$(release_pr_open_number "$branch")"
|
|
194
|
+
[[ -z "$n" ]] || { echo "${branch} 還有開著的 Release PR #${n}(release-please--branches--${branch}):GA 還沒完成,先合併它,這裡沒有動任何東西" >&2; return 1; }
|
|
195
|
+
return 0
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
# release_pr_check_unit_version <unit> <pr version> <line> <branch> → adds a line to version_problems when the version is not
|
|
199
|
+
# what it must be (the rules are in the header of scripts/release/merge-release-pr.sh).
|
|
200
|
+
# Runs in the shell itself, not in $(...), because unit_released stops the script when it cannot read the tags.
|
|
201
|
+
declare -a version_problems=()
|
|
202
|
+
release_pr_check_unit_version() {
|
|
203
|
+
local u="$1" v="$2" line="$3" branch="$4" p type base stage vs line_stage latest cur want
|
|
204
|
+
p="$(jq -r --arg u "$u" '.packages | to_entries[] | select((.value.component // (.key | split("/") | last)) == $u) | .key' "$CONFIG" | head -1)"
|
|
205
|
+
[[ -n "$p" ]] || return 0
|
|
206
|
+
stage="$(config_unit_stage "$p")"
|
|
207
|
+
# once the line is at ga the Release PR carries final versions, while the config of a unit still says its last prerelease
|
|
208
|
+
# stage until the merge-back restores it
|
|
209
|
+
[[ "$(train_stage)" != ga ]] || stage=ga
|
|
210
|
+
if unit_released "$u"; then
|
|
211
|
+
if ! vs="$(version_stage "$v")"; then
|
|
212
|
+
version_problems+=("${u} PR 版號 ${v},預期階段 ${stage} 的版號(X.Y.Z 或 X.Y.Z-<階段>.N)")
|
|
213
|
+
return 0
|
|
214
|
+
fi
|
|
215
|
+
# a unit that only walks ga ships its final version at once, so on an early line its own stage (ga) is the latest
|
|
216
|
+
# one it may be in; any other unit may not be later than the line
|
|
217
|
+
line_stage="$(train_stage)"
|
|
218
|
+
latest="$line_stage"
|
|
219
|
+
if policy_unit_exists "$u"; then
|
|
220
|
+
latest="$(unit_stage_at "$u" "$line_stage")"
|
|
221
|
+
[[ -n "$latest" ]] || latest="$line_stage"
|
|
222
|
+
(( $(stage_index "$latest") >= $(stage_index "$line_stage") )) || latest="$line_stage"
|
|
223
|
+
fi
|
|
224
|
+
if [[ "$vs" != "$stage" ]] || (( $(stage_index "$vs") > $(stage_index "$latest") )); then
|
|
225
|
+
version_problems+=("${u} PR 版號 ${v},預期階段 ${stage}(設定裡的階段,且不晚於 ${latest})")
|
|
226
|
+
fi
|
|
227
|
+
return 0
|
|
228
|
+
fi
|
|
229
|
+
type="$(unit_release_type "$p")"
|
|
230
|
+
base="$(unit_main_base_version "$p" "$line")"
|
|
231
|
+
cur="$(git show "origin/$branch:$MANIFEST" | jq -r --arg p "$p" '.[$p] // empty')"
|
|
232
|
+
want="$(unit_first_version "$type" "$base" "$stage" "$line" "$cur")"
|
|
233
|
+
[[ "$v" == "$want" ]] || version_problems+=("${u} PR 版號 ${v},預期 ${want}(沒有 tag,第一版)")
|
|
234
|
+
return 0
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
# release_pr_check_versions <line> <branch> "<unit> <version>"... → one round over the units; version_problems is empty when
|
|
238
|
+
# every version is what it must be
|
|
239
|
+
release_pr_check_versions() {
|
|
240
|
+
local line="$1" branch="$2" pair; shift 2
|
|
241
|
+
version_problems=()
|
|
242
|
+
for pair in "$@"; do release_pr_check_unit_version "${pair% *}" "${pair#* }" "$line" "$branch"; done
|
|
243
|
+
return 0
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
# release_pin_open_pr <branch> <line> → pins the "next" of facts/ and docs/ to the versions the open Release PR of <branch> gives,
|
|
247
|
+
# commits (chore(facts), chore(docs)) and pushes. The one pin, for merge-release-pr.sh and for the release-please job. It
|
|
248
|
+
# stops short, with success, whenever one of its conditions does not hold, because a pin made on a Release PR that release-please
|
|
249
|
+
# is about to recompute is a pin to the old version and cannot be fixed afterwards. In this order:
|
|
250
|
+
# 1. an open Release PR; none → RELEASE_PIN_RESULT=no-pr (a re-run of the job that merged it, for one)
|
|
251
|
+
# 2. the local branch is not behind origin/<branch>
|
|
252
|
+
# 3. no commit release-please processes lies between the base of the Release PR (the parent of its head, the branch tip of the run
|
|
253
|
+
# that wrote it) and the tip of origin/<branch>: a releasable commit (releasable_commits_in, the rule of unit_changed) that
|
|
254
|
+
# touches a unit path of the config, or a change to the config or the manifest; else the branch moved after the run, and the run
|
|
255
|
+
# for the newer commit will write the PR again → RELEASE_PIN_RESULT=skipped. A commit release-please ignores, such as the
|
|
256
|
+
# chore(facts) pin commit of an earlier round, does not count: it never makes release-please rewrite the PR, so the base would
|
|
257
|
+
# never move forward and the pin would never be allowed again
|
|
258
|
+
# 4. verify one round of the versions of the units the PR releases (release_pr_check_unit_version) → skipped on a mismatch
|
|
259
|
+
# Then it pins and commits. It pushes whenever the local branch is ahead of origin, not only when it just committed: an earlier
|
|
260
|
+
# run may have made the commit and failed to push. RELEASE_PIN_RESULT is one of:
|
|
261
|
+
# no-pr | skipped (RELEASE_PIN_REASON says why) | unchanged (nothing to pin, nothing to push) | pinned (pushed; release-please
|
|
262
|
+
# runs again and the PR is recomputed) | push-skipped (the push was not confirmed) | push-failed (returns 1)
|
|
263
|
+
# Fetches origin itself. The working tree must be clean and on <branch>. Call it in the shell itself, not in $(...), to keep
|
|
264
|
+
# the variables.
|
|
265
|
+
RELEASE_PIN_RESULT="" RELEASE_PIN_REASON=""
|
|
266
|
+
# shellcheck disable=SC2034 # RELEASE_PIN_RESULT is read by pin-release-pr.sh and merge-release-pr.sh, which source this file
|
|
267
|
+
release_pin_open_pr() {
|
|
268
|
+
local branch="$1" line="$2" n head_ref pr_sha base out row pair u v comps
|
|
269
|
+
local -a specs=() pr_units=() pinned=() docs_pinned=()
|
|
270
|
+
RELEASE_PIN_RESULT="" RELEASE_PIN_REASON=""
|
|
271
|
+
n="$(release_pr_open_number "$branch")"
|
|
272
|
+
if [[ -z "$n" ]]; then
|
|
273
|
+
RELEASE_PIN_RESULT=no-pr
|
|
274
|
+
info "⊘ ${branch} 沒有開著的 Release PR,不釘版"
|
|
275
|
+
return 0
|
|
276
|
+
fi
|
|
277
|
+
head_ref="release-please--branches--$branch"
|
|
278
|
+
git fetch -q origin "$branch" || die "git fetch origin $branch 沒成功"
|
|
279
|
+
git fetch -q origin "$head_ref" || die "git fetch origin $head_ref 沒成功"
|
|
280
|
+
pr_sha="$(git rev-parse FETCH_HEAD)"
|
|
281
|
+
if ! git merge-base --is-ancestor "origin/$branch" HEAD; then
|
|
282
|
+
RELEASE_PIN_RESULT=skipped RELEASE_PIN_REASON="本機的 ${branch} 落後遠端,留給下一次 run"
|
|
283
|
+
warn "$RELEASE_PIN_REASON"; return 0
|
|
284
|
+
fi
|
|
285
|
+
base="$(git rev-parse -q --verify "${pr_sha}^" || true)"
|
|
286
|
+
if [[ -z "$base" ]]; then
|
|
287
|
+
RELEASE_PIN_RESULT=skipped RELEASE_PIN_REASON="Release PR #${n} 的 head 沒有父 commit,無法確認它的基底"
|
|
288
|
+
warn "$RELEASE_PIN_REASON"; return 0
|
|
289
|
+
fi
|
|
290
|
+
mapfile -t specs < <(jq -r '.packages | keys[]' "$CONFIG")
|
|
291
|
+
if releasable_commits_in "${base}..origin/${branch}" "${specs[@]}" || ! git diff --quiet "$base" "origin/$branch" -- "$CONFIG" "$MANIFEST"; then
|
|
292
|
+
RELEASE_PIN_RESULT=skipped RELEASE_PIN_REASON="Release PR #${n} 的基底(${base:0:7})之後,${branch} 上又有 release-please 會處理的變更(動到單元路徑的可發版 commit,或設定、manifest 的變更),Release PR 還會被重算"
|
|
293
|
+
info "⊘ ${RELEASE_PIN_REASON},不釘版"; return 0
|
|
294
|
+
fi
|
|
295
|
+
out="$(release_pr_units "$branch")" || die "取 manifest 失敗:讀不到 Release PR 或 origin/${branch} 的 manifest,不是「沒有差異」"
|
|
296
|
+
while IFS= read -r row; do [[ -n "$row" ]] && pr_units+=("$row"); done < <(sort <<<"$out")
|
|
297
|
+
if (( ${#pr_units[@]} == 0 )); then
|
|
298
|
+
RELEASE_PIN_RESULT=skipped RELEASE_PIN_REASON="Release PR #${n} 對 origin/${branch} 的 manifest 沒有差異,沒有版號可釘"
|
|
299
|
+
info "⊘ ${RELEASE_PIN_REASON}"; return 0
|
|
300
|
+
fi
|
|
301
|
+
release_pr_check_versions "$line" "$branch" "${pr_units[@]}"
|
|
302
|
+
if (( ${#version_problems[@]} )); then
|
|
303
|
+
RELEASE_PIN_RESULT=skipped RELEASE_PIN_REASON="Release PR #${n} 的版號不符:${version_problems[*]}"
|
|
304
|
+
warn "${RELEASE_PIN_REASON}。不釘版,等 release-please 重算"; return 0
|
|
305
|
+
fi
|
|
306
|
+
|
|
307
|
+
if has_facts; then
|
|
308
|
+
declare -A comp_units=()
|
|
309
|
+
comps="$(facts_components)"
|
|
310
|
+
while IFS=$'\t' read -r _ u; do [[ -n "$u" ]] && comp_units[$u]=1; done <<<"$comps"
|
|
311
|
+
for pair in "${pr_units[@]}"; do
|
|
312
|
+
u="${pair% *}" v="${pair#* }"
|
|
313
|
+
[[ -n "${comp_units[$u]:-}" ]] || continue
|
|
314
|
+
facts_pin "$u" "$v"
|
|
315
|
+
pinned+=("$u@$v")
|
|
316
|
+
done
|
|
317
|
+
if [[ -n "$(git status --porcelain -- facts)" ]]; then
|
|
318
|
+
git add -- facts
|
|
319
|
+
run git commit -q -m "chore(facts): 釘 next 為 ${pinned[*]}" \
|
|
320
|
+
-m "合併 Release PR #${n} 之前,把這次要發的單元的 next 釘成 PR 的版號。釘在發布分支,不放 Release PR 分支,因為 release-please 重算時會強制改寫它。"
|
|
321
|
+
else
|
|
322
|
+
info "⊘ 沒有要釘的 next,不加新的 commit"
|
|
323
|
+
fi
|
|
324
|
+
fi
|
|
325
|
+
|
|
326
|
+
# 文件套件:和 facts 同一個位置釘,用 clarify-kit pin。docs/<單元> 存在的單元,才釘成 PR 給它的版號
|
|
327
|
+
if has_docs; then
|
|
328
|
+
for pair in "${pr_units[@]}"; do
|
|
329
|
+
u="${pair% *}" v="${pair#* }"
|
|
330
|
+
docs_unit_dir "$u" >/dev/null || continue
|
|
331
|
+
docs_pin_unit "$u" "$v"
|
|
332
|
+
docs_pinned+=("$u@$v")
|
|
333
|
+
done
|
|
334
|
+
if [[ -n "$(git status --porcelain -- docs)" ]]; then
|
|
335
|
+
git add -- docs
|
|
336
|
+
run git commit -q -m "chore(docs): 釘 next 為 ${docs_pinned[*]}" \
|
|
337
|
+
-m "合併 Release PR #${n} 之前,把這次要發的單元的文件 next 釘成 PR 的版號。釘在發布分支,不放 Release PR 分支,因為 release-please 重算時會強制改寫它。"
|
|
338
|
+
else
|
|
339
|
+
info "⊘ 文件套件沒有要釘的 next,不加新的 commit"
|
|
340
|
+
fi
|
|
341
|
+
fi
|
|
342
|
+
|
|
343
|
+
# 看本機是否領先遠端,不看這次有沒有新變動:上一次可能建好 commit 卻沒推出去(答 n、沒帶 --yes、推送失敗),
|
|
344
|
+
# 重跑時 facts 已乾淨,只看變動會跳過推送,check 讀本機工作樹通過,釘版卻沒到遠端
|
|
345
|
+
RELEASE_PIN_RESULT=unchanged
|
|
346
|
+
if (( $(git rev-list --count "origin/$branch..HEAD") > 0 )); then
|
|
347
|
+
if ! external_retry push "$(remote_target)" git push origin "$branch"; then
|
|
348
|
+
RELEASE_PIN_RESULT=push-failed RELEASE_PIN_REASON="推送 ${branch} 沒成功"
|
|
349
|
+
return 1
|
|
350
|
+
fi
|
|
351
|
+
if (( ${#SKIPPED_EXTERNAL[@]} )); then RELEASE_PIN_RESULT=push-skipped; return 0; fi
|
|
352
|
+
RELEASE_PIN_RESULT=pinned
|
|
353
|
+
fi
|
|
354
|
+
return 0
|
|
355
|
+
}
|
|
356
|
+
|
|
93
357
|
# release_pr_squash <number> <head-sha>: squash-merge only if the PR head is still <head-sha>, so a PR
|
|
94
358
|
# that release-please rewrote after the checks is refused instead of merged
|
|
95
359
|
release_pr_squash() {
|