blueprint-shared-templates 0.2.0 → 0.3.1

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.
Files changed (74) hide show
  1. package/base/.github/ISSUE_TEMPLATE/bug.yml +2 -2
  2. package/base/.github/ISSUE_TEMPLATE/hotfix.yml +1 -1
  3. package/base/.github/actions/setup-workspace/action.yml +2 -2
  4. package/base/.github/workflows/auto-merge.yml +4 -0
  5. package/base/.github/workflows/ci.yml +21 -1
  6. package/base/scripts/ci/run-affected.sh +6 -0
  7. package/base/scripts/lib/common.sh +1 -1
  8. package/base/scripts/lib/retry.mjs +36 -6
  9. package/base/scripts/merge/decide.mjs +30 -15
  10. package/deploy/.github/workflows/deploy-prerelease.yml +6 -50
  11. package/deploy/.github/workflows/deploy-prod.yml +103 -0
  12. package/deploy/scripts/deploy/plan-prod.sh +57 -0
  13. package/deploy/scripts/deploy/promote.sh +23 -7
  14. package/deploy/scripts/deploy/publish-bundle.sh +10 -1
  15. package/deploy/scripts/deploy/route-tag.sh +10 -12
  16. package/deploy/scripts/deploy/run-prerelease.sh +4 -7
  17. package/deploy/scripts/deploy/{run-production.sh → run-prod.sh} +15 -17
  18. package/deploy/scripts/deploy/writeback-ops.sh +71 -40
  19. package/hub/scripts/release/dispatch-release-lines.sh +25 -2
  20. package/hub/scripts/release/snapshot-members.sh +1 -1
  21. package/ops/.github/workflows/ops-deploy.yml +92 -11
  22. package/ops/schemas/targets.schema.json +209 -0
  23. package/ops/scripts/ci/check-targets.mjs +291 -0
  24. package/ops/scripts/deploy/apply-iac.sh +89 -0
  25. package/ops/scripts/deploy/apply-ops.sh +101 -48
  26. package/ops/scripts/deploy/ops-run.sh +50 -12
  27. package/ops/scripts/deploy/smoke.sh +35 -16
  28. package/ops/scripts/lib/ops-steps.sh +75 -0
  29. package/org/scripts/ci/check-org-values.mjs +91 -0
  30. package/package.json +2 -2
  31. package/publish/.github/workflows/publish.yml +12 -3
  32. package/publish/scripts/release/mirror-units.sh +45 -5
  33. package/publish/scripts/release/publish-units.sh +28 -4
  34. package/release/.github/workflows/advance-release.yml +107 -0
  35. package/release/.github/workflows/close-release.yml +133 -0
  36. package/release/.github/workflows/merge-back.yml +82 -0
  37. package/release/.github/workflows/merge-release-pr.yml +82 -0
  38. package/release/.github/workflows/open-release-line.yml +14 -5
  39. package/release/.github/workflows/release-line-finalize.yml +5 -3
  40. package/release/.github/workflows/release-please.yml +99 -15
  41. package/release/.github/workflows/sync-release-tools.yml +91 -0
  42. package/release/release-policy.json +1 -1
  43. package/release/schemas/release-policy.schema.json +13 -3
  44. package/release/scripts/ci/branch-exists.sh +27 -0
  45. package/release/scripts/ci/check-release-policy.sh +13 -2
  46. package/release/scripts/ci/pin-train.sh +5 -3
  47. package/release/scripts/ci/release-train.sh +22 -3
  48. package/release/scripts/lib/release-plan.sh +3 -1
  49. package/release/scripts/lib/release-pr.sh +275 -11
  50. package/release/scripts/lib/release-stages.sh +245 -27
  51. package/release/scripts/release/check-trigger-actor.sh +32 -0
  52. package/release/scripts/release/close-ready.mjs +72 -0
  53. package/release/scripts/release/close-ready.sh +70 -0
  54. package/release/scripts/release/cut-release.sh +34 -3
  55. package/release/scripts/release/ensure-stage-deploys.sh +3 -3
  56. package/release/scripts/release/finalize-release.sh +47 -15
  57. package/release/scripts/release/merge-back-ready.sh +27 -0
  58. package/release/scripts/release/merge-release-pr.sh +34 -107
  59. package/release/scripts/release/open-release-line.sh +28 -8
  60. package/release/scripts/release/pin-release-pr.sh +53 -0
  61. package/release/scripts/release/product-release-notes.sh +28 -0
  62. package/release/scripts/release/sync-release-tools.sh +137 -0
  63. package/release/scripts/release/{verify-production.sh → verify-prod.sh} +11 -10
  64. package/transform.mjs +2 -3
  65. package/verify/.github/workflows/{verify-production.yml → verify-prod.yml} +7 -7
  66. package/verify/scripts/release/verify-ops.sh +4 -4
  67. package/deploy/.github/workflows/deploy-production.yml +0 -173
  68. package/deploy/scripts/deploy/plan-production.sh +0 -43
  69. package/infra/.github/workflows/deploy-prerelease.yml +0 -157
  70. package/infra/.github/workflows/deploy-production.yml +0 -173
  71. package/infra/scripts/deploy/apply-infra.sh +0 -46
  72. package/infra/scripts/deploy/apply-prerelease.sh +0 -22
  73. package/infra/scripts/deploy/apply-production.sh +0 -33
  74. package/infra/scripts/deploy/route-tag.sh +0 -65
@@ -5,14 +5,14 @@
5
5
  # fails after the release (and its tag) was created (observed 2026-09-09 as a transient GitHub
6
6
  # GraphQL error) the dispatch step is skipped, and nothing retries: tags created with GITHUB_TOKEN
7
7
  # raise no push event. This script is idempotent, so release-please.yml runs it after every run,
