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.
Files changed (77) 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 +17 -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 +32 -17
  10. package/base/scripts/setup/github-repo-settings.sh +1 -1
  11. package/deploy/.github/workflows/deploy-prerelease.yml +6 -50
  12. package/deploy/.github/workflows/deploy-prod.yml +103 -0
  13. package/deploy/scripts/deploy/plan-prod.sh +57 -0
  14. package/deploy/scripts/deploy/promote.sh +23 -7
  15. package/deploy/scripts/deploy/publish-bundle.sh +10 -1
  16. package/deploy/scripts/deploy/route-tag.sh +10 -12
  17. package/deploy/scripts/deploy/run-prerelease.sh +4 -7
  18. package/deploy/scripts/deploy/{run-production.sh → run-prod.sh} +15 -17
  19. package/deploy/scripts/deploy/writeback-ops.sh +71 -40
  20. package/facts-skeleton.mjs +1 -1
  21. package/hub/scripts/release/dispatch-release-lines.sh +25 -2
  22. package/hub/scripts/release/snapshot-members.sh +1 -1
  23. package/ops/.github/workflows/ops-deploy.yml +92 -11
  24. package/ops/schemas/targets.schema.json +209 -0
  25. package/ops/scripts/ci/check-targets.mjs +291 -0
  26. package/ops/scripts/deploy/apply-iac.sh +89 -0
  27. package/ops/scripts/deploy/apply-ops.sh +101 -48
  28. package/ops/scripts/deploy/ops-run.sh +50 -12
  29. package/ops/scripts/deploy/smoke.sh +35 -16
  30. package/ops/scripts/lib/ops-steps.sh +75 -0
  31. package/org/scripts/ci/check-org-values.mjs +91 -0
  32. package/package.json +2 -2
  33. package/publish/.github/workflows/publish.yml +12 -3
  34. package/publish/scripts/release/cleanup-private-packages.mjs +1 -1
  35. package/publish/scripts/release/mirror-units.sh +45 -5
  36. package/publish/scripts/release/publish-units.sh +28 -4
  37. package/release/.github/workflows/advance-release.yml +107 -0
  38. package/release/.github/workflows/close-release.yml +133 -0
  39. package/release/.github/workflows/merge-back.yml +82 -0
  40. package/release/.github/workflows/merge-release-pr.yml +82 -0
  41. package/release/.github/workflows/open-release-line.yml +14 -5
  42. package/release/.github/workflows/release-line-finalize.yml +5 -3
  43. package/release/.github/workflows/release-please.yml +99 -15
  44. package/release/.github/workflows/sync-release-tools.yml +91 -0
  45. package/release/release-policy.json +1 -1
  46. package/release/schemas/release-policy.schema.json +13 -3
  47. package/release/scripts/ci/branch-exists.sh +27 -0
  48. package/release/scripts/ci/check-release-policy.sh +13 -2
  49. package/release/scripts/ci/pin-train.sh +5 -3
  50. package/release/scripts/ci/release-train.sh +22 -3
  51. package/release/scripts/lib/release-plan.sh +3 -1
  52. package/release/scripts/lib/release-pr.sh +275 -11
  53. package/release/scripts/lib/release-stages.sh +265 -36
  54. package/release/scripts/release/check-trigger-actor.sh +32 -0
  55. package/release/scripts/release/close-ready.mjs +72 -0
  56. package/release/scripts/release/close-ready.sh +70 -0
  57. package/release/scripts/release/cut-release.sh +35 -4
  58. package/release/scripts/release/ensure-stage-deploys.sh +3 -3
  59. package/release/scripts/release/finalize-release.sh +47 -15
  60. package/release/scripts/release/merge-back-ready.sh +27 -0
  61. package/release/scripts/release/merge-release-pr.sh +34 -107
  62. package/release/scripts/release/open-release-line.sh +28 -8
  63. package/release/scripts/release/pin-release-pr.sh +53 -0
  64. package/release/scripts/release/product-release-notes.sh +28 -0
  65. package/release/scripts/release/sync-release-tools.sh +137 -0
  66. package/release/scripts/release/{verify-production.sh → verify-prod.sh} +11 -10
  67. package/transform.mjs +3 -4
  68. package/verify/.github/workflows/{verify-production.yml → verify-prod.yml} +7 -7
  69. package/verify/scripts/release/verify-ops.sh +4 -4
  70. package/deploy/.github/workflows/deploy-production.yml +0 -173
  71. package/deploy/scripts/deploy/plan-production.sh +0 -43
  72. package/infra/.github/workflows/deploy-prerelease.yml +0 -157
  73. package/infra/.github/workflows/deploy-production.yml +0 -173
  74. package/infra/scripts/deploy/apply-infra.sh +0 -46
  75. package/infra/scripts/deploy/apply-prerelease.sh +0 -22
  76. package/infra/scripts/deploy/apply-production.sh +0 -33
  77. package/infra/scripts/deploy/route-tag.sh +0 -65
@@ -1,19 +1,32 @@
1
1
  #!/usr/bin/env bash
2
2
  # Put what ops/versions.json declares for an environment online. Per declared unit: download its bundle from the
3
- # GitHub Release the declaration names, check the bundle hash against the declaration, `wrangler versions upload`,
4
- # then `wrangler versions deploy <id>@100`. A unit whose /healthz already reports the declared version and
5
- # bundle hash is skipped, so a rerun changes nothing.
3
+ # GitHub Release that ops/versions.lock.json names, check the bundle hash against the lock, join the settings of the
4
+ # environment (ops/workloads/<purpose>/<env>/<unit>/wrangler.toml) to the wrangler.toml of the bundle, `wrangler versions upload`,
5
+ # then `wrangler versions deploy <id>@100`. A unit whose /healthz already reports the declared version, the bundle hash and the
6
+ # hash of the joined settings is skipped, so a rerun changes nothing.
6
7
  #
7
- # The four environments are four separate Workers (<unit>-<env>), and a version id belongs to one Worker, so an
8
+ # Each environment is a separate Worker (<unit>-<env>), and a version id belongs to one Worker, so an
8
9
  # environment never reuses the id of another: what carries over is the bundle, and the hash tells it is the same.
9
10
  #
