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
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env bash
2
+ # Bring the release tooling of the open release lines up to main: scripts/, .github/workflows/ and .github/actions/ (RELEASE_DRIFT_PATHS,
3
+ # the paths the tooling gate of advance-release.sh compares with origin/main). The sync workflow (sync-release-tools.yml) runs it when
4
+ # main changes one of them, and a person can run it by hand. For each line it restores the paths that are behind main to main's content
5
+ # in one commit and pushes it to the release branch; the scripts of main do the work, the scripts of the branch may be the old ones.
6
+ #
7
+ # usage: sync-release-tools.sh [--line X.Y] [--yes] [--dry-run] without --line every release/vX.Y on origin is looked at
8
+ #
9
+ # A line is left alone (a skip is a success) when
10
+ # - nothing is open: there is no release branch;
11
+ # - the line was not opened with cut-release.sh (no Release-Train-Base commit), because then what is "its own" cannot be told;
12
+ # - the line has pushed the product commit (chore(<branch>): product vX.Y.Z of merge-back) or its merge-back PR is open. The product tag
13
+ # goes on the last commit of the branch, so one more commit, a sync, would be tagged and released with the product;
14
+ # - every path equals main's.
15
+ # A line fails (and the others are still done) when a path has commits of the branch that main does not have, found with
16
+ # train_commits_not_on_main per path (by patch and by content, so an earlier sync commit does not count). Those commits are listed.
17
+ # Syncing would erase a fix made only on the branch: cherry-pick it to main first, then run this again.
18
+ #
19
+ # A path is made equal to main's: files that main no longer has are removed, files of main are restored. The commit is made in a
20
+ # temporary worktree and pushed to the branch with `git push` (never forced). When the push is refused, because the branch moved
21
+ # meanwhile, it fetches the branch and does the whole look and sync once more; a second refusal fails the line.
22
+ # It needs the token of the GitHub App (a push with GITHUB_TOKEN starts no workflow, and a change of .github/workflows needs the
23
+ # Workflows permission of the App). The checkout it runs in is not changed; it needs origin and, for the PR check, GH_TOKEN.
24
+ # No loop of this script sleeps: the single retry is written out, and external_retry waits through scripts/lib/retry.mjs.
25
+ set -euo pipefail
26
+ source "$(dirname "$0")/../lib/common.sh"
27
+ cd "$REPO_ROOT"
28
+
29
+ line=""
30
+ while [[ $# -gt 0 ]]; do
31
+ case "$1" in
32
+ --line) line="$2"; shift 2 ;;
33
+ --yes) ASSUME_YES=1; export ASSUME_YES; shift ;;
34
+ --dry-run) DRY_RUN=1; shift ;;
35
+ -h|--help) sed -n '2,${/^#/!q; p;}' "$0"; exit 0 ;;
36
+ *) die "unknown argument: $1" ;;
37
+ esac
38
+ done
39
+ [[ -z "$line" || "$line" =~ ^[0-9]+\.[0-9]+$ ]] || die "--line 需為 X.Y"
40
+ target="$(remote_target)"
41
+
42
+ fetch_all() {
43
+ git fetch -q --prune origin '+refs/heads/main:refs/remotes/origin/main' '+refs/heads/release/*:refs/remotes/origin/release/*' \
44
+ || die "git fetch origin 沒成功,無法判斷發布工具落後多少"
45
+ }
46
+
47
+ wt=""
48
+ drop_worktree() {
49
+ [[ -n "$wt" ]] || return 0
50
+ git worktree remove --force "$wt/tree" 2>/dev/null || true
51
+ rm -rf "$wt"
52
+ wt=""
53
+ }
54
+ # the exit trap of common.sh reports the writes that were declined (no --yes): keep it, with the worktree dropped first
55
+ on_exit() {
56
+ local rc=$?
57
+ drop_worktree
58
+ (exit "$rc")
59
+ report_skipped_external
60
+ }
61
+ trap on_exit EXIT
62
+
63
+ # sync_line <branch> → 0: done or left alone, 1: the branch has fixes of its own, 2: the push was refused
64
+ sync_line() {
65
+ local branch="$1" open product c commit p files ahead_msg="" pr
66
+ local -a paths=() behind=() ahead=()
67
+ git rev-parse -q --verify "refs/remotes/origin/$branch" >/dev/null || { info "⊘ origin 上沒有 ${branch},不做事"; return 0; }
68
+ open="$(git log -1 --format=%H -E --grep='^Release-Train-Base: [0-9a-f]{7,40}$' "origin/$branch")"
69
+ [[ -n "$open" ]] || { info "⊘ $branch 沒有 Release-Train-Base 的開線 commit(不是用 cut-release.sh 開的),分不出哪些是它自己的修正,不同步"; return 0; }
70
+ product="$(git log -1 --format=%h -E --grep="^chore\\(${branch//./\\.}\\): product v[0-9]" "$open..origin/$branch")"
71
+ if [[ -n "$product" ]]; then
72
+ info "⊘ $branch 已推了產品 commit ${product},產品 tag 會打在它的最後一個 commit,不再同步"
73
+ return 0
74
+ fi
75
+ pr="$(gh pr list --base main --head "${branch}--to-main" --state open --json number --jq '.[0].number // empty')" \
76
+ || die "gh pr list 沒成功,無法判斷 ${branch} 的合回 PR 是不是開著"
77
+ if [[ -n "$pr" ]]; then
78
+ info "⊘ ${branch} 的合回 PR #${pr} 開著,產品 tag 會打在發布分支的最後一個 commit,不再同步"
79
+ return 0
80
+ fi
81
+ mapfile -t paths < <(main_existing_paths "${RELEASE_DRIFT_PATHS[@]}")
82
+ for p in ${paths[@]+"${paths[@]}"}; do
83
+ git diff --quiet "origin/main" "origin/$branch" -- "$p" && continue
84
+ c="$(train_commits_not_on_main "origin/$branch" -- "$p")"
85
+ if [[ -z "$c" ]]; then behind+=("$p"); continue; fi
86
+ ahead+=("$p")
87
+ while IFS= read -r commit; do
88
+ [[ -n "$commit" ]] || continue
89
+ files="$(git diff-tree --no-commit-id --name-only -r --no-renames "${commit%% *}" -- "$p" | paste -sd ',' - | sed 's/,/, /g')"
90
+ ahead_msg+=" ${commit}(${files})"$'\n'
91
+ done <<<"$c"
92
+ done
93
+ if (( ${#ahead[@]} )); then
94
+ printf '%s' "$ahead_msg" >&2
95
+ warn "$branch 有 main 還沒有的發布工具修正(${ahead[*]}),不覆蓋。先把上面的 commit cherry-pick 到 main 並合進去,再重跑同步。沒有推送"
96
+ return 1
97
+ fi
98
+ if (( ${#behind[@]} == 0 )); then info "⊘ $branch 的發布工具已和 main 相同"; return 0; fi
99
+ log "$branch 的發布工具落後 main(${behind[*]}),同步"
100
+ if (( DRY_RUN )); then info "[dry-run] 還原 ${behind[*]} 成 main 的內容,commit 並推到 $branch"; return 0; fi
101
+ wt="$(mktemp -d)"
102
+ # this function runs on the left of ||, where set -e is off, so each step that must not fail says so
103
+ git worktree add -q --detach "$wt/tree" "origin/$branch" || die "git worktree add 沒成功"
104
+ # make each path equal to main's: files main dropped go, files of main come back
105
+ git -C "$wt/tree" rm -rq --ignore-unmatch -- "${behind[@]}" || die "git rm ${behind[*]} 沒成功"
106
+ git -C "$wt/tree" restore --source=origin/main --staged --worktree -- "${behind[@]}" || die "git restore --source=origin/main 沒成功"
107
+ if git -C "$wt/tree" diff --cached --quiet; then info "⊘ 還原之後沒有差異,不提交"; drop_worktree; return 0; fi
108
+ git -C "$wt/tree" commit -q -m "chore($branch): sync release tooling from main" -m "git restore --source=origin/main -- ${behind[*]}" || die "git commit 沒成功"
109
+ if external_retry push "$target" git -C "$wt/tree" push origin "HEAD:refs/heads/$branch"; then
110
+ info "已同步 ${branch}(${behind[*]}),commit $(git -C "$wt/tree" rev-parse --short HEAD)"
111
+ drop_worktree
112
+ return 0
113
+ fi
114
+ drop_worktree
115
+ return 2
116
+ }
117
+
118
+ fetch_all
119
+ declare -a lines=()
120
+ if [[ -n "$line" ]]; then lines=("release/v$line")
121
+ else while IFS= read -r b; do [[ "$b" =~ ^release/v[0-9]+\.[0-9]+$ ]] && lines+=("$b"); done < <(release_branches); fi
122
+ if (( ${#lines[@]} == 0 )); then info "⊘ 沒有開著的發布線,不做事"; exit 0; fi
123
+
124
+ declare -a failed=()
125
+ for b in "${lines[@]}"; do
126
+ log "$b"
127
+ for attempt in 1 2; do
128
+ status=0
129
+ sync_line "$b" || status=$?
130
+ (( status == 2 )) || break
131
+ if (( attempt == 2 )); then warn "推送 $b 被拒兩次,不再重試"; break; fi
132
+ warn "推送 $b 被拒,取回最新的分支再看一次"
133
+ fetch_all
134
+ done
135
+ (( status == 0 )) || failed+=("$b")
136
+ done
137
+ (( ${#failed[@]} == 0 )) || die "這些發布線沒有同步:${failed[*]}"
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env bash
2
- # Check that the units production declares are the versions the Release Plan names. The check reads what is declared after the
2
+ # Check that the units prod declares are the versions the Release Plan names. The check reads what is declared after the
3
3
  # release, so it is not a dependency of the unit that holds the declaration (decision infra-ops-version-unit).
4
4
  #
5
5
  # The Release Plan lists the version of every unit in a table with the columns 單元 and 實作版號 (the table that is pasted at GA,
6
6
  # or the output of snapshot.sh and snapshot-members.sh, which have the same columns). For each unit that ops/versions.json declares
7
- # under "production", the version there has to be the version in the table. The units the table lists and production does not
7
+ # at an instance of prod (a key <purpose>/prod, not hosts/...), the version there has to be the version in the table. Upstream
8
+ # software, written { impl, version }, is not a unit of the product and is not checked. The units the table lists and prod does not
8
9
  # declare (packages, libraries, facts) are not deployed and are not checked. The check fails, and says which unit, when
9
10
  # - a declared unit has another version in the table, or
10
11
  # - a declared unit has no row in the table.
11
12
  # It does not know which repository holds the plan or the declaration, so the monorepo (both in one repository) and a poly product
12
13
  # (the plan in the hub, the declaration in the ops repository) call it the same way.
13
14
  #
14
- # usage: verify-production.sh --plan <release-plan file> --ops <directory that has ops/versions.json>
15
+ # usage: verify-prod.sh --plan <release-plan file> --ops <directory that has ops/versions.json>
15
16
  # exit: 0 every declared unit matches, 1 a unit does not match, 2 an input is missing
16
17
  set -euo pipefail
17
18
  plan="" ops=""
@@ -22,7 +23,7 @@ while [[ $# -gt 0 ]]; do
22
23
  *) printf '%s\n' >&2 "unknown argument: $1"; exit 2 ;;
23
24
  esac
24
25
  done
25
- [[ -n "$plan" && -n "$ops" ]] || { printf '%s\n' >&2 "usage: verify-production.sh --plan <release-plan file> --ops <directory that has ops/versions.json>"; exit 2; }
26
+ [[ -n "$plan" && -n "$ops" ]] || { printf '%s\n' >&2 "usage: verify-prod.sh --plan <release-plan file> --ops <directory that has ops/versions.json>"; exit 2; }
26
27
  [[ -f "$plan" ]] || { printf '%s\n' >&2 "找不到 Release Plan:$plan"; exit 2; }
27
28
  decl="$ops/ops/versions.json"
28
29
  [[ -f "$decl" ]] || { printf '%s\n' >&2 "找不到 ops 宣告:$decl"; exit 2; }
@@ -45,19 +46,19 @@ planned="$(awk -F'|' '
45
46
  ' "$plan")"
46
47
  [[ -n "$planned" ]] || { printf '%s\n' >&2 "$plan 沒有單元版號表(欄位 單元 與 實作版號):GA 時貼入 snapshot 的輸出,或先產生 snapshot"; exit 2; }
47
48
 
48
- declared="$(jq -r '(.production // {}) | to_entries[] | "\(.key) \(.value.version)"' "$decl")"
49
- if [[ -z "$declared" ]]; then printf '%s\n' "ops production 沒有宣告任何單元,沒有可核對的"; exit 0; fi
49
+ declared="$(jq -r 'to_entries[] | select((.key | startswith("hosts/") | not) and (.key | endswith("/prod"))) | (.value // {}) | to_entries[] | select(.value | type == "string") | "\(.key) \(.value)"' "$decl")"
50
+ if [[ -z "$declared" ]]; then printf '%s\n' "ops prod 沒有宣告任何單元,沒有可核對的"; exit 0; fi
50
51
 
51
52
  fail=0
52
53
  while read -r unit version; do
53
54
  [[ -n "$unit" ]] || continue
54
55
  want="$(awk -v u="$unit" '$1 == u { print $2; exit }' <<<"$planned")"
55
56
  if [[ -z "$want" ]]; then
56
- printf '%s\n' " ✗ ${unit}:ops production 宣告 ${version},Release Plan 的單元版號表沒有這個單元"; fail=1
57
+ printf '%s\n' " ✗ ${unit}:ops prod 宣告 ${version},Release Plan 的單元版號表沒有這個單元"; fail=1
57
58
  elif [[ "$want" != "$version" ]]; then
58
- printf '%s\n' " ✗ ${unit}:Release Plan 是 ${want},ops production 宣告 ${version}"; fail=1
59
+ printf '%s\n' " ✗ ${unit}:Release Plan 是 ${want},ops prod 宣告 ${version}"; fail=1
59
60
  else
60
- printf '%s\n' " ✓ ${unit} ${version}:ops production 與 Release Plan 一致"
61
+ printf '%s\n' " ✓ ${unit} ${version}:ops prod 與 Release Plan 一致"
61
62
  fi
62
63
  done <<<"$declared"
63
- if (( fail )); then printf '%s\n' "核對失敗:ops production 的版本和 Release Plan 不一致"; exit 1; fi
64
+ if (( fail )); then printf '%s\n' "核對失敗:ops prod 的版本和 Release Plan 不一致"; exit 1; fi
package/transform.mjs CHANGED
@@ -32,9 +32,8 @@ export function fillFields(text, values, file = "template") {
32
32
  // `# @end` closes it; the marker lines are always dropped, and the lines between them stay only when the repository has
33
33
  // the role (or, with `!`, does not have it). Blocks do not nest. This is how ci.yml has the policy check and the facts
34
34
  // scripts only in a repository with the release role, which is the only role that ships those scripts (decision
35
- // ci-scope-source-only). `# @if deploy+infra` is kept only when the repository has every role joined by `+`: blocks do not
36
- // nest, so this is how a line that depends on two roles (the `needs` of the release job on the infra job in
37
- // deploy-production.yml, decision monorepo-release-align) is written.
35
+ // ci-scope-source-only). `# @if a+b` is kept only when the repository has every role joined by `+`: blocks do not
36
+ // nest, so this is how a line that depends on two roles is written.
38
37
  export function roleBlocks(text, roles, file = "workflow") {
39
38
  const out = [];
40
39
  let keep = null;
@@ -1,15 +1,15 @@
1
- name: verify-production
1
+ name: verify-prod
2
2
 
3
- # 產品發版後核對 production 部署的版本:把 ops/versions.json 的 production 和這一版 Release Plan 的單元版號比對,不一致就失敗並指出
3
+ # 產品發版後核對 prod 部署的版本:把 ops/versions.json 的 prod 和這一版 Release Plan 的單元版號比對,不一致就失敗並指出
4
4
  # 哪個單元(scripts/release/verify-ops.sh)。核對讀的是部署後宣告的狀態,不改任何東西。
5
- # poly 的 hub 和 monorepo 用同一份 workflow 與同一支 verify-production.sh,只差讀 ops 的來源:設了 OPS_REPO(hub)就用
5
+ # poly 的 hub 和 monorepo 用同一份 workflow 與同一支 verify-prod.sh,只差讀 ops 的來源:設了 OPS_REPO(hub)就用
6
6
  # clone-ops.sh 讀 poly-ops,沒設(monorepo)就讀同一個倉的 ops/versions.json。Release Plan 讀預設分支的 releases/。
7
7
  # 只手動觸發(workflow_dispatch,輸入產品 tag),因為核對要讀 ops-deploy 上線後的宣告:產品 tag 觸發時,寫回與 ops-deploy 還沒跑完,
8
- # 現在核對只會讀到舊的宣告。等 production 宣告寫回、ops-deploy 跑完之後重跑;hub 另外因為本身沒有單元,收不到產品 tag。
8
+ # 現在核對只會讀到舊的宣告。等 prod 宣告寫回、ops-deploy 跑完之後重跑;hub 另外因為本身沒有單元,收不到產品 tag。
9
9
  # 能讀 ops 倉的權杖(GitHub App,唯讀)只在設了 OPS_REPO 的倉建立:monorepo 讀自己,用內建的權杖。
10
10
 
11
11
  # run-name 帶輸入的 tag:gh run list 讀不到 workflow_dispatch 的輸入,scenario 的 --check-only 靠 run-name 對上產品 tag(demo-reset.yml 的 run-name 同理)。
12
- run-name: verify-production ${{ inputs.tag }}
12
+ run-name: verify-prod ${{ inputs.tag }}
13
13
 
14
14
  on:
15
15
  workflow_dispatch:
@@ -27,7 +27,7 @@ defaults:
27
27
  shell: bash
28
28
 
29
29
  concurrency:
30
- group: verify-production-${{ inputs.tag }}
30
+ group: verify-prod-${{ inputs.tag }}
31
31
  cancel-in-progress: false
32
32
 
33
33
  env:
@@ -56,7 +56,7 @@ jobs:
56
56
  private-key: ${{ secrets.@@privateKeySecret@@ }}
57
57
  owner: ${{ github.repository_owner }}
58
58
  permission-contents: read
59
- - name: 核對 ops production 的版本與 Release Plan
59
+ - name: 核對 ops prod 的版本與 Release Plan
60
60
  run: |
61
61
  if [[ -n "$OPS_TOKEN" ]]; then
62
62
  export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.${GITHUB_SERVER_URL}/.extraheader"
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
- # After a product release: read the ops declaration and check that the units it declares for production are the versions the
3
- # Release Plan of the product version names (verify-production.sh, which any repository with the release role has).
2
+ # After a product release: read the ops declaration and check that the units it declares for prod are the versions the
3
+ # Release Plan of the product version names (verify-prod.sh, which any repository with the release role has).
4
4
  # Where the declaration is read from is the only difference between the repositories that have this script:
5
5
  # - OPS_REPO set (the hub of a poly product): clone-ops.sh clones the ops repository, and snapshot-members.sh reads the manifests of
6
6
  # the members when the plan has no unit table yet;
@@ -37,5 +37,5 @@ if ! grep -q '實作版號' "$work/plan.md"; then
37
37
  info "Release Plan 還沒有單元版號表,用 ${snapshot[0]} 產生"
38
38
  { printf '\n'; bash "$(dirname "$0")/${snapshot[0]}" "${snapshot[@]:1}"; } >> "$work/plan.md"
39
39
  fi
40
- log "核對 ops production 的版本與 $tag 的 Release Plan"
41
- bash "$(dirname "$0")/verify-production.sh" --plan "$work/plan.md" --ops "$ops_root"
40
+ log "核對 ops prod 的版本與 $tag 的 Release Plan"
41
+ bash "$(dirname "$0")/verify-prod.sh" --plan "$work/plan.md" --ops "$ops_root"
@@ -1,173 +0,0 @@
1
- name: deploy-production
2
-
3
- # 這份檔在 deploy 與 infra 兩個角色的目錄各有一份,內容相同。倉有哪個角色,就留下那個角色的 job(compose 的角色區塊 # @if)。
4
- # 產品 tag 是唯一的上線閘門,逐單元的正式 tag 不觸發,因此本版所有單元有單一的上線時刻。
5
- # @if deploy
6
- # release job 一次把本版全部入版單元用 GA 版號重建 bundle,掛在產品 tag 的 GitHub Release,再一起寫進 production 的 ops 宣告。
7
- # 入版單元由 manifest 與前一個產品 tag 的差異推導,不需另行維護清單。
8
- # 不沿用 rc 的 bundle:版號寫在 bundle 裡,rc 的 bundle 寫 rc 的版號,GA 要重建(decision ga-rebuild-bundle)。
9
- # 這個 job 不呼叫 wrangler,也不讀 Cloudflare 的憑證。
10
- # @end
11
- # @if infra
12
- # infra job 一次把本版全部 infra 單元套用到 production:用 wrangler 建立單元宣告的 R2 bucket(scripts/deploy/apply-production.sh)。
13
- # 套用可以重複執行,已存在的 bucket 視為已套用。
14
- # @end
15
- # 兩個角色都有的倉(monorepo)先跑 infra job,release job 用 needs 等它成功才跑,因為 bucket 要在綁定它的 Worker 上線前存在
16
- # (decision monorepo-release-align)。
17
-
18
- on:
19
- push:
20
- tags: ["v[0-9]*"]
21
- workflow_dispatch:
22
- inputs:
23
- tag:
24
- description: "product tag, e.g. v1.3.0"
25
- required: true
26
- type: string
27
-
28
- permissions:
29
- contents: read
30
-
31
- defaults:
32
- run:
33
- shell: bash
34
-
35
- concurrency:
36
- group: deploy-production
37
- cancel-in-progress: false
38
-
39
- env:
40
- # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
41
- POLL_TRIES: "2"
42
- CI_GATE_TRIES: "2"
43
- CI_GATE_QUEUE_TRIES: "0"
44
-
45
- jobs:
46
- # @if infra
47
- infra:
48
- # production 只能由產品 tag 套用。免費方案的 private repo 用不了 environment 的 deployment branches
49
- # and tags,所以由這裡核對:觸發的 ref 必須是 tag,且要套用的 tag 是 v<數字>開頭的產品 tag。
50
- # 這個檢查寫在 workflow 裡,改 workflow 就能繞過;GitHub 強制的白名單需要 public repo 或 Pro/Team。
51
- # scripts/deploy/apply-production.sh 會再核對一次 tag 的格式。
52
- if: >-
53
- vars.DEPLOY_ENABLED == 'true'
54
- && startsWith(github.ref, 'refs/tags/v')
55
- && (
56
- startsWith(inputs.tag || github.ref_name, 'v0') ||
57
- startsWith(inputs.tag || github.ref_name, 'v1') ||
58
- startsWith(inputs.tag || github.ref_name, 'v2') ||
59
- startsWith(inputs.tag || github.ref_name, 'v3') ||
60
- startsWith(inputs.tag || github.ref_name, 'v4') ||
61
- startsWith(inputs.tag || github.ref_name, 'v5') ||
62
- startsWith(inputs.tag || github.ref_name, 'v6') ||
63
- startsWith(inputs.tag || github.ref_name, 'v7') ||
64
- startsWith(inputs.tag || github.ref_name, 'v8') ||
65
- startsWith(inputs.tag || github.ref_name, 'v9')
66
- )
67
- runs-on: self-hosted-linux
68
- timeout-minutes: 20
69
- steps:
70
- - uses: actions/checkout@v7
71
- with:
72
- ref: ${{ inputs.tag || github.ref_name }}
73
- fetch-depth: 0
74
- - uses: ./.github/actions/setup-workspace
75
- with:
76
- restore-from-default: "scripts"
77
- - name: 套用本版 infra 單元宣告的 R2 bucket 到 production
78
- run: bash scripts/deploy/apply-production.sh "$TAG"
79
- env:
80
- TAG: ${{ inputs.tag || github.ref_name }}
81
- CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
82
- CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
83
- DEPLOY_LOG_DIR: ${{ runner.temp }}/deploy-log
84
- - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
85
- if: always()
86
- with:
87
- name: apply-production-${{ inputs.tag || github.ref_name }}
88
- path: ${{ runner.temp }}/deploy-log
89
- if-no-files-found: ignore
90
- retention-days: 7
91
- # @end
92
-
93
- # @if deploy
94
- release:
95
- # @end
96
- # @if deploy+infra
97
- needs: infra
98
- # @end
99
- # @if deploy
100
- # production 只能由產品 tag 部署。免費方案的 private repo 用不了 environment 的 deployment branches
101
- # and tags,所以由這裡核對:觸發的 ref 必須是 tag,且要部署的 tag 是 v<數字>開頭的產品 tag。
102
- # 這個檢查寫在 workflow 裡,改 workflow 就能繞過;GitHub 強制的白名單需要 public repo 或 Pro/Team。
103
- # scripts/deploy/run-production.sh 會再核對一次 tag 的格式。
104
- # 兩個角色都有的倉:infra 被 skipped(DEPLOY_ENABLED 不是 true)時,沒有狀態函式的下游 job 也跟著 skipped,
105
- # 所以那個倉的 if 用 !cancelled() 讓 release 照條件判斷,infra 失敗時仍不跑。只有 deploy 角色的倉沒有 infra job,那版的 if 不依賴 infra。
106
- if: >-
107
- # @end
108
- # @if deploy+infra
109
- needs.infra.result != 'failure' && !cancelled() &&
110
- # @end
111
- # @if deploy
112
- startsWith(github.ref, 'refs/tags/v')
113
- && (
114
- startsWith(inputs.tag || github.ref_name, 'v0') ||
115
- startsWith(inputs.tag || github.ref_name, 'v1') ||
116
- startsWith(inputs.tag || github.ref_name, 'v2') ||
117
- startsWith(inputs.tag || github.ref_name, 'v3') ||
118
- startsWith(inputs.tag || github.ref_name, 'v4') ||
119
- startsWith(inputs.tag || github.ref_name, 'v5') ||
120
- startsWith(inputs.tag || github.ref_name, 'v6') ||
121
- startsWith(inputs.tag || github.ref_name, 'v7') ||
122
- startsWith(inputs.tag || github.ref_name, 'v8') ||
123
- startsWith(inputs.tag || github.ref_name, 'v9')
124
- )
125
- runs-on: self-hosted-linux
126
- timeout-minutes: 20
127
- # 掛 Release 與回寫同倉的 ops 宣告都要寫入權限;read 會讓 push 失敗
128
- permissions:
129
- contents: write
130
- actions: write
131
- steps:
132
- - uses: actions/checkout@v7
133
- with:
134
- ref: ${{ inputs.tag || github.ref_name }}
135
- fetch-depth: 0
136
- - uses: ./.github/actions/setup-workspace
137
- with:
138
- restore-from-default: "scripts"
139
- - id: ops-name
140
- if: vars.OPS_REPO != ''
141
- env:
142
- OPS_REPO: ${{ vars.OPS_REPO }}
143
- run: echo "name=${OPS_REPO#*/}" >> "$GITHUB_OUTPUT"
144
- - id: app-token
145
- if: vars.OPS_REPO != ''
146
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
147
- with:
148
- client-id: ${{ vars.@@clientIdVariable@@ }}
149
- private-key: ${{ secrets.@@privateKeySecret@@ }}
150
- owner: ${{ github.repository_owner }}
151
- repositories: ${{ steps.ops-name.outputs.name }}
152
- - name: 用 GA 版號重建入版單元,掛 Release,寫入 production 宣告
153
- run: |
154
- if [[ -n "$OPS_TOKEN" ]]; then
155
- export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.${GITHUB_SERVER_URL}/.extraheader"
156
- GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$OPS_TOKEN" | base64 | tr -d '\n')"
157
- export GIT_CONFIG_VALUE_0
158
- fi
159
- bash scripts/deploy/run-production.sh "$TAG"
160
- env:
161
- TAG: ${{ inputs.tag || github.ref_name }}
162
- GH_TOKEN: ${{ github.token }}
163
- OPS_TOKEN: ${{ steps.app-token.outputs.token }}
164
- OPS_REPO: ${{ vars.OPS_REPO }}
165
- DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
166
- DEPLOY_LOG_DIR: ${{ runner.temp }}/deploy-log
167
- BUNDLE_DIR: ${{ runner.temp }}/bundles
168
- - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
169
- with:
170
- name: deploy-production-${{ inputs.tag || github.ref_name }}
171
- path: ${{ runner.temp }}/deploy-log
172
- retention-days: 7
173
- # @end
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Which units a product tag puts online: the units whose version in .release-please-manifest.json differs from the
3
- # previous product tag, and that deploy to the GA environment (a web, service or backend unit under apps/ or services/ whose
4
- # wrangler.toml has an [env.<that environment>] table; a unit under infra/ is applied by the infra role, not built here). The units are derived from the manifest and the previous tag, so nobody keeps a list.
5
- # Prints key=value lines (usable as $GITHUB_OUTPUT): product (X.Y.Z), previous (the previous product tag or empty),
6
- # services (a JSON array of {unit, version, env}).
7
- #
8
- # usage: plan-production.sh <product tag> the tag must be checked out
9
- set -euo pipefail
10
- source "$(dirname "$0")/../lib/common.sh"
11
- cd "$REPO_ROOT"
12
- ref="${1:?usage: plan-production.sh <product tag>}"
13
- [[ "$ref" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "$ref 不是產品 tag(vX.Y.Z)"
14
- product="${ref#v}"
15
- # 產品 tag 之間沒有祖先關係(發布分支以 squash 合回),以版本序取前一版;用 --merged 會查無,
16
- # 讓「本版入版」退化為「全部單元」而每次都重新寫入所有服務的宣告
17
- prev="$(git tag --list 'v[0-9]*' --sort=-v:refname | awk -v c="$ref" 'f{print;exit} $0==c{f=1}')"
18
- if [[ -n "$prev" ]]; then
19
- changed=$(jq -s -r '.[0] as $p | .[1] | to_entries[] | select(.value != $p[.key]) | .key' \
20
- <(git show "$prev:$MANIFEST") "$MANIFEST")
21
- else
22
- changed=$(jq -r 'keys[]' "$MANIFEST")
23
- fi
24
- services="[]"
25
- for path in $changed; do
26
- # unit 名稱一律取設定的 component,設定沒有時才退回資料夾名稱
27
- unit="$(unit_component "$path")"
28
- ver="$(manifest_version "$path")"
29
- case "$(policy_unit_kind "$unit")" in
30
- service|backend|web) ;;
31
- *) info "略過非部署單元:$path" >&2; continue ;;
32
- esac
33
- case "${path%%/*}" in
34
- apps|services) ;;
35
- *) info "略過不在 apps/、services/ 之下的單元:$path" >&2; continue ;;
36
- esac
37
- env="$(stage_target "$unit" ga || true)"
38
- if [[ -z "$env" ]] || ! grep -q "^\[env\.${env}\]" "$path/wrangler.toml" 2>/dev/null; then
39
- info "略過沒有 GA 環境設定的單元:$path" >&2; continue
40
- fi
41
- services="$(jq -c --arg u "$unit" --arg v "$ver" --arg e "$env" '. + [{unit: $u, version: $v, env: $e}]' <<<"$services")"
42
- done
43
- printf '%s=%s\n' product "$product" previous "$prev" services "$services"
@@ -1,157 +0,0 @@
1
- name: deploy-prerelease
2
-
3
- # 這份檔在 deploy 與 infra 兩個角色的目錄各有一份,內容相同。倉有哪個角色,就留下那個角色的 job(compose 的角色區塊 # @if),
4
- # 所以只有 deploy 角色的倉沒有 apply job,只有 infra 角色的倉沒有 bundle job,兩個角色都有的倉(monorepo)兩個都有。
5
- # 預發布階段逐單元處理:每個 prerelease tag({unit}/vX.Y.Z-<階段>.N)依階段處理到對應環境,
6
- # 階段與去處的對應寫在政策檔 release-policy.json 的 targets 與各單元的 targets
7
- # (GA 由 deploy-production.yml 處理,單元的正式 tag 不處理)。
8
- # 單元沒有該階段的去處時略過,原因寫進 job summary:單元的 wrangler.toml 要有該環境的 [env.<環境>]。判斷集中在
9
- # scripts/deploy/route-tag.sh。route 依單元所在的目錄決定 kind:apps/、services/ 下的單元是 service,由 bundle job 處理,
10
- # infra/ 下的單元是 infra,由 apply job 處理。同一個 tag 只會跑其中一個 job。
11
- # @if deploy
12
- # bundle job 只建置:建置 bundle、算雜湊、掛在這個 tag 的 GitHub Release,再把版號、bundle 位置與雜湊寫進 ops 宣告。
13
- # monorepo 寫自己的 ops/ 並派送 ops-deploy.yml,poly 寫 poly-ops(repository variable OPS_REPO)並由它上線。
14
- # 這個 job 不呼叫 wrangler,也不讀 Cloudflare 的憑證。
15
- # @end
16
- # @if infra
17
- # apply job 不建置 bundle,也不寫 ops 宣告,而是用 wrangler 在環境裡建立單元宣告的 R2 bucket(scripts/deploy/apply-infra.sh)。
18
- # 只有這個 job 與 deploy-production.yml 的 infra job 讀 Cloudflare 的憑證。
19
- # 只合併到預設分支不套用,套用跟著單元自己的 tag(decision infra-apply-on-tag)。
20
- # 同一個倉的 infra 與 api 同時打預發布 tag 時,兩個 run 的順序不保證。ops-deploy 若先於 bucket 建立而失敗,用 workflow_dispatch 重跑
21
- # (decision monorepo-release-align)。
22
- # @end
23
- # 產品層的統一上線閘門在 deploy-production.yml,不在這裡。
24
-
25
- on:
26
- push:
27
- tags: ["*/v*"]
28
- workflow_dispatch:
29
- inputs:
30
- tag:
31
- description: "unit tag, e.g. blueprint-monorepo-web/v1.4.0-beta.2"
32
- required: true
33
- type: string
34
-
35
- permissions:
36
- contents: read
37
-
38
- defaults:
39
- run:
40
- shell: bash
41
-
42
- env:
43
- # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
44
- POLL_TRIES: "2"
45
- CI_GATE_TRIES: "2"
46
- CI_GATE_QUEUE_TRIES: "0"
47
-
48
- jobs:
49
- route:
50
- runs-on: self-hosted-linux
51
- timeout-minutes: 5
52
- outputs:
53
- unit: ${{ steps.p.outputs.unit }}
54
- version: ${{ steps.p.outputs.version }}
55
- stage: ${{ steps.p.outputs.stage }}
56
- env: ${{ steps.p.outputs.env }}
57
- kind: ${{ steps.p.outputs.kind }}
58
- skip: ${{ steps.p.outputs.skip }}
59
- steps:
60
- - uses: actions/checkout@v7
61
- with:
62
- persist-credentials: false
63
- - id: p
64
- env:
65
- TAG: ${{ inputs.tag || github.ref_name }}
66
- run: |
67
- bash scripts/deploy/route-tag.sh "$TAG" | tee -a "$GITHUB_OUTPUT" > route.txt
68
- {
69
- echo "### $TAG"
70
- sed 's/^/- /' route.txt
71
- } >> "$GITHUB_STEP_SUMMARY"
72
-
73
- # @if deploy
74
- bundle:
75
- needs: route
76
- if: needs.route.outputs.skip == 'false' && needs.route.outputs.kind == 'service'
77
- runs-on: self-hosted-linux
78
- timeout-minutes: 15
79
- # 掛 Release 與回寫同倉的 ops 宣告都要寫入權限;read 會讓 push 失敗
80
- permissions:
81
- contents: write
82
- actions: write
83
- concurrency:
84
- group: deploy-${{ needs.route.outputs.env }}-${{ needs.route.outputs.unit }}
85
- steps:
86
- - uses: actions/checkout@v7
87
- with:
88
- ref: ${{ inputs.tag || github.ref_name }}
89
- - uses: ./.github/actions/setup-workspace
90
- with:
91
- restore-from-default: "scripts"
92
- # poly 的 app 與 service 把宣告寫進 poly-ops,要 GitHub App 的權杖。monorepo 沒設 OPS_REPO,這一步略過。
93
- - id: ops-name
94
- if: vars.OPS_REPO != ''
95
- env:
96
- OPS_REPO: ${{ vars.OPS_REPO }}
97
- run: echo "name=${OPS_REPO#*/}" >> "$GITHUB_OUTPUT"
98
- - id: app-token
99
- if: vars.OPS_REPO != ''
100
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
101
- with:
102
- client-id: ${{ vars.@@clientIdVariable@@ }}
103
- private-key: ${{ secrets.@@privateKeySecret@@ }}
104
- owner: ${{ github.repository_owner }}
105
- repositories: ${{ steps.ops-name.outputs.name }}
106
- - name: 建置 bundle、掛 Release、寫入 ops 宣告
107
- run: |
108
- if [[ -n "$OPS_TOKEN" ]]; then
109
- export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.${GITHUB_SERVER_URL}/.extraheader"
110
- GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$OPS_TOKEN" | base64 | tr -d '\n')"
111
- export GIT_CONFIG_VALUE_0
112
- fi
113
- bash scripts/deploy/run-prerelease.sh "$TAG"
114
- env:
115
- TAG: ${{ inputs.tag || github.ref_name }}
116
- GH_TOKEN: ${{ github.token }}
117
- OPS_TOKEN: ${{ steps.app-token.outputs.token }}
118
- OPS_REPO: ${{ vars.OPS_REPO }}
119
- DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
120
- DEPLOY_LOG_DIR: ${{ runner.temp }}/deploy-log
121
- BUNDLE_DIR: ${{ runner.temp }}/bundles
122
- - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
123
- with:
124
- name: deploy-${{ needs.route.outputs.env }}-${{ needs.route.outputs.unit }}-${{ needs.route.outputs.version }}
125
- path: ${{ runner.temp }}/deploy-log
126
- retention-days: 7
127
- # @end
128
- # @if infra
129
- apply:
130
- needs: route
131
- if: needs.route.outputs.skip == 'false' && needs.route.outputs.kind == 'infra' && vars.DEPLOY_ENABLED == 'true'
132
- runs-on: self-hosted-linux
133
- timeout-minutes: 15
134
- concurrency:
135
- group: apply-${{ needs.route.outputs.env }}-${{ needs.route.outputs.unit }}
136
- steps:
137
- - uses: actions/checkout@v7
138
- with:
139
- ref: ${{ inputs.tag || github.ref_name }}
140
- - uses: ./.github/actions/setup-workspace
141
- with:
142
- restore-from-default: "scripts"
143
- - name: 套用單元宣告的 R2 bucket
144
- run: bash scripts/deploy/apply-prerelease.sh "$TAG"
145
- env:
146
- TAG: ${{ inputs.tag || github.ref_name }}
147
- CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
148
- CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
149
- DEPLOY_LOG_DIR: ${{ runner.temp }}/deploy-log
150
- - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
151
- if: always()
152
- with:
153
- name: apply-${{ needs.route.outputs.env }}-${{ needs.route.outputs.unit }}-${{ needs.route.outputs.version }}
154
- path: ${{ runner.temp }}/deploy-log
155
- if-no-files-found: ignore
156
- retention-days: 7
157
- # @end