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
@@ -100,6 +100,7 @@ jobs:
100
100
  PATHS: ${{ steps.reg.outputs.paths }}
101
101
  STAGE: ${{ inputs.stage }}
102
102
  PUBLISH_CHECK_ONLY: "1"
103
+ GH_TOKEN: ${{ github.token }}
103
104
  run: |
104
105
  mapfile -t paths < <(jq -r '.[]' <<<"$PATHS")
105
106
  bash scripts/release/publish-units.sh "$STAGE" "${paths[@]}"
@@ -132,6 +133,7 @@ jobs:
132
133
  STAGE: ${{ inputs.stage }}
133
134
  PUBLISH_OUT: ${{ runner.temp }}/publish
134
135
  PUBLISH_REGISTRIES: npm,pypi,crates
136
+ GH_TOKEN: ${{ github.token }}
135
137
  run: |
136
138
  mapfile -t paths < <(jq -r '.[]' <<<"$PATHS")
137
139
  bash scripts/release/publish-units.sh pack "$STAGE" "${paths[@]}"
@@ -217,6 +219,7 @@ jobs:
217
219
  PUBLISH_REGISTRIES: ${{ steps.crate.outputs.registries }}
218
220
  PUBLISH_DRY_RUN: ${{ inputs.dry_run && '1' || '0' }}
219
221
  CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
222
+ GH_TOKEN: ${{ github.token }}
220
223
  run: |
221
224
  mapfile -t paths < <(jq -r '.[]' <<<"$PATHS")
222
225
  bash scripts/release/publish-units.sh upload "$STAGE" "${paths[@]}"
@@ -224,9 +227,12 @@ jobs:
224
227
  # 私有套件發到 GitHub Packages,用 GITHUB_TOKEN 而不是 OIDC,所以單一 job 跑 self-hosted-linux,建置與上傳都在這裡。
225
228
  # Actions 的權限只能設在 job,所以真上傳要的 packages: write 單獨放在這個 job,上面的 job 沒有。token 只在
226
229
  # 上傳那一步以 NODE_AUTH_TOKEN 提供,不寫進任何檔案,也不設在 job 層。
230
+ # 私有套件可以依賴公開套件(例如 peer 依賴共用 facts),反過來不會,所以等 build 與 publish 結束才上傳:
231
+ # 先上架的私有套件在公開套件跟上前裝不起來。這次沒有公開去處時 publish 是 skipped,不擋這個 job;
232
+ # 前面任一個 job 失敗或被取消就不上傳。
227
233
  publish-github-packages:
228
- needs: plan
229
- if: needs.plan.outputs.github-packages == 'true' && vars.PUBLISH_ENABLED == 'true'
234
+ needs: [plan, build, publish]
235
+ if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && needs.plan.outputs.github-packages == 'true' && vars.PUBLISH_ENABLED == 'true'
230
236
  runs-on: self-hosted-linux
231
237
  timeout-minutes: 20
232
238
  permissions:
@@ -248,6 +254,7 @@ jobs:
248
254
  PUBLISH_REGISTRIES: github-packages
249
255
  PUBLISH_DRY_RUN: ${{ inputs.dry_run && '1' || '0' }}
250
256
  NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
257
+ GH_TOKEN: ${{ github.token }}
251
258
  run: |
252
259
  mapfile -t paths < <(jq -r '.[]' <<<"$PATHS")
253
260
  bash scripts/release/publish-units.sh "$STAGE" "${paths[@]}"
@@ -263,7 +270,9 @@ jobs:
263
270
  timeout-minutes: 10
264
271
  permissions:
265
272
  contents: read
266
- # 一次一個寫入者,兩次發版不會搶同一個 main。
273
+ # 一次一個寫入者,兩次發版不會搶同一個 main。同一個 group 只留一個排隊的 run,新的進來會取消舊的,
274
+ # 被取消那次的版本因此沒有推到鏡像。mirror-units.sh 每次都補齊鏡像缺的所有版本(比對來源的單元 tag
275
+ # 與鏡像已有的 tag),下一次執行就會補上,不靠這個 run 一定跑完。
267
276
  concurrency:
268
277
  group: mirror
269
278
  cancel-in-progress: false
@@ -12,6 +12,11 @@
12
12
  # release line is cut from main, the previous line came back to main as a squash, so the source commits of two lines
13
13
  # are not ancestors of each other, while the Go proxy and SwiftPM only read the tags. The script never forces a push.
14
14
  #
15
+ # Every run makes up all the versions the mirror lacks, oldest first, not only the version of its own checkout: the
16
+ # publish workflow runs one mirror job at a time and a run that waited is cancelled when a newer one queues, so the
17
+ # version of a cancelled run would never reach the mirror otherwise. The versions are the release tags of the unit
18
+ # (<component>/v<version>) in the source repository.
19
+ #
15
20
  # main is always the commit of the highest version tagged in the mirror. A rerun is safe:
16
21
  # - the mirror tag exists and its tree is the unit's tree at the release tag: nothing to do
17
22
  # - the mirror tag exists with another tree: refuse, because a published version must not move
