blueprint-shared-templates 0.4.1 → 0.5.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.
package/org/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @@repoName@@
2
+
3
+ `@@organization@@` 組織在組織層的 `@@repoName@@` 倉。它是導入方的組織層倉,放這個組織的組織值與組織層的倉清單,不是管理中樞的複本。共用套件、範本與組織層倉範本由管理中樞發布,這個倉只放導入方該有的東西。
4
+
5
+ ## 放什麼
6
+
7
+ - `facts/` 是 `@@aggregatePackageName@@`。它有兩筆 fact:組織值(`@@repoName@@.org-values`,欄位定義在共用 fact `blueprint-shared.org-values`,fact-kit 依那份 schema 驗證),以及組織層的倉清單(`@@repoName@@.org-layout.repos`)。
8
+ - `docs/` 是 `@@scope@@/@@repoName@@-docs`。它放組織層的文件,並引用上面的 fact 與共用 fact。`docs/@@repoName@@-docs/@@repoName@@/layer-names.doc.ts` 寫出各倉的 facts、docs 套件名怎麼從這一層推出。
9
+ - `scripts/ci/check-org-values.mjs` 逐欄位核對組織值,缺欄位、多欄位或型別不對時印出欄位名。
10
+
11
+ ## 依賴
12
+
13
+ 共用套件 `blueprint-shared-facts` 與 `blueprint-shared-docs` 從公開的 npm 安裝。`@@scope@@` scope 的套件發到 @@aggregateRegistry@@。
14
+
15
+ ## GitHub App 的權限
16
+
17
+ 組織的 bot App 要開這些 repository 權限,發版與合併的 workflow 才讀寫得動:Contents (write)、Pull requests (write)、Issues (write)、Workflows (write)、Actions (read)、Checks (read)、Statuses (read)、Variables (read)。有 workflow 要觸發另一個 workflow 的倉,另需 Actions (write)。依據是共用 fact `blueprint-shared.templates.github-app-placement` 的 `permissions`。
18
+
19
+ ## 建置
20
+
21
+ ```sh
22
+ pnpm install
23
+ pnpm build
24
+ pnpm check
25
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blueprint-shared-templates",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Templates shared by several products, published on its own",
5
5
  "license": "MIT",
6
6
  "author": "Carlos Space",
@@ -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 exists → the next job runs finalize-release.sh --phase merge-back.
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
@@ -82,9 +85,10 @@ jobs:
82
85
  merge_back_ready: ${{ steps.ready.outputs.ready }}
83
86
  steps:
84
87
  # Only when the App is configured; otherwise the step is skipped and its empty output falls
85
- # through to GITHUB_TOKEN below. The App needs Contents, Pull requests, Issues and Workflows (write):
88
+ # through to GITHUB_TOKEN below. The App needs Contents, Pull requests, Issues and Workflows (write), and Actions (read):
86
89
  # release-please labels its PRs, and PR labels go through the Issues API. Workflows is for sync-release-tools.yml,
87
90
  # whose push to a release branch changes .github/workflows; a push of that path is refused without it.
91
+ # Actions (read) is for the release scripts, which list workflow runs with gh run list (scripts/lib/release-pr.sh).
88
92
  # It comes before the checkout so that the checkout keeps the App token for the push of the pin step.
89
93
  - id: app-token
90
94
  if: vars.@@clientIdVariable@@ != ''
@@ -174,13 +178,16 @@ jobs:
174
178
  git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
175
179
  bash scripts/release/pin-release-pr.sh --line "${BRANCH#release/v}" --yes
176
180
 
177
- # 合回:階段是 ga 而且這條線要的最終 tag 都齊了才輸出 true,下一個 job 以它為條件。tag 是上面 release-please 這次 run 才建的,
178
- # 所以腳本先取回 tag。沒有單元升版的線也算齊,但它可能沒有這個事件,那條線靠手動的 merge-back workflow 補。
181
+ # 合回:階段是 ga、這條線沒有開著的 Release PR(腳本用 GH_TOKEN 查),而且 manifest 對預設分支有升版的單元至少一個、
182
+ # 各自的最終 tag 都齊了才輸出 true,下一個 job 以它為條件。tag 是上面 release-please 這次 run 才建的,所以腳本先取回 tag。
183
+ # 沒有單元升版的線不輸出 true(剛開線時也是這樣),那條線靠手動的 merge-back workflow 補。
179
184
  - id: ready
180
185
  if: steps.branch.outputs.exists == 'true' && vars.@@clientIdVariable@@ != ''
186
+ env:
187
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
181
188
  run: bash scripts/release/merge-back-ready.sh >> "$GITHUB_OUTPUT"
182
189
 
183
- # GA 之後開合回 PR:上一個 job 算出階段是 ga 且最終 tag 都齊了才啟動,條件沒成立時這個 job 不啟動,不佔 runner。
190
+ # GA 之後開合回 PR:上一個 job 算出合回就緒(階段是 ga、沒有開著的 Release PR、升版單元的最終 tag 都齊了)才啟動,條件沒成立時這個 job 不啟動,不佔 runner。
184
191
  # 推送與開 PR 用 App 的權杖,不然合回 PR 的檢查不會跑。需要 App,所以沒有 App 的倉略過。
185
192
  merge-back:
186
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
- # The merge-back commit of each release carries Release-Train-Base (the cut of that release) and
141
- # Release-Train-Units (the units of that train). Walk main newest to oldest over those cuts that are ancestors
142
- # of <base>; a cut from a patch train rebuilt from a tag is not on main and is skipped. The units to cover are
143
- # those of <unit>... that have been released (unit_released). A merge-back commit covers the units its
144
- # Release-Train-Units lists; one with no such trailer covers all of them. The result is the cut that covers the
145
- # last of them, so a unit left out of the newest releases still counts from the cut of the release that had it.
146
- # No release lists a unit that has never been released, so a cut with the trailer covers such a unit when it is
147
- # strictly older than the unit's first commit: every commit of the unit then comes after the cut and counts toward
148
- # its first version.
149
- # With nothing to cover it is the newest cut; when the walk ends with a unit uncovered it is the oldest cut;
150
- # with no cut at all it is empty (no previous release). The walk has no depth limit: the cut is a fact of an
151
- # earlier release, however far back.
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 left=() firsts=() listed=() keep=()
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 left+=("$u"); continue; fi
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 RELEASE_SKIPPED+=("$c"); continue; fi
167
- # shellcheck disable=SC2034 # read by cut-release.sh, which sources this file
168
- RELEASE_START="$c"
169
- [[ -n "$us" ]] || break
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
- keep=()
172
- for u in "${left[@]+"${left[@]}"}"; do in_array "$u" "${listed[@]}" || keep+=("$u"); done
173
- left=("${keep[@]+"${keep[@]}"}")
174
- keep=()
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 keep+=("$first"); fi
191
+ if [[ "$c" == "$first" ]] || ! git merge-base --is-ancestor "$c" "$first"; then continue 2; fi
177
192
  done
178
- firsts=("${keep[@]+"${keep[@]}"}")
179
- (( ${#left[@]} + ${#firsts[@]} )) || break
180
- 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)
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, the merge-back wait list (train_units_to_ship) and the pin base check (release_pin_open_pr).
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
- # train_units_to_ship [<ref>] → one component per line: the units the line opened with (the Release-Train-Units trailer of the opening
422
- # commit on <ref>, default HEAD) minus those with no releasable commit since the start point of the line (unit_changed's rule, anchored
423
- # where release-please counts from: last-release-sha of the config, the whole history when the config has none). Such a unit gets no
424
- # Release PR entry and no tag, so waiting for its tag would never end. The list does not depend on the manifest: right after the
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 mv
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 < <(train_units_to_ship "${1:-HEAD}")
455
+ done < <(train_units_by_manifest)
457
456
  return 0
458
457
  }
459
458
 
460
- # train_merge_back_ready [<ref>] → 0 when the merge-back of the line can be opened: the line stage on <ref> (default HEAD) is ga and
461
- # train_final_tags_missing lists nothing. Otherwise 1, with TRAIN_MERGE_BACK_WAITING set to what is still missing. The release-please
462
- # job asks it after every run, so it only looks and never waits. A train with no unit to ship counts as ready at ga.
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 "${1:-HEAD}")"
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
- missing="$(train_final_tags_missing "${1:-HEAD}")"
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
@@ -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
- # 清單是開線 commit 的 Release-Train-Units 扣掉沒有可發 commit 的單元,不看 manifest 差異
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 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
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"
package/transform.mjs CHANGED
@@ -8,7 +8,7 @@
8
8
  // not a text conversion and stays with the code that composes a repository.
9
9
 
10
10
  // The fields of the templates, the same list as the fact blueprint-shared.templates.fields (a test compares them).
11
- export const FIELDS = ["clientIdVariable", "licenseHolder", "mergeBotApp", "mergeBotUserId", "mergeLabel", "privateKeySecret", "scope"];
11
+ export const FIELDS = ["aggregatePackageName", "aggregateRegistry", "clientIdVariable", "licenseHolder", "mergeBotApp", "mergeBotUserId", "mergeLabel", "organization", "privateKeySecret", "repoName", "scope"];
12
12
 
13
13
  const FIELD = /@@(\w+)@@/g;
14
14