10
- # The order is the one of ops/needs.json, as git-flow-template orders the releases of ops/helmfile.yaml by needs.
11
+ # The settings of an environment are not in the bundle. The wrangler.toml of the bundle holds what every environment shares (main,
12
+ # compatibility_date, assets), and must have no [env. table. The wrangler.toml of ops holds only tables that begin with
13
+ # [env.<this env>] (its vars and bindings). The two are joined after the bundle hash is checked, so /healthz still reports the declared
14
+ # bundle hash, and the hash of the joined file goes up as CONFIG_SHA256, so a change of settings alone puts a new version online.
15
+ #
16
+ # The steps are the directories <iac|workloads>/<purpose>/<env>/... and the order is the one of ops/needs.json, as git-flow-template orders
17
+ # the releases of ops/helmfile.yaml by needs (scripts/lib/ops-steps.sh). A need that points at another environment or at hosts/ counts as
18
+ # applied. This script applies the workloads steps only. The iac steps (OpenTofu) are applied by apply-iac.sh, which ops-run.sh runs before
19
+ # this one, and here they only take part in the order.
20
+ #
21
+ # The name of an R2 bucket is not in the settings of a unit. The wrangler.toml of ops has a [[env.<env>.r2_buckets]] table with a binding
22
+ # and no bucket_name; the name is bucket_name in the terraform.tfvars.json of the iac step that the unit needs in ops/needs.json, the one
23
+ # place that has it, and it is added to the table when the settings are joined.
11
24
  #
12
25
  # usage: apply-ops.sh <env> [--only unit1,unit2]
13
26
  # env: WRANGLER the command that runs wrangler (default `pnpm exec wrangler`; local mode: the stand-in)
14
27
  # DEPLOY_LOG_DIR where <env>.log is appended (default tmp/deploy-log)
15
28
  # ops/urls.json the URL pattern of each environment, see healthz.sh
16
- # GH_TOKEN a token that can read the Releases the declaration names
29
+ # GH_TOKEN a token that can read the Releases the lock names
17
30
  # CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID read by wrangler; set only by the workflow step that deploys
18
31
  set -euo pipefail
19
32
  env_name="${1:?usage: apply-ops.sh <env> [--only u1,u2]}"
@@ -26,56 +39,71 @@ done
26
39
  root="$(git rev-parse --show-toplevel)"
27
40
  here="$(dirname "$0")"
28
41
  source "$here/../lib/bundle.sh"
42
+ source "$here/../lib/ops-steps.sh"
29
43
  decl="$root/ops/versions.json"
44
+ lock="$root/ops/versions.lock.json"
30
45
  [[ -f "$decl" ]] || { printf '%s\n' >&2 "找不到 $decl"; exit 1; }
31
- jq -e --arg e "$env_name" 'has($e)' "$decl" >/dev/null || { printf '%s\n' >&2 "$decl 沒有 $env_name 環境"; exit 1; }
46
+ [[ -f "$lock" ]] || { printf '%s\n' >&2 "找不到 $lock"; exit 1; }
47
+ # the instances of this environment: <purpose>/<env>, not hosts/...
48
+ instances_filter='to_entries[] | select((.key | startswith("hosts/") | not) and (.key | endswith("/" + $e))) | .key as $k | (.value // {}) | keys[] | "\($k) \(.)"'
49
+ jq -e --arg e "$env_name" 'to_entries | any(.[]; (.key | startswith("hosts/") | not) and (.key | endswith("/" + $e)))' "$decl" >/dev/null \
50
+ || { printf '%s\n' >&2 "$decl 沒有 $env_name 環境的實例"; exit 1; }
32
51
  read -r -a wrangler <<<"${WRANGLER:-pnpm exec wrangler}"
33
52
  log_dir="${DEPLOY_LOG_DIR:-$root/tmp/deploy-log}"
34
53
  mkdir -p "$log_dir"
35
54
  work="$(mktemp -d)"; trap 'rm -rf "$work"' EXIT
36
55
 