@@ -88,13 +93,43 @@ mirror_remote() { # mirror_remote <component>
88
93
  else die "$1: 不知道鏡像倉的 owner,請設 GITHUB_REPOSITORY(owner/repo)或 MIRROR_REMOTE"; fi
89
94
  }
90
95
 
91
- mirror_unit() { # mirror_unit <path>
92
- local p="${1%/}" reg ver comp remote mtag ref tree sha tagged main top="" topsha="" s r an ae ad
96
+ # mirror_unit <path>: mirror every version of the unit that the mirror lacks, oldest first. A run that was cancelled
97
+ # while it waited (one pending run per concurrency group) left its version out of the mirror, and the next run of
98
+ # the workflow only carries the version of its own checkout, so each run looks at all the release tags of the unit and
99
+ # makes up what is missing. The version of the checkout has to have a release tag (a run for a version that was not
100
+ # released stops); an older tag whose tree is not a Go or Swift package is skipped, since the unit may have been
101
+ # something else then. A dry run rehearses only the version of the checkout, from HEAD when it has no tag yet.
102
+ mirror_unit() {
103
+ local p="${1%/}" reg ver comp v
104
+ local -a versions=()
93
105
  reg="$(unit_mirror_kind "$p" 2>/dev/null || true)"
94
106
  if [[ "$reg" != go && "$reg" != swift ]]; then info "$p: not a Go or Swift unit, skipped"; return 0; fi
95
107
  jq -e --arg p "$p" '.packages | has($p)' "$CONFIG" >/dev/null || die "unexpected package path: $p (not a key of packages in $CONFIG)"
96
108
  ver="$(manifest_version "$p")"
97
109
  version_stage "$ver" >/dev/null || die "$p: version \"$ver\" is not X.Y.Z or X.Y.Z-<alpha|beta|rc>.N"
110
+ if (( dry )); then mirror_version "$p" "$reg" "$ver" strict; return; fi
111
+ comp="$(unit_component "$p")"
112
+ versions=("$ver")
113
+ while IFS= read -r v; do
114
+ v="${v#"$comp"/v}"
115
+ version_stage "$v" >/dev/null 2>&1 || continue
116
+ [[ "$v" == "$ver" ]] || versions+=("$v")
117
+ done < <(git tag --list "$comp/v*")
118
+ # oldest first: main stays at the commit of the highest version, an older one only gets its tag
119
+ local i j tmp
120
+ for ((i=1; i<${#versions[@]}; i++)); do
121
+ for ((j=i; j>0; j--)); do
122
+ version_gt "${versions[j-1]}" "${versions[j]}" || break
123
+ tmp="${versions[j]}"; versions[j]="${versions[j-1]}"; versions[j-1]="$tmp"
124
+ done
125
+ done
126
+ for v in "${versions[@]}"; do
127
+ if [[ "$v" == "$ver" ]]; then mirror_version "$p" "$reg" "$v" strict; else mirror_version "$p" "$reg" "$v" lenient; fi
128
+ done
129
+ }
130
+
131
+ mirror_version() { # mirror_version <path> <go|swift> <version> <strict|lenient>
132
+ local p="$1" reg="$2" ver="$3" mode="$4" comp remote mtag ref tree sha tagged main top="" topsha="" s r an ae ad
98
133
  comp="$(unit_component "$p")"
99
134
  remote="$(mirror_remote "$comp")"
100
135
  mtag="$(mirror_tag "$reg" "$ver")"
@@ -105,10 +140,15 @@ mirror_unit() { # mirror_unit <path>
105
140
  info "release tag $ref does not exist yet (dry run): taking the tree of HEAD"
106
141
  ref=HEAD
107
142
  fi
108
- tree="$(git rev-parse -q --verify "$ref:$p" 2>/dev/null)" && [[ "$(git cat-file -t "$tree")" == tree ]] || die "$p is not part of $ref"
143
+ # an older release that was something else (no such directory, no go.mod or Package.swift) is not a version to make up
144
+ skip_old() { info "$p: $1, so $ver is not mirrored"; }
145
+ if ! tree="$(git rev-parse -q --verify "$ref:$p" 2>/dev/null)" || [[ "$(git cat-file -t "$tree")" != tree ]]; then
146
+ [[ "$mode" == lenient ]] && { skip_old "it is not part of $ref"; return 0; }
147
+ die "$p is not part of $ref"
148
+ fi
109
149
  case "$reg" in
110
- go) git cat-file -e "$tree:go.mod" 2>/dev/null || die "$p: the unit has no go.mod at $ref" ;;
111
- swift) git cat-file -e "$tree:Package.swift" 2>/dev/null || die "$p: the unit has no Package.swift at $ref" ;;
150
+ go) git cat-file -e "$tree:go.mod" 2>/dev/null || { [[ "$mode" == lenient ]] && { skip_old "the unit has no go.mod at $ref"; return 0; }; die "$p: the unit has no go.mod at $ref"; } ;;
151
+ swift) git cat-file -e "$tree:Package.swift" 2>/dev/null || { [[ "$mode" == lenient ]] && { skip_old "the unit has no Package.swift at $ref"; return 0; }; die "$p: the unit has no Package.swift at $ref"; } ;;
112
152
  esac
113
153
 
114
154
  # what the mirror has now (a read; works without a token on a public repository)
@@ -45,6 +45,8 @@
45
45
  # PUBLISH_REGISTRIES comma list of targets (npm,github-packages,pypi,crates,go,swift): act only on the units of these
46
46
  # targets. The checks still run for every unit. publish.yml has one job per kind of target.
47
47
  # PUBLISH_CHECK_ONLY 1 stops after the checks (file version, stage, same content as the tag)
48
+ # GH_TOKEN a token that can read origin (publish.yml gives github.token). Only the git commands that read the
49
+ # tags of origin carry it (origin_git), because the checkout keeps no credential
48
50
  # PUBLISH_OUT where packages are built (default tmp/publish): npm tarballs in npm/<component>/, Python wheels and
49
51
  # sdists in pypi/, and packed.txt, the list of units `pack` built. Keep npm/ and pypi/ apart: the
50
52
  # PyPI upload checks every file in its directory. crates.io has no file to carry: `upload` publishes
@@ -131,15 +133,37 @@ check_file_version() { # check_file_version <path> <file> <version in file> <man
131
133
 
132
134
  unit_tag() { printf '%s/v%s\n' "$(unit_component "$1")" "$2"; }
133
135
 
136
+ # publish.yml checks out without keeping a credential (persist-credentials: false), so origin of a private repository
137
+ # cannot be read without one. A git command that reads origin gets GH_TOKEN on that command alone, as an extra header
138
+ # for GITHUB_SERVER_URL passed through the environment of git (GIT_CONFIG_*): the token is not written to any file and
139
+ # is not in the arguments of a process. Without GH_TOKEN the command runs as it is.
140
+ origin_git() { # origin_git <git arguments>...
141
+ [[ -n "${GH_TOKEN:-}" ]] || { git "$@"; return; }
142
+ local basic; basic="$(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n')"
143
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.${GITHUB_SERVER_URL:-https://github.com}/.extraheader" \
144
+ GIT_CONFIG_VALUE_0="AUTHORIZATION: basic ${basic}" git "$@"
145
+ }
146
+
134
147
  # A publish that failed after its tag was made can be dispatched again from the release branch once the fix lands
135
148
  # there. That is only safe while the unit's own files still equal the tag: otherwise one version number would name
136
149
  # two different packages. publish.yml's checkout is shallow and carries no tags, so a shallow clone fetches the tag
137
- # first; a unit without a tag has nothing to compare.
150
+ # first; a unit without a tag has nothing to compare. Only "the remote has no such tag" counts as no tag: any other
151
+ # failure of reaching the remote stops the script with the error of git.
138
152
  check_same_as_tag() { # check_same_as_tag <path> <version>
139
- local t; t="$(unit_tag "$1" "$2")"
153
+ local t out rc; t="$(unit_tag "$1" "$2")"
140
154
  if ! git rev-parse -q --verify "refs/tags/$t" >/dev/null 2>&1; then
141
155
  [[ "$(git rev-parse --is-shallow-repository 2>/dev/null)" == true ]] || return 0
142
- git fetch -q --depth=1 origin "refs/tags/$t:refs/tags/$t" 2>/dev/null || return 0
156
+ # ask the remote first, so that "the tag does not exist" (exit code 2) is told apart from every other failure: a remote
157
+ # that cannot be read, a bad credential or a network error must not read as "there is no tag to compare with"
158
+ rc=0
159
+ out="$(origin_git ls-remote --exit-code --tags origin "refs/tags/$t" 2>&1)" || rc=$?
160
+ case "$rc" in
161
+ 0) ;;
162
+ 2) return 0 ;;
163
+ *) die "${1}:讀不到遠端的 tag ${t},無法確認內容有沒有變(git ls-remote 結束碼 ${rc}):${out}" ;;
164
+ esac
165
+ out="$(origin_git fetch -q --depth=1 origin "refs/tags/$t:refs/tags/$t" 2>&1)" \
166
+ || die "${1}:遠端有 tag ${t},但抓不下來:${out}"
143
167
  fi
144
168
  git diff --quiet "$t" HEAD -- "$1" \
145
169
  || die "$1 的內容和 tag $t 不同。修正動到套件本身時,要推進到下一個序號重發,不能用同一個版號"
@@ -383,7 +407,7 @@ publish_tag() { # publish_tag <path> <version> <target>
383
407
  local p="$1" ver="$2" t
384
408
  t="$(unit_tag "$p" "$ver")"
385
409
  if ! git rev-parse -q --verify "refs/tags/$t" >/dev/null 2>&1; then
386
- git fetch -q --depth=1 origin "refs/tags/$t:refs/tags/$t" 2>/dev/null || true
410
+ origin_git fetch -q --depth=1 origin "refs/tags/$t:refs/tags/$t" 2>/dev/null || true
387
411
  git rev-parse -q --verify "refs/tags/$t" >/dev/null 2>&1 || die "tag $t 不存在,所以 $p $ver 還沒有發版"
388
412
  fi
389
413
  log "${3}:$(unit_name "$p" "$3") ${ver},tag $t 即發布紀錄,由 mirror-units.sh 推到鏡像倉,這裡不上傳"
@@ -0,0 +1,107 @@
1
+ name: advance-release
2
+
3
+ # 推進階段:手動觸發,輸入發布線與目標階段,在發布分支上跑 advance-release.sh。目標是 ga 時,腳本自己轉給
4
+ # finalize-release.sh --phase ga,這裡不另外處理。
5
+ # 從 main 派送。發布分支 checkout 在工作區根目錄,main 的 checkout 放在子目錄 .main-tools,用 main 的腳本對根目錄執行,
6
+ # 所以不用 setup-workspace 的 restore-from-default:它會把 main 的檔放進暫存區,發布腳本一開始檢查工作區乾不乾淨就會中止。
7
+ # 子目錄寫進 .git/info/exclude,工作區看起來仍是乾淨的。
8
+ # 推送要讓發布分支上的 workflow 接著跑,所以用 GitHub App 的權杖,GITHUB_TOKEN 推的分支不觸發它。
9
+ # 條件還沒成立(CI 閘還沒過、起點閘或部署閘不符)時,腳本直接失敗並印出要等什麼,不在 job 裡等。等條件成立後再觸發一次。
10
+ # 誰可以觸發由倉層變數 RELEASE_TRIGGER_ACTORS 列出(逗號分隔的帳號),沒設時不限制。比對的是 github.triggering_actor。
11
+ # 觸發者檢查排在取 App 權杖與 checkout 之後,沒有移到取權杖之前(評估過):檢查用的腳本在 main 的 checkout(.main-tools)裡,
12
+ # 而 actions/checkout 遇到沒有 .git 但已有內容的目錄會先清空它,所以發布分支要先 checkout 在根目錄,main 才能放進子目錄。
13
+ # 名單外的人觸發時權杖已經取得,但還沒有任何寫入,檢查失敗 job 就結束。sync-release-tools.yml 與 close-release.yml 的 checkout 在根目錄、
14
+ # 不受這限制,檢查在取權杖之前。
15
+
16
+ on:
17
+ workflow_dispatch:
18
+ inputs:
19
+ line:
20
+ description: "the release line, X.Y"
21
+ required: true
22
+ type: string
23
+ to:
24
+ description: "target stage: beta, rc or ga. Empty: the next stage the units of the line walk"
25
+ required: false
26
+ default: ""
27
+ type: string
28
+
29
+ permissions:
30
+ contents: read
31
+
32
+ defaults:
33
+ run:
34
+ shell: bash
35
+
36
+ # one group per release line, shared with merge-release-pr.yml, so the two never write to the same line at once
37
+ concurrency:
38
+ group: release-line-${{ inputs.line }}
39
+ cancel-in-progress: false
40
+
41
+ env:
42
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
43
+ POLL_TRIES: "2"
44
+ CI_GATE_TRIES: "2"
45
+ CI_GATE_QUEUE_TRIES: "0"
46
+
47
+ jobs:
48
+ advance:
49
+ # the workflow of another branch would run with the key of the App
50
+ if: github.ref_name == github.event.repository.default_branch
51
+ runs-on: self-hosted-linux
52
+ timeout-minutes: 15
53
+ steps:
54
+ - id: app-token
55
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
56
+ with:
57
+ client-id: ${{ vars.@@clientIdVariable@@ }}
58
+ private-key: ${{ secrets.@@privateKeySecret@@ }}
59
+ # 部署閘要跨倉查 ops 倉的 ops-deploy 紀錄與 ops/versions.json。上面的權杖只涵蓋本倉,ops 倉是 private 時回 404,
60
+ # 所以另取一個只限 ops 倉、唯讀的權杖,只給部署閘用(DEPLOY_GATE_OPS_TOKEN)。沒有 OPS_REPO(monorepo)時這兩步略過。
61
+ - id: ops-name
62
+ if: vars.OPS_REPO != ''
63
+ env:
64
+ OPS_REPO: ${{ vars.OPS_REPO }}
65
+ run: echo "name=${OPS_REPO#*/}" >> "$GITHUB_OUTPUT"
66
+ - id: ops-token
67
+ if: vars.OPS_REPO != ''
68
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
69
+ with:
70
+ client-id: ${{ vars.@@clientIdVariable@@ }}
71
+ private-key: ${{ secrets.@@privateKeySecret@@ }}
72
+ owner: ${{ github.repository_owner }}
73
+ repositories: ${{ steps.ops-name.outputs.name }}
74
+ permission-actions: read
75
+ permission-contents: read
76
+ - name: Release branch at the root
77
+ uses: actions/checkout@v7
78
+ with:
79
+ ref: release/v${{ inputs.line }}
80
+ fetch-depth: 0
81
+ token: ${{ steps.app-token.outputs.token }}
82
+ - name: Scripts of the default branch in a subdirectory
83
+ uses: actions/checkout@v7
84
+ with:
85
+ ref: ${{ github.event.repository.default_branch }}
86
+ path: .main-tools
87
+ fetch-depth: 1
88
+ persist-credentials: false
89
+ - name: Keep the subdirectory out of the work tree
90
+ run: echo "/.main-tools/" >> .git/info/exclude
91
+ - name: Only the listed accounts may run this
92
+ env:
93
+ TRIGGERING_ACTOR: ${{ github.triggering_actor }}
94
+ ALLOWED_ACTORS: ${{ vars.RELEASE_TRIGGER_ACTORS }}
95
+ run: bash .main-tools/scripts/release/check-trigger-actor.sh
96
+ - uses: ./.github/actions/setup-workspace
97
+ - name: Advance the stage
98
+ env:
99
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
100
+ DEPLOY_GATE_OPS_TOKEN: ${{ steps.ops-token.outputs.token }}
101
+ OPS_REPO: ${{ vars.OPS_REPO }}
102
+ LINE: ${{ inputs.line }}
103
+ TO: ${{ inputs.to }}
104
+ run: |
105
+ git config user.name "github-actions[bot]"
106
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
107
+ bash .main-tools/scripts/release/advance-release.sh --line "$LINE" ${TO:+--to "$TO"} --yes
@@ -0,0 +1,133 @@
1
+ name: close-release
2
+
3
+ # 收尾:合回 PR(release/vX.Y--to-main)的 ci 與 pr-message 兩支 workflow 完成時(workflow_run completed),看必要檢查是否都過了、
4
+ # PR 的 head 還是被檢查的那個 commit,條件都成立就跑 finalize-release.sh --phase close:合併合回 PR、在發布分支的最後一個 commit 打
5
+ # 產品 tag、刪掉發布分支與暫時分支。產品 tag 帶出 deploy-prod.yml 與 release-line-finalize.yml。
6
+ # pr-message 也是必要檢查,可能比 ci 晚完成,所以兩支完成都會帶出這支。早完成的那一次還有檢查在跑,結論成功、不做事,晚完成的那一次才收尾。
7
+ # 判斷是 scripts/release/close-ready.sh,用 auto-merge 同一套必要檢查(scripts/merge/decide.mjs 的 requiredCheckProblems)。
8
+ # 條件沒成立時(檢查還在跑、head 變了、PR 已合併、不是合回 PR)不做事、結論成功,因為同一條線的事件發生很多次。PR 與 main 有衝突時
9
+ # finalize-release.sh 不合併並失敗,訊息寫要重跑合回(merge-back),重跑會推出新的 head 並帶出新的檢查,檢查完成再帶出這支。
10
+ # PR 編號與 head sha 只讀事件內容 github.event.workflow_run.pull_requests[0].number 與 github.event.workflow_run.head_sha:
11
+ # github.sha 是 main 的 commit,不是 PR 的 head;PR 合併後用 run 編號回查 pull_requests 會讀到空陣列。
12
+ # 收尾不放進 auto-merge.yml:它掛 pull_request_target,lint 的 pr-no-publish 規則不讓在 PR 上跑的 workflow 呼叫 finalize-release.sh。
13
+ # 合併、打 tag、刪分支都用 GitHub App 的權杖:GITHUB_TOKEN 打的產品 tag 不觸發 deploy-prod.yml。權杖只在判斷通過之後才取。
14
+ #
15
+ # 另可手動觸發(後備,事件沒接到時補做):輸入發布線,條件沒成立時失敗並印出原因。手動觸發需要 GitHub App,沒有 App 的倉跑它會在
16
+ # create-github-app-token 失敗。事件觸發時沒有 App 的倉整個 job 略過、結論成功,照舊在本機跑 finalize-release.sh --phase close。
17
+ # 手動觸發時先檢查觸發者(倉層變數 RELEASE_TRIGGER_ACTORS,逗號分隔的帳號,沒設時不限制,比對的是 github.triggering_actor),
18
+ # 檢查在取 App 權杖之前。workflow_run 觸發時跑的一律是預設分支上的這個檔。
19
+
20
+ on:
21
+ workflow_run:
22
+ workflows: [ci, pr-message]
23
+ types: [completed]
24
+ workflow_dispatch:
25
+ inputs:
26
+ line:
27
+ description: "the release line, X.Y"
28
+ required: true
29
+ type: string
30
+
31
+ permissions:
32
+ contents: read
33
+
34
+ defaults:
35
+ run:
36
+ shell: bash
37
+
38
+ # the runs of one merge-back PR queue: a close is never cancelled halfway, and a run that waits reads the PR again when it starts
39
+ concurrency:
40
+ group: close-release-${{ inputs.line || github.event.workflow_run.pull_requests[0].number }}
41
+ cancel-in-progress: false
42
+
43
+ env:
44
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
45
+ POLL_TRIES: "2"
46
+ CI_GATE_TRIES: "2"
47
+ CI_GATE_QUEUE_TRIES: "0"
48
+
49
+ jobs:
50
+ close:
51
+ # An event that cannot lead to a close stays off the runner: a finished ci or pr-message that belongs to no pull request (a push,
52
+ # a fork), or whose branch is not release/vX.Y--to-main. The workflow of another branch would run with the key of the App.
53
+ if: >-
54
+ (github.event_name == 'workflow_dispatch'
55
+ && github.ref_name == github.event.repository.default_branch)
56
+ || (github.event_name == 'workflow_run'
57
+ && vars.@@clientIdVariable@@ != ''
58
+ && github.event.workflow_run.pull_requests[0].number
59
+ && startsWith(github.event.workflow_run.head_branch, 'release/v')
60
+ && endsWith(github.event.workflow_run.head_branch, '--to-main'))
61
+ runs-on: self-hosted-linux
62
+ timeout-minutes: 15
63
+ # the read of the checks and the PR; the writes are done with the token of the App
64
+ permissions:
65
+ actions: read
66
+ contents: read
67
+ pull-requests: read
68
+ checks: read
69
+ statuses: read
70
+ steps:
71
+ - name: Default branch, read only
72
+ uses: actions/checkout@v7
73
+ with:
74
+ fetch-depth: 1
75
+ persist-credentials: false
76
+ - name: Only the listed accounts may run this by hand
77
+ if: github.event_name == 'workflow_dispatch'
78
+ env:
79
+ TRIGGERING_ACTOR: ${{ github.triggering_actor }}
80
+ ALLOWED_ACTORS: ${{ vars.RELEASE_TRIGGER_ACTORS }}
81
+ run: bash scripts/release/check-trigger-actor.sh
82
+ - uses: ./.github/actions/setup-workspace
83
+ with:
84
+ install: "false"
85
+ - id: ready
86
+ name: Can the merge-back PR be closed now
87
+ env:
88
+ GH_TOKEN: ${{ github.token }}
89
+ GH_REPO: ${{ github.repository }}
90
+ EVENT: ${{ github.event_name }}
91
+ PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
92
+ HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
93
+ LINE: ${{ inputs.line }}
94
+ run: |
95
+ if [[ "$EVENT" == workflow_dispatch ]]; then
96
+ bash scripts/release/close-ready.sh --line "$LINE" --strict
97
+ else
98
+ bash scripts/release/close-ready.sh --pr "$PR_NUMBER" --head-sha "$HEAD_SHA"
99
+ fi >> "$GITHUB_OUTPUT"
100
+ - name: Summary
101
+ if: always()
102
+ env:
103
+ READY: ${{ steps.ready.outputs.ready }}
104
+ REASON: ${{ steps.ready.outputs.reason }}
105
+ run: |
106
+ {
107
+ echo "### close-release"
108
+ echo "- ready: \`${READY:-unknown}\`"
109
+ echo "- ${REASON:-the decision did not finish}"
110
+ } >> "$GITHUB_STEP_SUMMARY"
111
+ - id: app-token
112
+ if: steps.ready.outputs.ready == 'true'
113
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
114
+ with:
115
+ client-id: ${{ vars.@@clientIdVariable@@ }}
116
+ private-key: ${{ secrets.@@privateKeySecret@@ }}
117
+ # the whole history and the tags: close reads origin/main and the release branch; the token stays in the checkout for the pushes
118
+ - name: Default branch with the history, pushing as the App
119
+ if: steps.ready.outputs.ready == 'true'
120
+ uses: actions/checkout@v7
121
+ with:
122
+ fetch-depth: 0
123
+ token: ${{ steps.app-token.outputs.token }}
124
+ - name: Merge the merge-back PR, tag the product version, delete the branches
125
+ if: steps.ready.outputs.ready == 'true'
126
+ env:
127
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
128
+ LINE: ${{ steps.ready.outputs.line }}
129
+ HEAD_SHA: ${{ steps.ready.outputs.sha }}
130
+ run: |
131
+ git config user.name "github-actions[bot]"
132
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
133
+ bash scripts/release/finalize-release.sh --line "$LINE" --phase close --head-sha "$HEAD_SHA" --yes
@@ -0,0 +1,82 @@
1
+ name: merge-back
2
+
3
+ # 開合回 PR:手動觸發,輸入發布線,在發布分支上跑 finalize-release.sh --phase merge-back。它是 release-please.yml 的
4
+ # merge-back job 的後備:那個 job 只在 release-please 的 run 裡算出階段是 ga 且最終 tag 都齊了才啟動,沒有單元升版的線
5
+ # 可能沒有這個事件,job 中途失敗時也要有人能補做。
6
+ # 從 main 派送。發布分支 checkout 在工作區根目錄,main 的 checkout 放在子目錄 .main-tools,用 main 的腳本對根目錄執行,
7
+ # 理由和做法見 advance-release.yml。
8
+ # 推送與開 PR 用 GitHub App 的權杖,GITHUB_TOKEN 推的分支和開的 PR 不觸發檢查,合回 PR 的收尾就不會被帶出。
9
+ # 條件還沒成立(階段不是 ga、或這條線要的最終 tag 還沒齊)時,腳本直接失敗並列出缺哪些 tag,不在 job 裡等。等 tag 齊了再觸發一次。
10
+ # 誰可以觸發由倉層變數 RELEASE_TRIGGER_ACTORS 列出(逗號分隔的帳號),沒設時不限制。比對的是 github.triggering_actor。
11
+ # 觸發者檢查排在取 App 權杖與 checkout 之後,沒有移到取權杖之前(評估過):檢查用的腳本在 main 的 checkout(.main-tools)裡,
12
+ # 而 actions/checkout 遇到沒有 .git 但已有內容的目錄會先清空它,所以發布分支要先 checkout 在根目錄,main 才能放進子目錄。
13
+ # 名單外的人觸發時權杖已經取得,但還沒有任何寫入,檢查失敗 job 就結束。sync-release-tools.yml 與 close-release.yml 的 checkout 在根目錄、
14
+ # 不受這限制,檢查在取權杖之前。
15
+
16
+ on:
17
+ workflow_dispatch:
18
+ inputs:
19
+ line:
20
+ description: "the release line, X.Y"
21
+ required: true
22
+ type: string
23
+
24
+ permissions:
25
+ contents: read
26
+
27
+ defaults:
28
+ run:
29
+ shell: bash
30
+
31
+ # one group per release line, shared with advance-release.yml and merge-release-pr.yml, so they never write to the same line at once
32
+ concurrency:
33
+ group: release-line-${{ inputs.line }}
34
+ cancel-in-progress: false
35
+
36
+ env:
37
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
38
+ POLL_TRIES: "2"
39
+ CI_GATE_TRIES: "2"
40
+ CI_GATE_QUEUE_TRIES: "0"
41
+
42
+ jobs:
43
+ merge-back:
44
+ # the workflow of another branch would run with the key of the App
45
+ if: github.ref_name == github.event.repository.default_branch
46
+ runs-on: self-hosted-linux
47
+ timeout-minutes: 15
48
+ steps:
49
+ - id: app-token
50
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
51
+ with:
52
+ client-id: ${{ vars.@@clientIdVariable@@ }}
53
+ private-key: ${{ secrets.@@privateKeySecret@@ }}
54
+ - name: Release branch at the root
55
+ uses: actions/checkout@v7
56
+ with:
57
+ ref: release/v${{ inputs.line }}
58
+ fetch-depth: 0
59
+ token: ${{ steps.app-token.outputs.token }}
60
+ - name: Scripts of the default branch in a subdirectory
61
+ uses: actions/checkout@v7
62
+ with:
63
+ ref: ${{ github.event.repository.default_branch }}
64
+ path: .main-tools
65
+ fetch-depth: 1
66
+ persist-credentials: false
67
+ - name: Keep the subdirectory out of the work tree
68
+ run: echo "/.main-tools/" >> .git/info/exclude
69
+ - name: Only the listed accounts may run this
70
+ env:
71
+ TRIGGERING_ACTOR: ${{ github.triggering_actor }}
72
+ ALLOWED_ACTORS: ${{ vars.RELEASE_TRIGGER_ACTORS }}
73
+ run: bash .main-tools/scripts/release/check-trigger-actor.sh
74
+ - uses: ./.github/actions/setup-workspace
75
+ - name: Open the merge-back PR
76
+ env:
77
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
78
+ LINE: ${{ inputs.line }}
79
+ run: |
80
+ git config user.name "github-actions[bot]"
81
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
82
+ bash .main-tools/scripts/release/finalize-release.sh --line "$LINE" --phase merge-back --yes
@@ -0,0 +1,82 @@
1
+ name: merge-release-pr
2
+
3
+ # 合 Release PR:手動觸發,輸入發布線,在發布分支上跑 merge-release-pr.sh。它同時是釘版的後備。
4
+ # 從 main 派送。發布分支 checkout 在工作區根目錄,main 的 checkout 放在子目錄 .main-tools,用 main 的腳本對根目錄執行,
5
+ # 理由和做法見 advance-release.yml。
6
+ # 合併與推送用 GitHub App 的權杖,GITHUB_TOKEN 做的合併和推送不觸發後面的 workflow。
7
+ # release-please 還沒處理完這條發布線時,腳本直接失敗並印出要等什麼,沒有合併,不在 job 裡等。
8
+ # 腳本發現還有 next 要釘時,釘完推送後也失敗,請人等 release-please 處理完這個 commit 再觸發一次。
9
+ # 合併只合腳本讀到的那個 head(--match-head-commit),Release PR 在這之後被重算就拒絕合併。
10
+ # 誰可以觸發由倉層變數 RELEASE_TRIGGER_ACTORS 列出(逗號分隔的帳號),沒設時不限制。比對的是 github.triggering_actor。
11
+ # 觸發者檢查排在取 App 權杖與 checkout 之後,沒有移到取權杖之前(評估過):檢查用的腳本在 main 的 checkout(.main-tools)裡,
12
+ # 而 actions/checkout 遇到沒有 .git 但已有內容的目錄會先清空它,所以發布分支要先 checkout 在根目錄,main 才能放進子目錄。
13
+ # 名單外的人觸發時權杖已經取得,但還沒有任何寫入,檢查失敗 job 就結束。sync-release-tools.yml 與 close-release.yml 的 checkout 在根目錄、
14
+ # 不受這限制,檢查在取權杖之前。
15
+
16
+ on:
17
+ workflow_dispatch:
18
+ inputs:
19
+ line:
20
+ description: "the release line, X.Y"
21
+ required: true
22
+ type: string
23
+
24
+ permissions:
25
+ contents: read
26
+
27
+ defaults:
28
+ run:
29
+ shell: bash
30
+
31
+ # one group per release line, shared with advance-release.yml, so the two never write to the same line at once
32
+ concurrency:
33
+ group: release-line-${{ inputs.line }}
34
+ cancel-in-progress: false
35
+
36
+ env:
37
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
38
+ POLL_TRIES: "2"
39
+ CI_GATE_TRIES: "2"
40
+ CI_GATE_QUEUE_TRIES: "0"
41
+
42
+ jobs:
43
+ merge:
44
+ # the workflow of another branch would run with the key of the App
45
+ if: github.ref_name == github.event.repository.default_branch
46
+ runs-on: self-hosted-linux
47
+ timeout-minutes: 15
48
+ steps:
49
+ - id: app-token
50
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
51
+ with:
52
+ client-id: ${{ vars.@@clientIdVariable@@ }}
53
+ private-key: ${{ secrets.@@privateKeySecret@@ }}
54
+ - name: Release branch at the root
55
+ uses: actions/checkout@v7
56
+ with:
57
+ ref: release/v${{ inputs.line }}
58
+ fetch-depth: 0
59
+ token: ${{ steps.app-token.outputs.token }}
60
+ - name: Scripts of the default branch in a subdirectory
61
+ uses: actions/checkout@v7
62
+ with:
63
+ ref: ${{ github.event.repository.default_branch }}
64
+ path: .main-tools
65
+ fetch-depth: 1
66
+ persist-credentials: false
67
+ - name: Keep the subdirectory out of the work tree
68
+ run: echo "/.main-tools/" >> .git/info/exclude
69
+ - name: Only the listed accounts may run this
70
+ env:
71
+ TRIGGERING_ACTOR: ${{ github.triggering_actor }}
72
+ ALLOWED_ACTORS: ${{ vars.RELEASE_TRIGGER_ACTORS }}
73
+ run: bash .main-tools/scripts/release/check-trigger-actor.sh
74
+ - uses: ./.github/actions/setup-workspace
75
+ - name: Merge the Release PR
76
+ env:
77
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
78
+ LINE: ${{ inputs.line }}
79
+ run: |
80
+ git config user.name "github-actions[bot]"
81
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
82
+ bash .main-tools/scripts/release/merge-release-pr.sh --line "$LINE" --yes
@@ -1,8 +1,10 @@
1
1
  name: open-release-line
2
2
 
3
- # 開線:由 hub 的 open-release-lines.yml 用 workflow_dispatch 啟動。hub 把產品版號、這個倉的單元與 Release Plan
4
- # 的內容當 input 傳來,這裡把內容寫成檔案,用 cut-release.sh --plan-file 開出 release/vX.Y。
5
- # 成員倉不讀 hub,也沒有讀 hub 的憑證。monorepo 的 plan 在自己的 releases/,用 cut-release.sh --plan 開線,不經這裡。
3
+ # 開線:手動觸發,或由 hub 的 open-release-lines.yml 用 workflow_dispatch 啟動。
4
+ # 成員倉由 hub 派送:hub 把產品版號、這個倉的單元與 Release Plan 的內容當 input 傳來,這裡把內容寫成檔案,
5
+ # 用 cut-release.sh --plan-file 開出 release/vX.Y。成員倉不讀 hub,也沒有讀 hub 的憑證,所以沒有貼 plan_content 就中止。
6
+ # 自己存放 plan 的倉(單倉產品、hub、組織層倉)不必貼 plan_content,plan 已經提交在 main 的 releases/,
7
+ # 用 cut-release.sh --plan 讀它開線。
6
8
  # 開線要推 release/** 分支並讓 release-please 在那條分支上跑,所以用 GitHub App 的權杖,GITHUB_TOKEN 推的分支不觸發它。
7
9
 
8
10
  on:
@@ -17,14 +19,20 @@ on:
17
19
  required: true
18
20
  type: string
19
21
  plan_content:
20
- description: "content of releases/release-plan-vX.Y.Z.md of the hub"
21
- required: true
22
+ description: "content of releases/release-plan-vX.Y.Z.md of the hub; required in a member repository, optional elsewhere (the plan of this repository's releases/ is used)"
23
+ required: false
24
+ default: ""
22
25
  type: string
23
26
  from:
24
27
  description: "base of the line: main (default) or the latest product tag of the line vX.Y.Z, for a patch line"
25
28
  required: false
26
29
  default: main
27
30
  type: string
31
+ stages_override:
32
+ description: 'stages of some units for this release only, a JSON object like {"product-api":["rc","ga"]}; empty keeps the policy file of main'
33
+ required: false
34
+ default: ""
35
+ type: string
28
36
 
29
37
  permissions:
30
38
  contents: read
@@ -68,3 +76,4 @@ jobs:
68
76
  UNITS: ${{ inputs.units }}
69
77
  PLAN_CONTENT: ${{ inputs.plan_content }}
70
78
  FROM: ${{ inputs.from }}
79
+ STAGES_OVERRIDE: ${{ inputs.stages_override }}