8
- # including failed ones: it reads the manifest on the current branch, and for each app, service or infra unit with a
8
+ # including failed ones: it reads the manifest on the current branch, and for each app or service unit with a
9
9
  # prerelease version whose tag exists, looks at the newest deploy-prerelease run of the tag. No run, or a run that
10
10
  # failed while the run before it did not, dispatches one again. Two failed runs in a row are not dispatched again:
11
11
  # the script prints ✗ with both run ids and ends 1 after it went through every unit, so the failure is seen and a
12
12
  # persistent one is not retried on every run. A run that is still going, or succeeded, counts as dispatched, and
13
13
  # so does the run a retry started. A tag with nothing to
14
14
  # deploy at its stage (no environment declared for the unit, scripts/deploy/route-tag.sh) is skipped, not
15
- # dispatched. A repository without apps/, services/ or infra/ units has nothing to look at, so it never reaches route-tag.sh.
15
+ # dispatched. A repository without apps/ or services/ units has nothing to look at, so it never reaches route-tag.sh.
16
16
  #
17
17
  # usage: ensure-stage-deploys.sh (env: GH_TOKEN)
18
18
  set -euo pipefail
@@ -21,7 +21,7 @@ cd "$(git rev-parse --show-toplevel)"
21
21
  units="$(jq -r --slurpfile cfg release-please-config.json '
22
22
  ($cfg[0].packages) as $pkgs
23
23
  | to_entries[]
24
- | select(.key | startswith("apps/") or startswith("services/") or startswith("infra/"))
24
+ | select(.key | startswith("apps/") or startswith("services/"))
25
25
  | select(.value | test("-"))
26
26
  | "\($pkgs[.key].component // (.key | split("/")[1])) \(.value)"
27
27
  ' .release-please-manifest.json)"
@@ -21,7 +21,11 @@
21
21
  # diff", which carries whatever landed on main during stabilisation and was never released.
22
22
  # A hotfix train rebuilt from that tag would drag those unreleased changes into a patch.
23
23
  #
24
- # usage: finalize-release.sh --line X.Y --phase ga|merge-back|close [--yes] [--dry-run]
24
+ # usage: finalize-release.sh --line X.Y --phase ga|merge-back|close [--head-sha <sha>] [--yes] [--dry-run]
25
+ # --head-sha close only: the head commit of the merge-back PR that was checked (the head_sha of the event that started the
26
+ # close workflow). A PR whose head is another commit is not merged. Left out, the head read just before the merge is used.
27
+ # Either way the merge carries --match-head-commit, so a commit pushed after the read is refused by GitHub.
28
+ # close does not merge a PR that conflicts with main either: it stops and says to run merge-back again.
25
29
  #
26
30
  # The product version is the one in the Release-Plan trailer cut-release.sh wrote when it opened the train
27
31
  # (the plan, releases/release-plan-vX.Y.Z.md, is where versions are assigned). Every release has one: a
@@ -32,11 +36,12 @@ set -euo pipefail
32
36
  source "$(dirname "$0")/../lib/common.sh"
33
37
  cd "$REPO_ROOT"
34
38
 
35
- line="" phase="" product=""
39
+ line="" phase="" product="" head_sha=""
36
40
  while [[ $# -gt 0 ]]; do
37
41
  case "$1" in
38
42
  --line) line="$2"; shift 2 ;;
39
43
  --phase) phase="$2"; shift 2 ;;
44
+ --head-sha) head_sha="$2"; shift 2 ;;
40
45
  --yes) ASSUME_YES=1; export ASSUME_YES; shift ;;
41
46
  --dry-run) DRY_RUN=1; shift ;;
42
47
  -h|--help) sed -n '2,${/^#/!q; p;}' "$0"; exit 0 ;;
@@ -94,7 +99,7 @@ case "$phase" in
94
99
  fi
95
100
  external_retry push "$target" git push origin "$branch"
96
101
  printf '\n'
97
- info "下一步:scripts/release/merge-release-pr.sh --line $line 合併 Release PR → 各單元正式 tag → production(tag 白名單)。"
102
+ info "下一步:scripts/release/merge-release-pr.sh --line $line 合併 Release PR → 各單元正式 tag → prod(tag 白名單)。"
98
103
  info "之後執行:finalize-release.sh --line $line --phase merge-back"
99
104
  ;;
100
105
 
@@ -104,18 +109,18 @@ case "$phase" in
104
109
  run git fetch --prune --tags origin
105
110
  run git merge --ff-only "origin/$branch"
106
111
  resolve_product
112
+ # 這條線還有開著的 Release PR,代表 GA 的 Release PR 沒合併:此時合回,發布分支之後還會有 release-please 的 commit
113
+ train_open_release_pr_check "$branch" || die "不合回:${branch} 的 Release PR 還開著"
107
114
  declare -a units=()
108
115
  while IFS= read -r u; do [[ -n "$u" ]] && units+=("$u"); done < <(train_units_by_manifest)
109
116
  # 沒有單元升版的發布線照常收尾:產品版號寫進發布分支、合回 main,close 再打產品 tag。參與一次產品發布
110
117
  # 但這次沒有單元變動的倉(例如只放 plan 的 hub)就是這種線。