37
- in_only() { [[ -z "$only" ]] && return 0; [[ ",$only," == *",$1,"* ]]; }
38
-
39
- # 順序宣告在 ops/needs.json:{ "<unit>": ["<unit it needs>", ...] },對應範本 ops/helmfile.yaml 各 release 的 needs。
40
- # 相依的單元先於自身(後端先於前端),拓撲排序;沒有宣告的單元沒有相依。不在這次要套的單元裡的相依不套,
41
- # 但仍參與排序與成環檢查。一次 run 只套一個單元(預發布)時順序沒有作用,production 一次套全部入版單元時才生效。
42
- needs_file="$root/ops/needs.json"
43
- declare -A needs_of state
44
- declare -a nodes order
45
- if [[ -f "$needs_file" ]]; then
46
- while read -r k d; do needs_of[$k]="${needs_of[$k]:-} $d"; done < <(jq -r 'to_entries[] | .key as $k | .value[] | "\($k) \(.)"' "$needs_file")
47
- fi
48
- mapfile -t declared < <(jq -r --arg e "$env_name" '(.[$e] // {}) | keys[]' "$decl")
49
- mapfile -t nodes < <({ printf '%s\n' "${declared[@]:-}"; [[ -f "$needs_file" ]] && jq -r 'to_entries[] | .key, .value[]' "$needs_file"; } | sed '/^$/d' | LC_ALL=C sort -u)
50
- declare -a stack=()
51
- visit() {
52
- local r="$1" d
53
- [[ "${state[$r]:-}" == "done" ]] && return 0
54
- if [[ "${state[$r]:-}" == visiting ]]; then
55
- local path="" x started=0
56
- for x in "${stack[@]}" "$r"; do [[ "$x" == "$r" ]] && started=1; (( started )) && path+="${path:+ → }$x"; done
57
- printf '%s\n' >&2 "✗ 相依成環:$path"; exit 1
58
- fi
59
- state[$r]=visiting; stack+=("$r")
60
- for d in ${needs_of[$r]:-}; do visit "$d"; done # 刻意不加引號:needs 是空白分隔字串
61
- unset 'stack[${#stack[@]}-1]'
62
- state[$r]="done"; order+=("$r")
56
+ # fill_bucket_names <toml> [name ...]: the file with `bucket_name = "<name>"` added under every [[env.<env>.r2_buckets]] header whose
57
+ # table has none, taking the names in turn. A table with its own bucket_name keeps it. Ends with 1 when the names run out.
58
+ fill_bucket_names() {
59
+ local file="$1"; shift
60
+ awk -v names="$*" '
61
+ { line[NR] = $0 }
62
+ END {
63
+ n = split(names, name, " "); used = 0
64
+ for (i = 1; i <= NR; i++) {
65
+ print line[i]
66
+ if (line[i] !~ /^[[:space:]]*\[\[env\.[A-Za-z0-9_-]+\.r2_buckets\]\][[:space:]]*$/) continue
67
+ has = 0
68
+ for (j = i + 1; j <= NR && line[j] !~ /^[[:space:]]*\[/; j++) if (line[j] ~ /^[[:space:]]*bucket_name[[:space:]]*=/) has = 1
69
+ if (has) continue
70
+ if (used >= n) { short = 1; continue }
71
+ used++
72
+ print "bucket_name = \"" name[used] "\""
73
+ }
74
+ exit short
75
+ }' "$file"
63
76
  }
64
- for r in "${nodes[@]:-}"; do [[ -n "$r" ]] && visit "$r"; done
65
- units=()
66
- for r in "${order[@]:-}"; do in_declared=0; for d in "${declared[@]:-}"; do [[ "$d" == "$r" ]] && in_declared=1; done; (( in_declared )) && in_only "$r" && units+=("$r"); done
67
- printf '%s\n' "[apply-ops] $env_name 套用順序:${units[*]:-(無)}"
77
+
78
+ in_only() { [[ -z "$only" ]] && return 0; [[ ",$only," == *",$1,"* ]]; }
79
+ # 順序宣告在 ops/needs.json:{ "<步驟目錄>": ["<要先套用的步驟目錄>", ...] },鍵是 ops/ 底下的路徑,例如 workloads/edge/prod/<unit>。
80
+ # 相依的步驟先於自身(後端先於前端),拓撲排序;沒有宣告的步驟沒有相依。指到別的環境或 hosts/ 的相依視為已套用,不參與排序。
81
+ # 不在這次要套的單元裡的相依不套,但仍參與排序與成環檢查。
82
+ declare -A step_unit step_instance
83
+ declare -a order
84
+ declared=()
85
+ while read -r instance unit; do
86
+ [[ -n "$instance" ]] || continue
87
+ step="workloads/$instance/$unit"
88
+ declared+=("$step"); step_unit[$step]="$unit"; step_instance[$step]="$instance"
89
+ done < <(jq -r --arg e "$env_name" "$instances_filter" "$decl")
90
+ order_text="$(ops_order "$env_name" "${declared[@]:-}")" || exit 1
91
+ while IFS= read -r r; do [[ -n "$r" ]] && order+=("$r"); done <<<"$order_text"
92
+ steps=()
93
+ for r in "${order[@]:-}"; do [[ -n "${step_unit[$r]:-}" ]] && in_only "${step_unit[$r]}" && steps+=("$r"); done
94
+ printf '%s\n' "[apply-ops] $env_name 套用順序:${steps[*]:-(無)}"
68
95
  n=0
69
- for unit in "${units[@]:-}"; do
70
- [[ -n "$unit" ]] && in_only "$unit" || continue
71
- entry="$(jq -c --arg e "$env_name" --arg u "$unit" '.[$e][$u]' "$decl")"
72
- version="$(jq -r .version <<<"$entry")"; sha="$(jq -r .sha256 <<<"$entry")"
96
+ for step in "${steps[@]:-}"; do
97
+ [[ -n "$step" ]] || continue
98
+ unit="${step_unit[$step]}"; instance="${step_instance[$step]}"
99
+ version="$(jq -r --arg i "$instance" --arg u "$unit" '.[$i][$u] | if type == "object" then .version else . end' "$decl")"
100
+ entry="$(jq -c --arg i "$instance" --arg u "$unit" '.[$i][$u] // empty' "$lock")"
101
+ [[ -n "$entry" ]] || { printf '%s\n' >&2 "✗ ${unit}:${lock} 沒有 ${instance} 的 ${unit}(bundle 雜湊與位置)"; exit 1; }
102
+ sha="$(jq -r .sha256 <<<"$entry")"
73
103
  repo="$(jq -r .bundle.repo <<<"$entry")"; tag="$(jq -r .bundle.tag <<<"$entry")"; asset="$(jq -r .bundle.asset <<<"$entry")"
74
104
  worker="$unit-$env_name"
75
- now="$(bash "$here/healthz.sh" "$worker" "$env_name" 2>/dev/null || true)"
76
- if [[ "$(jq -r .version <<<"${now:-{\}}" 2>/dev/null || true)" == "$version" && "$(jq -r .bundleSha256 <<<"${now:-{\}}" 2>/dev/null || true)" == "$sha" ]]; then
77
- printf '%s\n' " ⊘ $unit ${version}:$worker 已在線上,略過"; continue
78
- fi
105
+ ops_toml="$root/ops/$step/wrangler.toml"
106
+ [[ -f "$ops_toml" ]] || { printf '%s\n' >&2 "✗ ${unit}:找不到 ${ops_toml}($env_name 環境的設定)"; exit 1; }
79
107
  dir="$work/$unit"; mkdir -p "$dir/bundle"
80
108
  gh release download "$tag" --repo "$repo" --pattern "$asset" --dir "$dir" --clobber
81
109
  tar -xzf "$dir/$asset" -C "$dir/bundle"
@@ -83,18 +111,43 @@ for unit in "${units[@]:-}"; do
83
111
  if [[ "$got" != "$sha" ]]; then
84
112
  printf '%s\n' >&2 "✗ ${unit}:下載的 bundle 雜湊 $got 不是宣告的 $sha"; exit 1
85
113
  fi
114
+ # the settings of the environment join the shared ones only after the hash is checked, so the hash that /healthz reports stays the declared one
115
+ if grep -Eq '^[[:space:]]*\[\[?env\.' "$dir/bundle/wrangler.toml"; then
116
+ printf '%s\n' >&2 "✗ ${unit}:bundle 的 wrangler.toml 有 [env. 表,各環境的設定要寫在 ops/$step/wrangler.toml,不放在 bundle(可能回滾到舊的 bundle)"; exit 1
117
+ fi
118
+ bad="$(grep -E '^[[:space:]]*\[' "$ops_toml" | grep -Ev "^[[:space:]]*\[\[?env\.${env_name}(\]|\.)" || true)"
119
+ if [[ -n "$bad" ]]; then
120
+ printf '%s\n' >&2 "✗ ${unit}:ops/$step/wrangler.toml 只能有 [env.$env_name] 開頭的表,不能有:" "$bad"; exit 1
121
+ fi
122
+ # an R2 binding has no bucket_name in ops; the name comes from the tfvars of the iac steps this step needs
123
+ names=()
124
+ while IFS= read -r need; do
125
+ [[ "$need" == iac/* && -f "$root/ops/$need/terraform.tfvars.json" ]] || continue
126
+ name="$(jq -r '.bucket_name // empty' "$root/ops/$need/terraform.tfvars.json")"
127
+ [[ -n "$name" ]] && names+=("$name")
128
+ done < <(ops_needs "$step")
129
+ settings="$dir/settings.toml"
130
+ fill_bucket_names "$ops_toml" "${names[@]:-}" > "$settings" \
131
+ || { printf '%s\n' >&2 "✗ ${unit}:ops/$step/wrangler.toml 的 R2 綁定沒有 bucket_name,而且 ops/needs.json 給 ${step} 的 iac 步驟沒有足夠的 bucket_name(terraform.tfvars.json)"; exit 1; }
132
+ [[ -z "$(tail -c1 "$dir/bundle/wrangler.toml")" ]] || printf '\n' >> "$dir/bundle/wrangler.toml"
133
+ cat "$settings" >> "$dir/bundle/wrangler.toml"
134
+ cfg="$(sha256_of "$dir/bundle/wrangler.toml")"
135
+ now="$(bash "$here/healthz.sh" "$worker" "$env_name" 2>/dev/null || true)"
136
+ if [[ "$(jq -r .version <<<"${now:-{\}}" 2>/dev/null || true)" == "$version" && "$(jq -r .bundleSha256 <<<"${now:-{\}}" 2>/dev/null || true)" == "$sha" && "$(jq -r .configSha256 <<<"${now:-{\}}" 2>/dev/null || true)" == "$cfg" ]]; then
137
+ printf '%s\n' " ⊘ $unit ${version}:$worker 已在線上,略過"; continue
138
+ fi
86
139
  # every unit ships its built Worker script, and a web unit its static assets too (the layout of scripts/lib/bundle.sh)
87
140
  entry_args=()
88
141
  if [[ -f "$dir/bundle/dist/index.js" ]]; then entry_args=(dist/index.js --no-bundle); fi
89
142
  if [[ -d "$dir/bundle/public" ]]; then entry_args+=(--assets public); fi
90
143
  out="$dir/upload.ndjson"
91
144
  (cd "$dir/bundle" && WRANGLER_OUTPUT_FILE_PATH="$out" "${wrangler[@]}" versions upload "${entry_args[@]}" --env "$env_name" \
92
- --message "$unit $version sha256:$sha" --var "BUNDLE_SHA256:$sha")
145
+ --message "$unit $version sha256:$sha" --var "BUNDLE_SHA256:$sha" --var "CONFIG_SHA256:$cfg")
93
146
  id="$(jq -r 'select(.type == "version-upload") | .version_id' "$out" 2>/dev/null | tail -1)"
94
147
  [[ -n "$id" ]] || { printf '%s\n' >&2 "✗ ${unit}:wrangler 的輸出檔沒有 version-upload 的 version_id"; exit 1; }
95
148
  (cd "$dir/bundle" && "${wrangler[@]}" versions deploy "$id@100" --env "$env_name" --yes --message "$unit $version")
96
149
  n=$(( n + 1 ))
97
- printf '%s\n' "$(date -u '+%Y-%m-%d %H:%M') | $env_name | $unit | $version | apply | $id | sha256:$sha" >> "$log_dir/$env_name.log"
98
- printf '%s\n' " [$n] $worker ← ${version}(版本 ${id},雜湊 ${sha:0:12}…)"
150
+ printf '%s\n' "$(date -u '+%Y-%m-%d %H:%M') | $env_name | $unit | $version | apply | $id | sha256:$sha | config:${cfg:0:12}" >> "$log_dir/$env_name.log"
151
+ printf '%s\n' " [$n] $worker ← ${version}(版本 ${id},雜湊 ${sha:0:12}…,設定 ${cfg:0:12}…)"
99
152
  done
100
153
  printf '%s\n' "[apply-ops] $env_name 完成,上線 $n 個單元"
@@ -1,41 +1,79 @@
1
1
  #!/usr/bin/env bash
2
- # What ops-deploy.yml does: put declared bundles online and check each one with /healthz. Either the environment
2
+ # What ops-deploy.yml does: create the cloud resources of the iac steps (apply-iac.sh), then put declared bundles online and check each
3
+ # one with /healthz (apply-ops.sh, smoke.sh). The workflow runs the two parts as two jobs, iac first (--phase iac, then --phase workloads);
4
+ # without --phase one run does both, per environment, so a bucket exists before the unit that binds it goes online. Either the environment
3
5
  # and units are given (a workflow_dispatch, which a monorepo's deploy workflows send after they write ops/), or the
4
6
  # declarations that changed between two commits are found (a push to the default branch of poly-ops).
5
7
  #
8
+ # Every run aligns the whole declaration of the environment, whatever it was told about. GitHub keeps one pending run per concurrency group and
9
+ # cancels the older one, so the units that a cancelled run carried have to go online with the next run. apply-ops.sh skips the units that are
10
+ # already online with the declared version and hashes, so aligning everything changes only what differs.
11
+ #
6
12
  # usage: ops-run.sh --env <env> [--units u1,u2]
7
- # ops-run.sh --since <sha> the declarations that differ from <sha> in ops/versions.json
8
- # env: see apply-ops.sh and smoke.sh. Only apply-ops.sh runs wrangler, so only this workflow needs the Cloudflare credentials.
13
+ # --units is a hint that is printed: every unit that ops/versions.json declares for <env> is applied
14
+ # ops-run.sh --since <sha> every environment that ops/versions.json declares, every unit of it. <sha> only tells which settings
15
+ # changed since then; a unit with settings that ops/versions.json does not declare at <purpose>/<env>
16
+ # is not deployed: one line says so
17
+ # --phase iac|workloads|all which part to run (default all). Both parts take every unit the environment declares,
18
+ # so the iac job creates what the units of the workloads job bind
19
+ # env: see apply-iac.sh, apply-ops.sh and smoke.sh. Only apply-iac.sh runs tofu and only apply-ops.sh runs wrangler, so only this
20
+ # workflow needs the Cloudflare credentials.
9
21
  set -euo pipefail
10
22
  here="$(dirname "$0")"
11
23
  root="$(git rev-parse --show-toplevel)"
12
- env_name="" units="" since=""
24
+ env_name="" units="" since="" phase=all
13
25
  while [[ $# -gt 0 ]]; do
14
26
  case "$1" in
15
27
  --env) env_name="$2"; shift 2 ;;
16
28
  --units) units="$2"; shift 2 ;;
17
29
  --since) since="$2"; shift 2 ;;
30
+ --phase) phase="$2"; shift 2 ;;
18
31
  *) printf '%s\n' >&2 "unknown argument: $1"; exit 2 ;;
19
32
  esac
20
33
  done
34
+ [[ "$phase" =~ ^(iac|workloads|all)$ ]] || { printf '%s\n' >&2 "--phase 只接受 iac、workloads、all"; exit 2; }
21
35
  declare -a todo=() # "<env> <u1,u2>"
22
36
  if [[ -n "$since" ]]; then
23
37
  [[ "$since" =~ ^0+$ ]] && since="$(git hash-object -t tree /dev/null)"
24
38
  old="$(git show "$since:ops/versions.json" 2>/dev/null || printf '%s\n' '{}')"
25
- while read -r e us; do [[ -n "$e" ]] && todo+=("$e $us"); done < <(jq -r -n --argjson old "$old" --slurpfile new "$root/ops/versions.json" '
26
- $new[0] | to_entries[] | .key as $e | (.value // {}) as $now | ($old[$e] // {}) as $was
27
- | [$now | to_entries[] | select(.value != $was[.key]) | .key] | select(length > 0) | "\($e) \(join(","))"')
39
+ old_lock="$(git show "$since:ops/versions.lock.json" 2>/dev/null || printf '%s\n' '{}')"
40
+ new_lock="$(cat "$root/ops/versions.lock.json" 2>/dev/null || printf '%s\n' '{}')"
41
+ # "<env> <unit>" for every unit whose version or whose lock entry differs; the key of an instance is <purpose>/<env>
42
+ pairs="$(jq -r -n --argjson old "$old" --argjson oldlock "$old_lock" --slurpfile new "$root/ops/versions.json" --argjson newlock "$new_lock" '
43
+ $new[0] | to_entries[] | select(.key | startswith("hosts/") | not) | .key as $k | ($k | split("/")[1]) as $e
44
+ | (.value // {}) | to_entries[] | select(.value != ($old[$k] // {})[.key] or ($newlock[$k] // {})[.key] != ($oldlock[$k] // {})[.key]) | "\($e) \(.key)"')"
45
+ # the settings of a unit changed: ops/workloads/<purpose>/<env>/<unit>/...
46
+ changed="$(git diff --name-only "$since" -- ops/workloads ops/iac ops/needs.json)"
47
+ pairs+=$'\n'"$(sed -n 's#^ops/workloads/[^/]*/\([^/]*\)/\([^/]*\)/.*#\1 \2#p' <<<"$changed")"
48
+ # "<env> <unit>" of every unit that versions.json declares at an instance <purpose>/<env> (not hosts/...)
49
+ declared="$(jq -r 'to_entries[] | select(.key | startswith("hosts/") | not) | (.key | split("/")[1]) as $e | (.value // {}) | keys[] | "\($e) \(.)"' "$root/ops/versions.json")"
50
+ # ops/needs.json or ops/iac/ changed: every declared unit of every environment
51
+ if grep -qE '^ops/(iac/|needs\.json$)' <<<"$changed"; then pairs+=$'\n'"$declared"; fi
52
+ pairs="$(sed '/^$/d' <<<"$pairs" | LC_ALL=C sort -u)"
53
+ # a unit with settings but no declared version is not deployed: say so
54
+ while read -r e u; do
55
+ [[ -n "$e" ]] || continue
56
+ grep -qxF "$e $u" <<<"$declared" || printf '%s\n' "$e $u 沒有宣告版本,不部署"
57
+ done <<<"$pairs"
58
+ # every declared unit of every environment, not the units that changed: a run cancelled by a newer one carried declarations that nobody else applies
59
+ while read -r e us; do [[ -n "$e" ]] && todo+=("$e $us"); done < <(sed '/^$/d' <<<"$declared" | awk '{ units[$1] = units[$1] (units[$1] == "" ? "" : ",") $2 } END { for (e in units) print e, units[e] }' | LC_ALL=C sort)
28
60
  else
29
61
  [[ -n "$env_name" ]] || { printf '%s\n' >&2 "--env 或 --since 必填"; exit 2; }
30
- todo+=("$env_name $units")
62
+ # the units of the input are a hint: the environment is aligned as a whole
63
+ declared_units="$(jq -r --arg e "$env_name" 'to_entries[] | select((.key | startswith("hosts/") | not) and (.key | endswith("/" + $e))) | (.value // {}) | keys[]' "$root/ops/versions.json" 2>/dev/null | LC_ALL=C sort -u | paste -sd, - || true)"
64
+ [[ -z "$units" ]] || printf '%s\n' "units 只是提示(${units}):${env_name} 宣告的單元全部對齊"
65
+ todo+=("$env_name $declared_units")
31
66
  fi
32
- if (( ${#todo[@]} == 0 )); then printf '%s\n' "ops/versions.json 沒有變更的宣告,不部署"; exit 0; fi
67
+ if (( ${#todo[@]} == 0 )); then printf '%s\n' "ops/ 沒有變更的宣告或設定,不部署"; exit 0; fi
33
68
  for line in "${todo[@]}"; do
34
69
  e="${line%% *}"; us="${line#* }"; [[ "$us" == "$line" ]] && us=""
35
70
  printf '%s\n' "== $e${us:+:$us}"
36
- bash "$here/apply-ops.sh" "$e" ${us:+--only "$us"}
71
+ if [[ "$phase" != workloads ]]; then bash "$here/apply-iac.sh" "$e"; fi
72
+ if [[ "$phase" == iac ]]; then continue; fi
73
+ bash "$here/apply-ops.sh" "$e"
37
74
  specs=()
38
- while IFS= read -r s; do specs+=("$s"); done < <(jq -r --arg e "$e" --arg us "$us" '
39
- (.[$e] // {}) | to_entries[] | .key as $k | select($us == "" or ($us | split(",") | index($k))) | "\($k)=\(.value.version)"' "$root/ops/versions.json")
75
+ while IFS= read -r s; do specs+=("$s"); done < <(jq -r --arg e "$e" '
76
+ to_entries[] | select((.key | startswith("hosts/") | not) and (.key | endswith("/" + $e))) | (.value // {}) | to_entries[]
77
+ | "\(.key)=\(.value | if type == "object" then .version else . end)"' "$root/ops/versions.json")
40
78
  (( ${#specs[@]} )) && bash "$here/smoke.sh" "$e" "${specs[@]}"
41
79
  done
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env bash
2
2
  # Post-deploy smoke check: verifies what was DEPLOYED, not what was built.
3
- # 1. the ops declaration for <env> pins each unit to the expected version
3
+ # 1. the ops declaration (ops/versions.json, the instances <purpose>/<env>) pins each unit to the expected version
4
4
  # 2. the apply log records an apply of that unit in this run, or /healthz already reported the declaration
5
- # 3. /healthz of the Worker reports that version and the bundle hash of the declaration
6
- # On failure it prints the rollback command (re-run production with the previous product tag);
7
- # it never rolls back by itself (usage decision 2026-09-09).
5
+ # 3. /healthz of the Worker reports that version and the bundle hash of ops/versions.lock.json, and a hash of the settings
6
+ # of the environment (configSha256, which apply-ops.sh uploads)
7
+ # On failure it prints the rollback command (re-run prod with the product tag before the deployed one);
8
+ # it never rolls back by itself (usage decision 2026-09-09). The deployed tag is the newest product tag that ops/versions.lock.json
9
+ # names for the units that failed (deploy-prod.yml writes its tag there), because the newest tag of the repository is not the deployed one
10
+ # when an older tag is rerun. plan-prod.sh compares the tag with what prod declares, so the rerun puts back every unit that differs.
8
11
  #
9
12
  # usage: smoke.sh <env> <unit>=<version> [<unit>=<version> ...]
10
13
  # env: DEPLOY_LOG_DIR (defaults to tmp/deploy-log), ops/urls.json (see healthz.sh)
@@ -17,33 +20,49 @@ here="$(dirname "$0")"
17
20
  log_dir="${DEPLOY_LOG_DIR:-$root/tmp/deploy-log}"
18
21
  mkdir -p "$log_dir"
19
22
  decl="$root/ops/versions.json"
23
+ lock="$root/ops/versions.lock.json"
20
24
  fail=0
25
+ declare -a failed=()
21
26
  for spec in "$@"; do
22
27
  unit="${spec%%=*}"; version="${spec#*=}"
23
- entry="$(jq -c --arg e "$env_name" --arg u "$unit" '.[$e][$u] // empty' "$decl" 2>/dev/null || true)"
24
- if [[ -z "$entry" ]]; then printf '%s\n' " ⊘ ${unit}:ops 沒有 $env_name 的宣告(非部署單元),略過"; continue; fi
25
- pinned="$(jq -r .version <<<"$entry")"; sha="$(jq -r .sha256 <<<"$entry")"
28
+ # the instance of the unit in this environment: <purpose>/<env>, not hosts/...
29
+ instance="$(jq -r --arg e "$env_name" --arg u "$unit" 'to_entries[] | select((.key | startswith("hosts/") | not) and (.key | endswith("/" + $e)) and ((.value // {}) | has($u))) | .key' "$decl" 2>/dev/null | head -1 || true)"
30
+ if [[ -z "$instance" ]]; then printf '%s\n' " ⊘ ${unit}:ops 沒有 $env_name 的宣告(非部署單元),略過"; continue; fi
31
+ pinned="$(jq -r --arg i "$instance" --arg u "$unit" '.[$i][$u] | if type == "object" then .version else . end' "$decl")"
32
+ sha="$(jq -r --arg i "$instance" --arg u "$unit" '.[$i][$u].sha256 // empty' "$lock" 2>/dev/null || true)"
26
33
  if [[ "$pinned" != "$version" ]]; then
27
- printf '%s\n' " ✗ ${unit}:ops 宣告釘的是 ${pinned:-(空)},預期版本 $version"; fail=1; continue
34
+ printf '%s\n' " ✗ ${unit}:ops 宣告釘的是 ${pinned:-(空)},預期版本 $version"; fail=1; failed+=("$unit"); continue
28
35
  fi
29
36
  probe="$(bash "$here/healthz.sh" "$unit-$env_name" "$env_name" 2>/dev/null || true)"
30
37
  got_version="$(jq -r '.version // empty' <<<"${probe:-{\}}" 2>/dev/null || true)"
31
38
  got_sha="$(jq -r '.bundleSha256 // empty' <<<"${probe:-{\}}" 2>/dev/null || true)"
39
+ got_config="$(jq -r '.configSha256 // empty' <<<"${probe:-{\}}" 2>/dev/null || true)"
32
40
  if [[ "$got_version" != "$version" || "$got_sha" != "$sha" ]]; then
33
- printf '%s\n' " ✗ ${unit}:/healthz 回報版號 ${got_version:-(無)}、雜湊 ${got_sha:-(無)},宣告是 ${version}、$sha"; fail=1; continue
41
+ printf '%s\n' " ✗ ${unit}:/healthz 回報版號 ${got_version:-(無)}、雜湊 ${got_sha:-(無)},宣告是 ${version}、$sha"; fail=1; failed+=("$unit"); continue
34
42
  fi
35
- printf '%s\n' " ✓ $unit ${version}(sha256:${sha:0:12}…):宣告一致,/healthz 回報相同版號與 bundle 雜湊"
43
+ if [[ -z "$got_config" ]]; then
44
+ printf '%s\n' " ✗ ${unit}:/healthz 沒有回報設定雜湊 configSha256"; fail=1; failed+=("$unit"); continue
45
+ fi
46
+ printf '%s\n' " ✓ $unit ${version}(sha256:${sha:0:12}…,設定 ${got_config:0:12}…):宣告一致,/healthz 回報相同版號與 bundle 雜湊"
36
47
  printf '%s\n' "$(date -u '+%Y-%m-%d %H:%M') | $env_name | $unit | $version | smoke | ok" >> "$log_dir/smoke.log"
37
48
  done
38
49
  if (( fail )); then
39
50
  printf '\n'
40
- if [[ "$env_name" == production ]]; then
41
- # the tag being deployed is the newest, so the previous product tag is the second entry
42
- prev="$(git tag --list 'v[0-9]*' --sort=-v:refname | sed -n '2p')"
43
- printf '%s\n' "smoke 失敗。回滾:以前一個產品 tag 重跑 production(回滾會把 ops 宣告改寫回舊版本,再重新上線):"
44
- printf '%s\n' " gh workflow run deploy-production.yml --ref ${prev:-<前一個產品 tag>} -f tag=${prev:-<前一個產品 tag>}"
51
+ if [[ "$env_name" == prod ]]; then
52
+ # the product tag that put the failed units online: the lock of ops names it in bundle.tag
53
+ deployed="$(for u in "${failed[@]}"; do jq -r --arg e "$env_name" --arg u "$u" 'to_entries[] | select((.key | startswith("hosts/") | not) and (.key | endswith("/" + $e))) | .value[$u].bundle.tag // empty' "$lock" 2>/dev/null || true; done \
54
+ | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1 || true)"
55
+ tags="$(git tag --list 'v[0-9]*' --sort=-v:refname)"
56
+ if [[ -n "$deployed" ]]; then
57
+ prev="$(awk -v c="$deployed" 'f{print;exit} $0==c{f=1}' <<<"$tags")"
58
+ else
59
+ # no product tag in the lock: the tag being deployed is taken to be the newest
60
+ prev="$(sed -n '2p' <<<"$tags")"
61
+ fi
62
+ printf '%s\n' "smoke 失敗。回滾:以前一個產品 tag 重跑 prod(回滾會把 ops 宣告改寫回舊版本,再重新上線):"
63
+ printf '%s\n' " gh workflow run deploy-prod.yml --ref ${prev:-<前一個產品 tag>} -f tag=${prev:-<前一個產品 tag>}"
45
64
  else
46
- printf '%s\n' "smoke 失敗。${env_name} 不需回滾:production 未受影響;修正後以 hotfix 合入發布分支,下一個 prerelease tag 會重新部署並重跑 smoke。"
65
+ printf '%s\n' "smoke 失敗。${env_name} 不需回滾:prod 未受影響;修正後以 hotfix 合入發布分支,下一個 prerelease tag 會重新部署並重跑 smoke。"
47
66
  fi
48
67
  exit 1
49
68
  fi
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env bash
2
+ # The steps of ops and their order, shared by apply-iac.sh and apply-ops.sh. Source it; it only defines functions.
3
+ #
4
+ # A step is a directory of ops: iac/<purpose>/<env>/<name> (an OpenTofu root module) or workloads/<purpose>/<env>/<unit> (the settings of
5
+ # a Workers unit). ops/needs.json says which step goes before which: { "<step directory>": ["<step directory it needs>", ...] }, the keys
6
+ # and the values are paths under ops/. Steps are ordered topologically, a step it needs goes first (the iac step of a bucket before the
7
+ # unit that binds it, the backend before the front end). A need on another environment or on hosts/ counts as applied and takes no part.
8
+
9
+ # ops_in_env <step> <env>: the step is an iac or workloads step of this environment
10
+ ops_in_env() { [[ "$1" =~ ^(iac|workloads)/[^/]+/$2(/|$) ]]; }
11
+
12
+ # ops_iac_steps <env>: the iac steps that exist in ops/, one per line
13
+ ops_iac_steps() {
14
+ local root d
15
+ root="$(git rev-parse --show-toplevel)"
16
+ for d in "$root"/ops/iac/*/"$1"/*/; do
17
+ [[ -d "$d" ]] && printf '%s\n' "${d#"$root"/ops/}" | sed 's#/$##'
18
+ done
19
+ return 0
20
+ }
21
+
22
+ # ops_order <env> [<step> ...]: prints every step of the environment in the order it is applied, one per line. The steps given, the iac
23
+ # steps that exist and every step in ops/needs.json take part, so a need counts even for a step that is not applied in this run. A
24
+ # cycle prints "✗ 相依成環:<the steps on it>" to stderr and returns 1.
25
+ ops_order() {
26
+ local env_name="$1"; shift
27
+ local root needs_file k d n
28
+ root="$(git rev-parse --show-toplevel)"
29
+ needs_file="$root/ops/needs.json"
30
+ local -A _needs_of=() _state=()
31
+ local -a _order=() _stack=() _nodes=()
32
+ if [[ -f "$needs_file" ]]; then
33
+ while read -r k d; do ops_in_env "$k" "$env_name" && ops_in_env "$d" "$env_name" && _needs_of[$k]="${_needs_of[$k]:-} $d"; done \
34
+ < <(jq -r 'to_entries[] | .key as $k | .value[] | "\($k) \(.)"' "$needs_file")
35
+ fi
36
+ while IFS= read -r n; do [[ -n "$n" ]] && ops_in_env "$n" "$env_name" && _nodes+=("$n"); done < <(
37
+ { printf '%s\n' "$@"; ops_iac_steps "$env_name"; [[ -f "$needs_file" ]] && jq -r 'to_entries[] | .key, .value[]' "$needs_file"; } | sed '/^$/d' | LC_ALL=C sort -u
38
+ )
39
+ for n in "${_nodes[@]:-}"; do [[ -n "$n" ]] && { _ops_visit "$n" || return 1; }; done
40
+ printf '%s\n' "${_order[@]:-}" | sed '/^$/d'
41
+ }
42
+
43
+ # the depth-first visit of ops_order; it reads and writes the variables of ops_order (bash scopes them dynamically)
44
+ _ops_visit() {
45
+ local r="$1" d
46
+ [[ "${_state[$r]:-}" == "done" ]] && return 0
47
+ if [[ "${_state[$r]:-}" == visiting ]]; then
48
+ local path="" x started=0
49
+ for x in "${_stack[@]}" "$r"; do [[ "$x" == "$r" ]] && started=1; (( started )) && path+="${path:+ → }$x"; done
50
+ printf '%s\n' >&2 "✗ 相依成環:$path"; return 1
51
+ fi
52
+ _state[$r]=visiting; _stack+=("$r")
53
+ for d in ${_needs_of[$r]:-}; do _ops_visit "$d" || return 1; done # 刻意不加引號:needs 是空白分隔字串
54
+ unset '_stack[${#_stack[@]}-1]'
55
+ _state[$r]="done"; _order+=("$r")
56
+ }
57
+
58
+ # ops_needs <step>: the steps it needs directly, in the order of ops/needs.json, one per line
59
+ ops_needs() {
60
+ local root
61
+ root="$(git rev-parse --show-toplevel)"
62
+ [[ -f "$root/ops/needs.json" ]] || return 0
63
+ jq -r --arg s "$1" '.[$s] // [] | .[]' "$root/ops/needs.json"
64
+ }
65
+
66
+ # ops_needs_closure <step> ...: the given steps and every step they need, directly or not, one per line. Call it after ops_order
67
+ # passed, because a cycle would never end.
68
+ ops_needs_closure() {
69
+ local root
70
+ root="$(git rev-parse --show-toplevel)"
71
+ [[ -f "$root/ops/needs.json" ]] || { printf '%s\n' "$@"; return 0; }
72
+ printf '%s\n' "$@" | jq -R . | jq -rs --slurpfile n "$root/ops/needs.json" '
73
+ def reach($k): $k, (($n[0][$k] // [])[] | reach(.));
74
+ .[] | reach(.)' | LC_ALL=C sort -u
75
+ }
@@ -0,0 +1,91 @@
1
+ // The organization values of this repository against the schema blueprint-shared.org-values, and against the name of the facts package.
2
+ //
3
+ // 1. The value of the fact `<RepoName>.org-values`, read from the built facts (facts/dist), must pass the schema that
4
+ // blueprint-shared-facts publishes. Each missing field, each field the schema does not have and each field of the wrong type is printed
5
+ // with its name.
6
+ // 2. aggregatePackageName of the value must be the name of the aggregate package of facts/ (facts/package.json), because the packages of the
7
+ // other repositories of the organization read the facts of the organization under that name.
8
+ //
9
+ // fact-kit check fails on (1) as well, through validatedBy of the fact; this script says it field by field and adds (2).
10
+ // usage: node scripts/ci/check-org-values.mjs (build the facts first: pnpm build)
11
+ // Exit status: 0 every check passes, 1 a check fails, 2 the facts are not built or the schema is not installed.
12
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
13
+ import { createRequire } from "node:module";
14
+ import { join, resolve } from "node:path";
15
+ import Ajv2020 from "ajv/dist/2020.js";
16
+
17
+ const ROOT = resolve(import.meta.dirname, "..", "..");
18
+ const SCHEMA_ID = "blueprint-shared.org-values";
19
+ const readJson = (file) => JSON.parse(readFileSync(file, "utf8"));
20
+ const latest = (fact) => fact.variants?.at(-1) ?? fact;
21
+
22
+ // the built facts of the aggregate package: dist/index.json for one entry (it hangs on the root sub-path), dist/<entry>/index.json for several
23
+ function builtFacts(factsDir) {
24
+ const dist = join(factsDir, "dist");
25
+ if (!existsSync(dist)) return null;
26
+ const indexes = [
27
+ join(dist, "index.json"),
28
+ ...readdirSync(dist, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join(dist, d.name, "index.json")),
29
+ ].filter((file) => existsSync(file));
30
+ return indexes.flatMap((file) => readJson(file).facts);
31
+ }
32
+
33
+ // the schema, from the copy of blueprint-shared-facts that a package of facts/ installs
34
+ function schemaOf(factsDir) {
35
+ for (const entry of readdirSync(factsDir, { withFileTypes: true })) {
36
+ const manifest = join(factsDir, entry.name, "package.json");
37
+ if (!entry.isDirectory() || !existsSync(manifest)) continue;
38
+ try {
39
+ const index = createRequire(manifest).resolve("blueprint-shared-facts/blueprint-shared/index.json");
40
+ const fact = readJson(index).facts.find((f) => f.id === SCHEMA_ID);
41
+ if (fact) return latest(fact).content.schema;
42
+ } catch {
43
+ // this package does not install blueprint-shared-facts
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+
49
+ // one line per problem of the schema, with the name of the field
50
+ export function problemsOf(schema, value) {
51
+ const ajv = new Ajv2020({ allErrors: true, strict: false });
52
+ const validate = ajv.compile(schema);
53
+ if (validate(value)) return [];
54
+ return validate.errors.map((e) => {
55
+ const at = e.instancePath.replace(/^\//, "").replaceAll("/", ".");
56
+ if (e.keyword === "required") return `${[at, e.params.missingProperty].filter(Boolean).join(".")}: missing, the schema requires it`;
57
+ if (e.keyword === "additionalProperties") return `${[at, e.params.additionalProperty].filter(Boolean).join(".")}: not a field of ${SCHEMA_ID}`;
58
+ return `${at || "(value)"}: ${e.message}`;
59
+ });
60
+ }
61
+
62
+ function main() {
63
+ const factsDir = join(ROOT, "facts");
64
+ const facts = builtFacts(factsDir);
65
+ if (facts === null) {
66
+ console.error("✗ facts/dist is not there; build the facts first (pnpm build)");
67
+ return 2;
68
+ }
69
+ const found = facts.filter((f) => f.id.endsWith(".org-values"));
70
+ if (found.length !== 1) {
71
+ console.error(`✗ expected one fact named <RepoName>.org-values in the built facts, found ${found.length}`);
72
+ return 2;
73
+ }
74
+ const schema = schemaOf(factsDir);
75
+ if (schema === null) {
76
+ console.error(`✗ no package of facts/ installs blueprint-shared-facts with the schema ${SCHEMA_ID}; run pnpm install`);
77
+ return 2;
78
+ }
79
+ const value = latest(found[0]).content.value;
80
+ const problems = problemsOf(schema, value).map((p) => `${found[0].id}: ${p}`);
81
+ const aggregate = readJson(join(factsDir, "package.json")).name;
82
+ if (value?.aggregatePackageName !== aggregate) {
83
+ problems.push(`${found[0].id}: aggregatePackageName is ${value?.aggregatePackageName}, but the aggregate package of facts/ is named ${aggregate}`);
84
+ }
85
+ for (const p of problems) console.error(`✗ ${p}`);
86
+ if (problems.length > 0) return 1;
87
+ console.log(`✓ ${found[0].id} passes ${SCHEMA_ID}, and aggregatePackageName is ${aggregate}`);
88
+ return 0;
89
+ }
90
+
91
+ if (process.argv[1] && resolve(process.argv[1]) === import.meta.filename) process.exitCode = main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blueprint-shared-templates",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Templates shared by several products, published on its own",
5
5
  "license": "MIT",
6
6
  "author": "Carlos Space",
@@ -21,8 +21,8 @@
21
21
  "base",
22
22
  "deploy",
23
23
  "hub",
24
- "infra",
25
24
  "ops",
25
+ "org",
26
26
  "publish",
27
27
  "release",
28
28
  "verify"