111
118
  (( ${#units[@]} )) || info "本分支與 main 的 manifest 無差異:這條線沒有單元升版,只發產品 v${product}"
112
119
  declare -a paths=() missing=()
113
- for u in ${units[@]+"${units[@]}"}; do
114
- p="$(unit_path "$u")"; paths+=("$p")
115
- v="$(manifest_version "$p")"
116
- [[ "$v" == *-* ]] && { missing+=("$u 仍是 prerelease $v"); continue; }
117
- git rev-parse -q --verify "refs/tags/$u/v$v" >/dev/null || missing+=("$u/v$v")
118
- done
120
+ for u in ${units[@]+"${units[@]}"}; do p="$(unit_path "$u")"; paths+=("$p"); done
121
+ # 最終 tag 齊了沒的判斷(train_final_tags_missing)和 release-please 的 job 決定要不要開合回共用同一個函式。
122
+ # 清單是開線 commit 的 Release-Train-Units 扣掉沒有可發 commit 的單元,不看 manifest 差異
123
+ while IFS= read -r m; do [[ -n "$m" ]] && missing+=("$m"); done < <(train_final_tags_missing)
119
124
  (( ${#missing[@]} == 0 )) || die "GA 尚未完成:${missing[*]}(先合併 Release PR 並等 tag 建立)"
120
125
 
121
126
  # 發布分支的最後一個 commit 就是產品 tag 的位置,它的樹要等於實際發布的內容,所以在這裡把發布分支
@@ -159,13 +164,15 @@ Release-Train-Units: $train_units}"
159
164
  declare -a pending=()
160
165
  while IFS= read -r c; do [[ -n "$c" ]] && pending+=("${c%% *}"); done <<< "$pending_list"
161
166
  sync_branch="${branch}--to-main"
167
+ # 不進 main 的檔:發布分支自己的設定檔,和這次發布另外提交在分支上的政策檔(縮短某些單元階段的覆寫只屬於這條線)。
168
+ MERGE_BACK_EXCLUDE=(':!release-please-config.json' ':!release-policy.json')
162
169
  log "在 main 之上建立合回分支 ${sync_branch}(套用發布分支上 main 還沒有的 ${#pending[@]} 個 commit)"
163
170
  run git switch -C "$sync_branch" origin/main
164
171
  for c in "${pending[@]}"; do
165
172
  if (( DRY_RUN )); then info "[dry-run] 套用 $(git log -1 --format='%h %s' "$c")"; continue; fi
166
173
  # 失敗多半是 apply 留下衝突。有 facts/ 時交給 fact-kit merge-since 解只差 since 的衝突;其他差異、
167
174
  # 非衝突的失敗與沒有 facts/ 的倉庫都在這裡停下。每次重跑都從 origin/main 重建合回分支,手動解的不會保留。
168
- if ! git diff "$c^" "$c" -- . ':!release-please-config.json' | git apply --3way --allow-empty; then
175
+ if ! git diff "$c^" "$c" -- . "${MERGE_BACK_EXCLUDE[@]}" | git apply --3way --allow-empty; then
169
176
  facts_settle_since_conflicts "$(git log -1 --format='%h %s' "$c")"
170
177
  fi
171
178
  done
@@ -242,16 +249,40 @@ BODY
242
249
  require_clean_tree
243
250
  run git fetch --prune --tags origin
244
251
  resolve_product
252
+ train_open_release_pr_check "$branch" || die "不收尾:${branch} 的 Release PR 還開著,沒有合併、打 tag 或刪分支"
245
253
  sync_branch="${branch}--to-main"
246
254
  title="chore(release): product v$product → main"
247
255
 
256
+ # 0. 產品 tag 要打在發布分支的最後一個 commit,那個 commit 的內容就是發布的內容。合回之後又有人推到發布分支
257
+ # (例如遲到的 hotfix),main 沒有它,tag 卻會指到它。有這種 commit 就停下,先列出來,不合併、不打 tag、
258
+ # 不刪分支。tag 已建立(重跑 close)或分支已不在時沒有這個問題。
259
+ if ! git rev-parse -q --verify "refs/tags/v$product" >/dev/null && git rev-parse -q --verify "refs/remotes/origin/$branch" >/dev/null; then
260
+ late="$(train_commits_after_merge_back "origin/$branch" "$product")" || die "無法列出 $branch 在合回之後的 commit"
261
+ if [[ -n "$late" ]]; then
262
+ printf '%s\n' "$late" | sed 's/^/ /' >&2
263
+ die "$branch 在合回之後多了上面這些 main 沒有的 commit:產品 tag 會指到 main 沒有的內容。把它們也合進 main(或移出發布分支),再重跑 merge-back 與 close。沒有打 tag,也沒有刪分支"
264
+ fi
265
+ fi
266
+
248
267
  # 1. 合併 release PR。合併訊息由這裡指定:GitHub 預設的 squash 訊息會在 PR 內文後面接上各 commit 的
249
268
  # 標題,Release-Train-Base 就不在最後一段,git 讀不成 trailer(v0.5.0 實際發生,見待辦 i030)。
250
269
  pr="$(gh pr list --base main --head "$sync_branch" --state open --json number --jq '.[0].number // empty' 2>/dev/null || true)"
251
270
  if [[ -n "$pr" ]]; then
252
- body="$(gh pr view "$pr" --json body --jq .body)"
253
- log "以 squash 合併 release PR #${pr},合併訊息為 PR 標題與內文,Release-Train-Base 在最後一行"
254
- external_retry merge "$target" gh pr merge "$pr" --squash --subject "$title (#$pr)" --body "$body"
271
+ pr_json="$(gh pr view "$pr" --json body,headRefOid,mergeable)"
272
+ body="$(jq -r .body <<<"$pr_json")"
273
+ pr_head="$(jq -r .headRefOid <<<"$pr_json")"
274
+ # The head of the PR must be the commit that was checked. Merging another head would put into main a commit that no check ran for.
275
+ if [[ -n "$head_sha" && "$head_sha" != "$pr_head" ]]; then
276
+ die "release PR #${pr} 的 head 是 ${pr_head:0:7},不是檢查過的 ${head_sha:0:7}:檢查之後又有 commit。沒有合併,也沒有打 tag 或刪分支。新 head 的檢查完成後會再帶出收尾"
277
+ fi
278
+ # main moved after the merge-back PR was made and the two now conflict: the PR cannot be merged, and waiting does not change that.
279
+ # Running merge-back again builds the branch on the new main, pushes a new head and starts new checks; their end starts close again.
280
+ # UNKNOWN is GitHub still working it out, and the merge below is refused if it is a conflict after all.
281
+ if [[ "$(jq -r .mergeable <<<"$pr_json")" == CONFLICTING ]]; then
282
+ die "release PR #${pr} 與 main 有衝突(main 在合回 PR 建好之後又前進了),不能合併。沒有合併,也沒有打 tag 或刪分支。重跑合回:scripts/release/finalize-release.sh --line $line --phase merge-back(或 merge-back workflow),它在新的 main 上重建合回分支並推出新的 head,新的檢查跑完會再帶出收尾"
283
+ fi
284
+ log "以 squash 合併 release PR #${pr}(head ${pr_head:0:7}),合併訊息為 PR 標題與內文,Release-Train-Base 在最後一行"
285
+ external_retry merge "$target" gh pr merge "$pr" --squash --match-head-commit "${head_sha:-$pr_head}" --subject "$title (#$pr)" --body "$body"
255
286
  run git fetch --prune --tags origin
256
287
  fi
257
288
  if [[ -z "$(git log origin/main --format=%H --grep="product v$product" -n 1)" ]]; then
@@ -268,8 +299,9 @@ BODY
268
299
  fix_units="$(train_units_of "$train_ref")"
269
300
  fix_units_line="${fix_units:+
270
301
  Release-Train-Units: $fix_units}"
271
- # 先存成字串再比對:pipefail 之下,grep -q 提早結束會讓 git log 收到 SIGPIPE,整條管線被判為失敗。
272
- main_has_base() { grep -qx "$base" <<<"$(git log origin/main -n 20 --format='%(trailers:key=Release-Train-Base,valueonly)')"; }
302
+ # 不限筆數:合回 PR 等 CI 的期間 main 會繼續前進,這次的 commit 可能在 20 筆以前。範圍由 --grep 限縮
303
+ # (main_has_train_base,在 release-stages.sh)。
304
+ main_has_base() { main_has_train_base "$base"; }
273
305
  if ! main_has_base; then
274
306
  log "main 讀不到這次的 Release-Train-Base ${base:0:7},補一個只帶 trailer 的 commit"
275
307
  if (( DRY_RUN == 0 )); then
@@ -0,0 +1,27 @@
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 and every final tag the
3
+ # train needs exists. Prints GitHub Actions outputs on stdout (append to $GITHUB_OUTPUT) and the reason on stderr. It looks once
4
+ # and always exits 0, because a condition that does not hold yet is the normal case for most runs of release-please.
5
+ #
6
+ # usage: merge-back-ready.sh
7
+ # ready=true|false
8
+ #
9
+ # The decision is train_merge_back_ready (scripts/lib/release-stages.sh), the same check finalize-release.sh --phase merge-back
10
+ # stops on. Fetches the tags first: release-please makes the tags of the GA Release PR in the run that asks.
11
+ set -euo pipefail
12
+ source "$(dirname "$0")/../lib/common.sh"
13
+ cd "$REPO_ROOT"
14
+
15
+ branch="$(current_branch)"
16
+ if ! [[ "$branch" =~ ^release/v[0-9]+\.[0-9]+$ ]]; then
17
+ warn "${branch:-(detached)} 不是發布線,不合回"
18
+ echo "ready=false"
19
+ exit 0
20
+ fi
21
+ git fetch -q --tags origin main "$branch" || die "git fetch origin 沒成功,無法判斷最終 tag 齊了沒"
22
+ if train_merge_back_ready; then
23
+ echo "ready=true"
24
+ else
25
+ warn "$TRAIN_MERGE_BACK_WAITING"
26
+ echo "ready=false"
27
+ fi
@@ -2,26 +2,34 @@
2
2
  # Merge the Release PR of a release line. This is the one way to merge it: the fact-kit check below is only
3
3
  # a gate when the merge goes through it, because a private repository on the free plan cannot make a
4
4
  # check required.
5
+ # The pin (step 3) is normally done earlier, by the release-please job after it has written the Release PR
6
+ # (scripts/release/pin-release-pr.sh, which calls the same release_pin_open_pr as this script). This script pins too, as the
7
+ # fallback for a repository without the GitHub App, and for a pin that job missed or did not finish.
5
8
  #
6
9
  # usage: merge-release-pr.sh --line X.Y [--yes] [--dry-run]
7
10
  #
8
11
  # Order, on release/vX.Y:
9
- # 1. wait until no release-please run is queued and the Release PR's head has stopped moving
12
+ # 1. release-please must have processed the branch (release_please_settled in scripts/lib/release-pr.sh): no run queued or in
13
+ # progress, and no path it watches differs between its newest finished run and the branch tip. When it has not, the
14
+ # script stops after POLL_TRIES looks and merges nothing, on a machine as in a workflow. Then the Release PR's head must stop moving
10
15
  # 2. the units this merge releases: the manifest on the PR's head against origin/release/vX.Y, the PR's
11
16
  # version for each unit that differs. Each version is checked before anything else happens (see below)
12
- # 3. with facts/: for each unit that has a component package (its directory under facts/ is named after the unit),
17
+ # 3. release_pin_open_pr (scripts/lib/release-pr.sh) checks that no commit release-please processes (a releasable commit on a unit path, or a change of the config or
18
+ # manifest) lies between the base of the Release PR and the branch tip, checks the versions once more, then pins. With facts/: for each unit that has a component
19
+ # package (its directory under facts/ is named after the unit),
13
20
  # `fact-kit pin --version <v> --cwd facts/<dir>`. Pinned rows are committed on the release branch as
14
21
  # `chore(facts)`; the branch is pushed whenever it is ahead of origin, so a run whose push was skipped or
15
22
  # failed pushes on the next run. Never on the PR branch, which release-please rewrites with force
16
- # 4. wait for release-please again, and stop if the PR now releases something else than what was pinned
23
+ # 4. after the push the script stops: the push makes release-please run again and recompute the PR. Run it again once
24
+ # release-please has processed the pin commit; the second run has nothing to pin, checks the versions and merges
17
25
  # 5. `fact-kit check --train <unit>=<v>` for those units. A row still saying "next" that is not pending
18
26
  # fails it, printed as <file>:<line>. This script does not pin again on its own: fix the row (or mark it
19
27
  # pending) and run the script again
20
28
  # 6. `gh pr merge --squash --match-head-commit <sha>`
21
- # A repository without facts/ skips 3 and 5 and merges.
29
+ # A repository without facts/ pins no facts and skips 5, and merges.
22
30
  #
23
31
  # Version check (git-release asks for it, and a wrong Release PR was merged without it: sdk-py and sdk-rs went from
24
- # 0.1.0 to 0.2.0-alpha.1). Right after step 2, and again after the branch was pushed, every unit's PR version is
32
+ # 0.1.0 to 0.2.0-alpha.1). Right after step 2 every unit's PR version is
25
33
  # compared with what it must be:
26
34
  # - a unit with no <component>/v* tag on the remote: the first version of unit_first_version (the same function
27
35
  # advance-release.sh and finalize-release.sh write Release-As from), e.g. 0.1.0-beta.1
@@ -54,7 +62,6 @@ while [[ $# -gt 0 ]]; do
54
62
  done
55
63
  [[ "$line" =~ ^[0-9]+\.[0-9]+$ ]] || die "--line 需為 X.Y"
56
64
  branch="release/v$line"
57
- target="$(remote_target)"
58
65
 
59
66
  require_clean_tree
60
67
  [[ "$(current_branch)" == "$branch" ]] || die "請在 $branch 上執行(目前 $(current_branch))"
@@ -62,12 +69,12 @@ train_sync "$branch"
62
69
 
63
70
  if (( DRY_RUN )); then
64
71
  log "[dry-run] 合併 $branch 的 Release PR 的順序:"
65
- info "1. 等 release-please 閒置、Release PR 的 head 穩定"
72
+ info "1. release-please 要處理完(沒有排隊或執行中的 run,最新的 run 之後 release-please 會看的路徑沒有差異),等不到就中止;然後等 Release PR 的 head 穩定"
66
73
  if has_facts; then
67
74
  info "2. 這次要釘的單元:Release PR 的 manifest 對 origin/$branch 有差異的單元,版號取 PR 的值"
68
75
  info " 同時核對每個單元的 PR 版號:沒有 tag 的單元要等於第一版版號,有 tag 的單元階段要對上設定且不晚於它在這條線的結果階段;不符就重讀 PR,等到對上或逾時才停"
69
76
  info "3. 逐個 component 套件 fact-kit pin --version <v>,有變動才提交並推送 chore(facts)"
70
- info "4. 再等閒置,確認 PR 沒變"
77
+ info "4. 有推送釘版 commit 時中止,印出等 release-please 處理完再觸發;沒有推送才往下"
71
78
  info "5. fact-kit check --train <單元>=<v>"
72
79
  info "對得到 component 套件的單元:"
73
80
  facts_components | sed 's/^/ /' | tr '\t' ' '
@@ -93,55 +100,17 @@ read_units() {
93
100
  local out row
94
101
  git fetch -q origin "$branch" || die "取 manifest 失敗:git fetch origin $branch 沒成功"
95
102
  out="$(release_pr_units "$branch")" || die "取 manifest 失敗:讀不到 Release PR 或 origin/${branch} 的 manifest,不是「沒有差異」"
96
- while IFS= read -r row; do [[ -n "$row" ]] && units+=("$row"); done < <(sort <<<"$out")
103
+ while IFS= read -r row; do [[ -z "$row" ]] || units+=("$row"); done < <(sort <<<"$out")
97
104
  }
98
105
  read_units
99
106
  (( ${#units[@]} )) || die "Release PR #${n} 對 origin/${branch} 的 manifest 沒有差異,沒有可合併的版號"
100
107
 
101
- # check_unit_version <unit> <pr version> → adds a line to version_problems when the version is not what it must be.
102
- # Runs in the shell itself, not in $(...), because unit_released stops the script when it cannot read the tags.
103
- declare -a version_problems=()
104
- check_unit_version() {
105
- local u="$1" v="$2" p type base stage vs line_stage latest cur want
106
- p="$(jq -r --arg u "$u" '.packages | to_entries[] | select((.value.component // (.key | split("/") | last)) == $u) | .key' "$CONFIG" | head -1)"
107
- [[ -n "$p" ]] || return 0
108
- stage="$(config_unit_stage "$p")"
109
- # once the line is at ga the Release PR carries final versions, while the config of a unit still says its last prerelease
110
- # stage until the merge-back restores it
111
- [[ "$(train_stage)" != ga ]] || stage=ga
112
- if unit_released "$u"; then
113
- if ! vs="$(version_stage "$v")"; then
114
- version_problems+=("${u} PR 版號 ${v},預期階段 ${stage} 的版號(X.Y.Z 或 X.Y.Z-<階段>.N)")
115
- return 0
116
- fi
117
- # a unit that only walks ga ships its final version at once, so on an early line its own stage (ga) is the latest
118
- # one it may be in; any other unit may not be later than the line
119
- line_stage="$(train_stage)"
120
- latest="$line_stage"
121
- if policy_unit_exists "$u"; then
122
- latest="$(unit_stage_at "$u" "$line_stage")"
123
- [[ -n "$latest" ]] || latest="$line_stage"
124
- (( $(stage_index "$latest") >= $(stage_index "$line_stage") )) || latest="$line_stage"
125
- fi
126
- if [[ "$vs" != "$stage" ]] || (( $(stage_index "$vs") > $(stage_index "$latest") )); then
127
- version_problems+=("${u} PR 版號 ${v},預期階段 ${stage}(設定裡的階段,且不晚於 ${latest})")
128
- fi
129
- return 0
130
- fi
131
- type="$(unit_release_type "$p")"
132
- base="$(unit_main_base_version "$p" "$line")"
133
- cur="$(git show "origin/$branch:$MANIFEST" | jq -r --arg p "$p" '.[$p] // empty')"
134
- want="$(unit_first_version "$type" "$base" "$stage" "$line" "$cur")"
135
- [[ "$v" == "$want" ]] || version_problems+=("${u} PR 版號 ${v},預期 ${want}(沒有 tag,第一版)")
136
- return 0
137
- }
138
-
139
108
  # verify_versions: check every unit; on a mismatch read the PR again and check again, up to POLL_TRIES times
109
+ # shellcheck disable=SC2154 # version_problems is set by release_pr_check_versions in release-pr.sh
140
110
  verify_versions() {
141
- local i pair
111
+ local i
142
112
  for ((i=1; i<=POLL_TRIES; i++)); do
143
- version_problems=()
144
- for pair in "${units[@]}"; do check_unit_version "${pair% *}" "${pair#* }"; done
113
+ release_pr_check_versions "$line" "$branch" "${units[@]}"
145
114
  (( ${#version_problems[@]} )) || return 0
146
115
  if (( i == POLL_TRIES )); then
147
116
  printf '✗ Release PR #%s 的版號不符,不合併:\n' "$n" >&2
@@ -159,63 +128,21 @@ verify_versions() {
159
128
  verify_versions
160
129
  info "這次合併會發:${units[*]}"
161
130
 
162
- if has_facts; then
163
- declare -A comp_units=()
164
- comps="$(facts_components)"
165
- while IFS=$'\t' read -r _ u; do [[ -n "$u" ]] && comp_units[$u]=1; done <<<"$comps"
166
- declare -a pinned=()
167
- for pair in "${units[@]}"; do
168
- u="${pair% *}" v="${pair#* }"
169
- [[ -n "${comp_units[$u]:-}" ]] || continue
170
- facts_pin "$u" "$v"
171
- pinned+=("$u@$v")
172
- done
173
- if [[ -n "$(git status --porcelain -- facts)" ]]; then
174
- git add -- facts
175
- run git commit -q -m "chore(facts): 釘 next 為 ${pinned[*]}" \
176
- -m "合併 Release PR #${n} 之前,把這次要發的單元的 next 釘成 PR 的版號。釘在發布分支,不放 Release PR 分支,因為 release-please 重算時會強制改寫它。"
177
- else
178
- info "⊘ 沒有要釘的 next,不加新的 commit"
179
- fi
180
- fi
181
-
182
- # 文件套件:和 facts 同一個位置釘,用 clarify-kit pin。docs/<單元> 存在的單元,才釘成 PR 給它的版號
183
- if has_docs; then
184
- declare -a docs_pinned=()
185
- for pair in "${units[@]}"; do
186
- u="${pair% *}" v="${pair#* }"
187
- docs_unit_dir "$u" >/dev/null || continue
188
- docs_pin_unit "$u" "$v"
189
- docs_pinned+=("$u@$v")
190
- done
191
- if [[ -n "$(git status --porcelain -- docs)" ]]; then
192
- git add -- docs
193
- run git commit -q -m "chore(docs): 釘 next 為 ${docs_pinned[*]}" \
194
- -m "合併 Release PR #${n} 之前,把這次要發的單元的文件 next 釘成 PR 的版號。釘在發布分支,不放 Release PR 分支,因為 release-please 重算時會強制改寫它。"
195
- else
196
- info "⊘ 文件套件沒有要釘的 next,不加新的 commit"
197
- fi
198
- fi
199
-
200
- if has_facts || has_docs; then
201
- # 看本機是否領先遠端,不看這次有沒有新變動:上一次可能建好 commit 卻沒推出去(答 n、沒帶 --yes、推送失敗),
202
- # 重跑時 facts 已乾淨,只看變動會跳過推送,check 讀本機工作樹通過,釘版卻沒到遠端
203
- if (( $(git rev-list --count "origin/$branch..HEAD") > 0 )); then
204
- external_retry push "$target" git push origin "$branch"
205
- if (( ${#SKIPPED_EXTERNAL[@]} )); then
206
- warn "推送沒有執行,停在這裡:確認後帶 --yes 重跑"
207
- exit 0
208
- fi
209
- # 推送會讓 release-please 再跑一次,PR 可能被重算
210
- release_pr_settle "$branch" ${settle_opts[@]+"${settle_opts[@]}"}
211
- n="$RELEASE_PR_NUMBER" sha="$RELEASE_PR_SHA"
212
- before="${units[*]}"
213
- read_units
214
- [[ "${units[*]}" == "$before" ]] \
215
- || die "釘版期間 Release PR #${n} 變了(原本 ${before},現在 ${units[*]}),版號可能對不上。重跑本腳本"
216
- verify_versions
217
- fi
218
- fi
131
+ # 釘版:和 release-please 的 job 共用同一個函式(release_pin_open_pr,scripts/lib/release-pr.sh)。它先確認 Release PR 的基底
132
+ # 到發布分支尖端之間沒有差異、再核對一輪版號,才釘 facts 與文件套件的 next、提交並推送。上面已經等到 release-please 處理完
133
+ # 並核對過版號,這裡再核對一輪是因為釘版前的最後一道關:這之間 Release PR 若被重算,函式不釘,這裡也不合併。
134
+ release_pin_open_pr "$branch" "$line" || die "釘版後推送 ${branch} 沒成功,沒有合併"
135
+ case "$RELEASE_PIN_RESULT" in
136
+ unchanged) ;;
137
+ push-skipped)
138
+ warn "推送沒有執行,停在這裡:確認後帶 --yes 重跑"
139
+ exit 0 ;;
140
+ pinned)
141
+ # 推送會讓 release-please 再跑一次,Release PR 之後會被重算。這裡不等,因為 workflow 的 job 不能空等,
142
+ # 本機也一樣:釘完推送就停,等 release-please 處理完這個 commit 再重跑,重跑時沒有東西要釘,直接核對並合併。
143
+ die "已釘版並推送 ${branch}($(git rev-parse --short HEAD)),沒有合併。等 release-please 處理完這個 commit 之後再觸發一次(merge-release-pr.sh --line ${line}),重跑時沒有要釘的,會核對版號後合併" ;;
144
+ *) die "沒有釘版,也沒有合併(${RELEASE_PIN_RESULT}):${RELEASE_PIN_REASON:-Release PR 已不存在}。等 release-please 處理完再觸發一次" ;;
145
+ esac
219
146
 
220
147
  if has_facts; then
221
148
  # 等待期間可能又有修補合進發布分支。check 要讀合併時發布分支的內容,所以先同步到遠端最新
@@ -1,22 +1,42 @@
1
1
  #!/usr/bin/env bash
2
- # Open a release train from a Release Plan that arrived as a workflow input. open-release-line.yml runs this
3
- # in a member repository when the hub dispatches it: the hub passes the product version, the content of the
4
- # plan and this repository's units, so the member reads nothing from the hub and holds no credential for it.
2
+ # Open a release train from a workflow run. open-release-line.yml runs this in the repository that holds the line.
3
+ # A member repository gets the Release Plan as a workflow input: the hub passes the product version, the content of
4
+ # the plan and this repository's units, so the member reads nothing from the hub and holds no credential for it.
5
+ # A repository that holds its own plans (a single-repository product, the hub, a repository of the organization layer)
6
+ # needs no content: the plan is committed on main under releases/ and cut-release.sh reads it from there.
5
7
  #
6
8
  # usage: open-release-line.sh
7
9
  # env: PLAN the product version, vX.Y.Z
8
- # PLAN_CONTENT the content of releases/release-plan-vX.Y.Z.md of the hub
10
+ # PLAN_CONTENT optional. The content of releases/release-plan-vX.Y.Z.md of the hub. Required in a member repository
11
+ # (its policy file has product.primary), because the plan is not in this repository. When it is empty
12
+ # in any other repository, the plan of this repository's releases/ is used.
9
13
  # UNITS comma list of this repository's units in the plan
10
14
  # FROM optional, main (default) or the latest product tag of the line, passed to cut-release.sh --from.
11
15
  # A line that already shipped takes patches only and has to be cut from its latest product tag.
12
- # It writes the content to release-plan-<PLAN>.md in a temporary directory and calls
13
- # cut-release.sh --plan <PLAN> --plan-file <that file> --units <UNITS> --from <FROM> --yes.
16
+ # STAGES_OVERRIDE optional. The stages of some units for this release only, a JSON object {"<unit>":["rc","ga"]}, passed to
17
+ # cut-release.sh --stages-override, which checks the format and stops with the reason when it is wrong. The
18
+ # override goes into release-policy.json on the new release branch. It is read from the environment and never
19
+ # interpolated into a command.
20
+ # With content it writes it to release-plan-<PLAN>.md in a temporary directory and calls
21
+ # cut-release.sh --plan <PLAN> --plan-file <that file> --units <UNITS> --from <FROM> --yes. Without content it calls
22
+ # cut-release.sh --plan <PLAN> --units <UNITS> --from <FROM> --yes.
14
23
  set -euo pipefail
15
24
  plan="${PLAN:?PLAN is required (vX.Y.Z)}"
16
25
  units="${UNITS:?UNITS is required (comma list of units)}"
17
- content="${PLAN_CONTENT:?PLAN_CONTENT is required (the content of the Release Plan)}"
26
+ content="${PLAN_CONTENT:-}"
18
27
  [[ "$plan" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { printf '%s\n' >&2 "✗ PLAN 需為 vX.Y.Z:$plan"; exit 1; }
28
+ declare -a extra=()
29
+ [[ -z "${STAGES_OVERRIDE:-}" ]] || extra=(--stages-override "$STAGES_OVERRIDE")
30
+ if [[ -z "$content" ]]; then
31
+ policy="${RELEASE_POLICY:-$(git rev-parse --show-toplevel)/release-policy.json}"
32
+ [[ -f "$policy" ]] || { printf '%s\n' >&2 "✗ 找不到政策檔 $policy"; exit 1; }
33
+ if [[ -n "$(jq -r '.product.primary // empty' "$policy")" ]]; then
34
+ printf '%s\n' >&2 "✗ 這是成員倉,Release Plan 在 hub,不在這個倉裡。派送時要貼 plan_content(hub 的 releases/release-plan-${plan}.md 的內容)"
35
+ exit 1
36
+ fi
37
+ exec bash "$(dirname "$0")/cut-release.sh" --plan "$plan" --units "$units" --from "${FROM:-main}" "${extra[@]+"${extra[@]}"}" --yes
38
+ fi
19
39
  dir="$(mktemp -d)"
20
40
  trap 'rm -rf "$dir"' EXIT
21
41
  printf '%s\n' "$content" > "$dir/release-plan-$plan.md"
22
- bash "$(dirname "$0")/cut-release.sh" --plan "$plan" --plan-file "$dir/release-plan-$plan.md" --units "$units" --from "${FROM:-main}" --yes
42
+ bash "$(dirname "$0")/cut-release.sh" --plan "$plan" --plan-file "$dir/release-plan-$plan.md" --units "$units" --from "${FROM:-main}" "${extra[@]+"${extra[@]}"}" --yes
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env bash
2
+ # Pin the "next" of facts/ and docs/ to the versions of the open Release PR of a release line, commit and push. The step the
3
+ # release-please job runs after release-please has written the Release PR (the pin the merge workflow does too, as its fallback).
4
+ #
5
+ # usage: pin-release-pr.sh --line X.Y [--yes]
6
+ #
7
+ # What it does is release_pin_open_pr (scripts/lib/release-pr.sh): no open Release PR, a branch that moved after the Release PR
8
+ # was written, or a version that is not what the policy gives each end in "nothing pinned, success", because the same event
9
+ # comes many times and most of them are not the time to pin. The next run of release-please writes the PR again and asks again.
10
+ #
11
+ # The push is refused when the branch moved between the fetch and the push. Then the pin commits it made are dropped, the branch
12
+ # is brought to origin, and the whole check and pin runs once more (the second look finds the PR stale and pins nothing, or
13
+ # pins again on the new tip). A commit that is not a pin commit is never dropped.
14
+ # The release branch must be checked out, with a clean tree.
15
+ set -euo pipefail
16
+ source "$(dirname "$0")/../lib/common.sh"
17
+ cd "$REPO_ROOT"
18
+
19
+ line=""
20
+ while [[ $# -gt 0 ]]; do
21
+ case "$1" in
22
+ --line) line="$2"; shift 2 ;;
23
+ --yes) ASSUME_YES=1; export ASSUME_YES; shift ;;
24
+ -h|--help) sed -n '2,${/^#/!q; p;}' "$0"; exit 0 ;;
25
+ *) die "unknown argument: $1" ;;
26
+ esac
27
+ done
28
+ [[ "$line" =~ ^[0-9]+\.[0-9]+$ ]] || { info "⊘ --line 不是 X.Y(${line:-沒給}),這不是發布線,不釘版"; exit 0; }
29
+ branch="release/v$line"
30
+
31
+ require_clean_tree
32
+ [[ "$(current_branch)" == "$branch" ]] || die "請在 $branch 上執行(目前 $(current_branch))"
33
+ train_sync "$branch"
34
+
35
+ for attempt in 1 2; do
36
+ status=0
37
+ release_pin_open_pr "$branch" "$line" || status=$?
38
+ case "$RELEASE_PIN_RESULT" in
39
+ pinned) info "已釘版並推送 ${branch}($(git rev-parse --short HEAD))。release-please 會再跑一次,第二次沒有變動就停" ;;
40
+ push-skipped) warn "推送沒有執行" ;;
41
+ push-failed) ;;
42
+ *) info "沒有釘版(${RELEASE_PIN_RESULT})${RELEASE_PIN_REASON:+:$RELEASE_PIN_REASON}" ;;
43
+ esac
44
+ (( status != 0 )) || exit 0
45
+ (( attempt == 1 )) || die "推送 ${branch} 被拒兩次,不再重試。等下一次 run"
46
+ warn "推送 ${branch} 被拒,取回最新的分支再試一次"
47
+ git fetch -q origin "$branch" || die "git fetch origin $branch 沒成功"
48
+ while IFS= read -r subject; do
49
+ [[ "$subject" == "chore(facts): "* || "$subject" == "chore(docs): "* ]] \
50
+ || die "本機領先遠端的 commit 不全是釘版 commit(${subject}),不丟掉它們"
51
+ done < <(git log --format=%s "origin/$branch..HEAD")
52
+ git reset -q --hard "origin/$branch"
53
+ done
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+ # Put the Snapshot on the GitHub Release of a product tag: create the Release with the Snapshot as its notes, or
3
+ # replace the notes of the Release that already exists.
4
+ #
5
+ # The deploy-prod workflow (publish-bundle.sh) creates the Release of the same tag when it attaches the bundles,
6
+ # with the notes "bundles of <tag>", and it can win the race by a few seconds. So the notes are set with edit
7
+ # whenever the Release exists, which keeps its title and its assets. A create that fails while no Release exists
8
+ # (a missing permission, a tag that is not on the remote) fails the script, instead of reporting a Release that
9
+ # was never made.
10
+ #
11
+ # usage: product-release-notes.sh <tag> <snapshot.md>
12
+ # env: GH_TOKEN a token that can write Releases of this repository
13
+ set -euo pipefail
14
+ tag="${1:?usage: product-release-notes.sh <tag> <snapshot.md>}"
15
+ notes="${2:?missing snapshot file}"
16
+ [[ -f "$notes" ]] || { printf '%s\n' >&2 "找不到 Snapshot 檔:$notes"; exit 1; }
17
+ repo="${GITHUB_REPOSITORY:-$(gh repo view --json nameWithOwner --jq .nameWithOwner)}"
18
+ if ! gh release view "$tag" --repo "$repo" >/dev/null 2>&1; then
19
+ rc=0
20
+ gh release create "$tag" --repo "$repo" --title "$tag" --notes-file "$notes" || rc=$?
21
+ if (( rc == 0 )); then
22
+ printf '%s\n' "[product-release-notes] ${tag}:已建立 Release,內文是 Snapshot"
23
+ exit 0
24
+ fi
25
+ gh release view "$tag" --repo "$repo" >/dev/null 2>&1 || exit "$rc"
26
+ fi
27
+ gh release edit "$tag" --repo "$repo" --notes-file "$notes"
28
+ printf '%s\n' "[product-release-notes] ${tag}:Release 已存在,內文改成 Snapshot"