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.
- package/base/.github/ISSUE_TEMPLATE/bug.yml +2 -2
- package/base/.github/ISSUE_TEMPLATE/hotfix.yml +1 -1
- package/base/.github/actions/setup-workspace/action.yml +2 -2
- package/base/.github/workflows/auto-merge.yml +4 -0
- package/base/.github/workflows/ci.yml +21 -1
- package/base/scripts/ci/run-affected.sh +6 -0
- package/base/scripts/lib/common.sh +1 -1
- package/base/scripts/lib/retry.mjs +36 -6
- package/base/scripts/merge/decide.mjs +30 -15
- package/deploy/.github/workflows/deploy-prerelease.yml +6 -50
- package/deploy/.github/workflows/deploy-prod.yml +103 -0
- package/deploy/scripts/deploy/plan-prod.sh +57 -0
- package/deploy/scripts/deploy/promote.sh +23 -7
- package/deploy/scripts/deploy/publish-bundle.sh +10 -1
- package/deploy/scripts/deploy/route-tag.sh +10 -12
- package/deploy/scripts/deploy/run-prerelease.sh +4 -7
- package/deploy/scripts/deploy/{run-production.sh → run-prod.sh} +15 -17
- package/deploy/scripts/deploy/writeback-ops.sh +71 -40
- package/hub/scripts/release/dispatch-release-lines.sh +25 -2
- package/hub/scripts/release/snapshot-members.sh +1 -1
- package/ops/.github/workflows/ops-deploy.yml +92 -11
- package/ops/schemas/targets.schema.json +209 -0
- package/ops/scripts/ci/check-targets.mjs +291 -0
- package/ops/scripts/deploy/apply-iac.sh +89 -0
- package/ops/scripts/deploy/apply-ops.sh +101 -48
- package/ops/scripts/deploy/ops-run.sh +50 -12
- package/ops/scripts/deploy/smoke.sh +35 -16
- package/ops/scripts/lib/ops-steps.sh +75 -0
- package/org/scripts/ci/check-org-values.mjs +91 -0
- package/package.json +2 -2
- package/publish/.github/workflows/publish.yml +12 -3
- package/publish/scripts/release/mirror-units.sh +45 -5
- package/publish/scripts/release/publish-units.sh +28 -4
- package/release/.github/workflows/advance-release.yml +107 -0
- package/release/.github/workflows/close-release.yml +133 -0
- package/release/.github/workflows/merge-back.yml +82 -0
- package/release/.github/workflows/merge-release-pr.yml +82 -0
- package/release/.github/workflows/open-release-line.yml +14 -5
- package/release/.github/workflows/release-line-finalize.yml +5 -3
- package/release/.github/workflows/release-please.yml +99 -15
- package/release/.github/workflows/sync-release-tools.yml +91 -0
- package/release/release-policy.json +1 -1
- package/release/schemas/release-policy.schema.json +13 -3
- package/release/scripts/ci/branch-exists.sh +27 -0
- package/release/scripts/ci/check-release-policy.sh +13 -2
- package/release/scripts/ci/pin-train.sh +5 -3
- package/release/scripts/ci/release-train.sh +22 -3
- package/release/scripts/lib/release-plan.sh +3 -1
- package/release/scripts/lib/release-pr.sh +275 -11
- package/release/scripts/lib/release-stages.sh +245 -27
- package/release/scripts/release/check-trigger-actor.sh +32 -0
- package/release/scripts/release/close-ready.mjs +72 -0
- package/release/scripts/release/close-ready.sh +70 -0
- package/release/scripts/release/cut-release.sh +34 -3
- package/release/scripts/release/ensure-stage-deploys.sh +3 -3
- package/release/scripts/release/finalize-release.sh +47 -15
- package/release/scripts/release/merge-back-ready.sh +27 -0
- package/release/scripts/release/merge-release-pr.sh +34 -107
- package/release/scripts/release/open-release-line.sh +28 -8
- package/release/scripts/release/pin-release-pr.sh +53 -0
- package/release/scripts/release/product-release-notes.sh +28 -0
- package/release/scripts/release/sync-release-tools.sh +137 -0
- package/release/scripts/release/{verify-production.sh → verify-prod.sh} +11 -10
- package/transform.mjs +2 -3
- package/verify/.github/workflows/{verify-production.yml → verify-prod.yml} +7 -7
- package/verify/scripts/release/verify-ops.sh +4 -4
- package/deploy/.github/workflows/deploy-production.yml +0 -173
- package/deploy/scripts/deploy/plan-production.sh +0 -43
- package/infra/.github/workflows/deploy-prerelease.yml +0 -157
- package/infra/.github/workflows/deploy-production.yml +0 -173
- package/infra/scripts/deploy/apply-infra.sh +0 -46
- package/infra/scripts/deploy/apply-prerelease.sh +0 -22
- package/infra/scripts/deploy/apply-production.sh +0 -33
- package/infra/scripts/deploy/route-tag.sh +0 -65
|
@@ -60,7 +60,7 @@ jobs:
|
|
|
60
60
|
- name: Product GitHub Release (notes = Snapshot)
|
|
61
61
|
env:
|
|
62
62
|
GH_TOKEN: ${{ github.token }}
|
|
63
|
-
run:
|
|
63
|
+
run: bash scripts/release/product-release-notes.sh "${{ inputs.tag || github.ref_name }}" snapshot.md
|
|
64
64
|
# 治理同步分兩個 step。release PR 核對照常跑;Issue 核對只在設了 ISSUES_ENABLED 的倉跑,沒設時 skipped
|
|
65
65
|
# (示範倉不真實建立 Issue,decision issues-written-not-run)。
|
|
66
66
|
- name: Release PR check
|
|
@@ -72,13 +72,15 @@ jobs:
|
|
|
72
72
|
fail=0
|
|
73
73
|
{
|
|
74
74
|
echo "### governance sync"
|
|
75
|
+
# jq keeps the first match itself: a `| head -1` after gh ends the pipe while gh may still write (several merged PRs of the
|
|
76
|
+
# same head and version, as after a repository was reset), and pipefail then fails the step with 141 (SIGPIPE)
|
|
75
77
|
pr="$(gh pr list --state merged --base main --head "release/v${line}--to-main" --limit 20 --json number,title \
|
|
76
|
-
--jq ".[] | select(.title | contains(\"product v${v} \")) | \"#\\(.number) \\(.title)\""
|
|
78
|
+
--jq "first(.[] | select(.title | contains(\"product v${v} \"))) | \"#\\(.number) \\(.title)\"")"
|
|
77
79
|
if [ -n "$pr" ]; then echo "- ✓ release PR ${pr}"; else echo "- ✗ 找不到合回 main 的 release PR(head release/v${line}--to-main,標題含 product v${v})"; fail=1; fi
|
|
78
80
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
79
81
|
exit $fail
|
|
80
82
|
# 這一版的 release PR 已合回 main,排入這一版(label release:vX.Y.Z)的 Issue 全部關閉。
|
|
81
|
-
# 功能 Issue 由功能 PR 的 Closes 關閉,
|
|
83
|
+
# 功能 Issue 由功能 PR 的 Closes 關閉,stg 修補只寫 Refs,由 release PR 集中 Closes。GitHub
|
|
82
84
|
# 在 commit 進入預設分支後才非同步關閉 Issue,所以仍開著的 Issue 會重查幾次再判定。
|
|
83
85
|
- name: Issue check
|
|
84
86
|
if: vars.ISSUES_ENABLED == 'true'
|
|
@@ -9,6 +9,18 @@ name: release-please
|
|
|
9
9
|
# variable @@clientIdVariable@@ (and the @@privateKeySecret@@ secret) and the
|
|
10
10
|
# release runs as the App instead: its tags fire deploy-prerelease's own `push: tags` trigger, and both
|
|
11
11
|
# the dispatch step and the ensure-stage-deploys job switch themselves off. Everything works either way.
|
|
12
|
+
#
|
|
13
|
+
# With the App the workflow also does the two steps that follow release-please, each only when its condition holds and otherwise
|
|
14
|
+
# succeeding without doing anything, because the same push comes many times and most of them are not the time:
|
|
15
|
+
# - pin: this run wrote or updated the Release PR (prs_created, or a re-run of the job, which finds nothing to update after a
|
|
16
|
+
# pin that failed half way) and created no tag → scripts/release/pin-release-pr.sh pins the "next" of facts and docs to the
|
|
17
|
+
# versions of the Release PR and pushes. The push makes release-please run again; the second run has nothing to change.
|
|
18
|
+
# - merge-back: the line is at ga and every final tag exists → the next job runs finalize-release.sh --phase merge-back.
|
|
19
|
+
# The pushes use the token of the App, because a push made with GITHUB_TOKEN raises no workflow run and the merge-back PR would get
|
|
20
|
+
# no checks. The fallbacks by hand are the merge-release-pr and merge-back workflows. This file has no manual trigger.
|
|
21
|
+
# Two other workflows are started by events and work on the same lines: sync-release-tools.yml (main changes the tooling, the open
|
|
22
|
+
# lines follow, so this file and the scripts it calls on a branch are main's) and close-release.yml (the checks of the merge-back
|
|
23
|
+
# PR finish, the PR is merged, the product tag is made and the branches are deleted).
|
|
12
24
|
|
|
13
25
|
on:
|
|
14
26
|
push:
|
|
@@ -58,20 +70,22 @@ jobs:
|
|
|
58
70
|
# run 開跑時讀不到分支上的 manifest 而失敗,所以這次推送直接跳過。
|
|
59
71
|
if: "!startsWith(github.event.head_commit.message, format('chore({0}): product v', github.ref_name))"
|
|
60
72
|
runs-on: self-hosted-linux
|
|
61
|
-
|
|
73
|
+
# release-please takes about 130 s; a run that pins adds setup-workspace (Node, pnpm install) and the fact-kit and
|
|
74
|
+
# clarify-kit pin on top, so the limit is the one of the manual merge workflow, which does the same work
|
|
75
|
+
timeout-minutes: 15
|
|
62
76
|
permissions:
|
|
63
77
|
contents: write
|
|
64
78
|
pull-requests: write
|
|
65
79
|
actions: write
|
|
80
|
+
outputs:
|
|
81
|
+
branch_exists: ${{ steps.branch.outputs.exists }}
|
|
82
|
+
merge_back_ready: ${{ steps.ready.outputs.ready }}
|
|
66
83
|
steps:
|
|
67
|
-
- uses: actions/checkout@v7
|
|
68
|
-
with:
|
|
69
|
-
# train_stage reads the Release-Train-Stage trailer from history; a shallow checkout would not find it
|
|
70
|
-
fetch-depth: 0
|
|
71
|
-
|
|
72
84
|
# Only when the App is configured; otherwise the step is skipped and its empty output falls
|
|
73
|
-
# through to GITHUB_TOKEN below. The App needs Contents, Pull requests and
|
|
74
|
-
# release-please labels its PRs, and PR labels go through the Issues API.
|
|
85
|
+
# through to GITHUB_TOKEN below. The App needs Contents, Pull requests, Issues and Workflows (write):
|
|
86
|
+
# release-please labels its PRs, and PR labels go through the Issues API. Workflows is for sync-release-tools.yml,
|
|
87
|
+
# whose push to a release branch changes .github/workflows; a push of that path is refused without it.
|
|
88
|
+
# It comes before the checkout so that the checkout keeps the App token for the push of the pin step.
|
|
75
89
|
- id: app-token
|
|
76
90
|
if: vars.@@clientIdVariable@@ != ''
|
|
77
91
|
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
|
@@ -79,7 +93,20 @@ jobs:
|
|
|
79
93
|
client-id: ${{ vars.@@clientIdVariable@@ }}
|
|
80
94
|
private-key: ${{ secrets.@@privateKeySecret@@ }}
|
|
81
95
|
|
|
96
|
+
- uses: actions/checkout@v7
|
|
97
|
+
with:
|
|
98
|
+
# train_stage reads the Release-Train-Stage trailer from history; a shallow checkout would not find it
|
|
99
|
+
fetch-depth: 0
|
|
100
|
+
token: ${{ steps.app-token.outputs.token || github.token }}
|
|
101
|
+
|
|
102
|
+
# 這次 run 排隊期間,發布分支可能已被收尾刪掉(push 的 commit 不是產品 commit,上面的 if 擋不到)。
|
|
103
|
+
# 分支不在就讓下面所有步驟略過,run 不失敗;讀不到 origin 則照樣失敗。這一步用 checkout 留下的 token 讀 origin。
|
|
104
|
+
- id: branch
|
|
105
|
+
name: Release branch still on origin
|
|
106
|
+
run: bash scripts/ci/branch-exists.sh >> "$GITHUB_OUTPUT"
|
|
107
|
+
|
|
82
108
|
- id: rp
|
|
109
|
+
if: steps.branch.outputs.exists == 'true'
|
|
83
110
|
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
|
|
84
111
|
with:
|
|
85
112
|
token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
@@ -88,6 +115,7 @@ jobs:
|
|
|
88
115
|
manifest-file: .release-please-manifest.json
|
|
89
116
|
|
|
90
117
|
- name: Summary
|
|
118
|
+
if: steps.branch.outputs.exists == 'true'
|
|
91
119
|
run: |
|
|
92
120
|
{
|
|
93
121
|
echo "### release-please on \`${GITHUB_REF_NAME}\`"
|
|
@@ -96,19 +124,19 @@ jobs:
|
|
|
96
124
|
echo "- paths_released: ${{ steps.rp.outputs.paths_released }}"
|
|
97
125
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
98
126
|
|
|
99
|
-
# apps
|
|
127
|
+
# apps/* 與 services/* 的 prerelease → 依階段部署到對應環境(deploy-prerelease.yml,階段與環境對應見 scripts/lib/release-stages.sh)。infra/* 只發布介面,不部署,雲端資源由 ops 的 iac 步驟建立。正式版不在此 dispatch:prod 由產品 tag 統一觸發。
|
|
100
128
|
# 有 App token 時 tag 自己會觸發 deploy-prerelease,這一步就不需要,跑了還會變成部署兩次。
|
|
101
|
-
- name: Dispatch prerelease deploy for released apps
|
|
102
|
-
if: steps.rp.outputs.releases_created == 'true' && vars.@@clientIdVariable@@ == ''
|
|
129
|
+
- name: Dispatch prerelease deploy for released apps and services (無 App token 時才需要)
|
|
130
|
+
if: steps.branch.outputs.exists == 'true' && steps.rp.outputs.releases_created == 'true' && vars.@@clientIdVariable@@ == ''
|
|
103
131
|
env:
|
|
104
132
|
GH_TOKEN: ${{ github.token }}
|
|
105
133
|
PATHS: ${{ steps.rp.outputs.paths_released }}
|
|
106
134
|
OUTPUTS: ${{ toJSON(steps.rp.outputs) }}
|
|
107
135
|
run: |
|
|
108
|
-
for p in $(echo "$PATHS" | jq -r '.[] | select(startswith("apps/") or startswith("services/")
|
|
136
|
+
for p in $(echo "$PATHS" | jq -r '.[] | select(startswith("apps/") or startswith("services/"))'); do
|
|
109
137
|
tag=$(echo "$OUTPUTS" | jq -r --arg k "${p}--tag_name" '.[$k] // empty')
|
|
110
138
|
if [[ -z "$tag" ]]; then echo "no tag_name output for $p, skipping"; continue; fi
|
|
111
|
-
if [[ "$tag" != *-* ]]; then echo "$tag 為正式版,
|
|
139
|
+
if [[ "$tag" != *-* ]]; then echo "$tag 為正式版,prod 由產品 tag 統一觸發,略過"; continue; fi
|
|
112
140
|
echo "dispatch deploy-prerelease.yml for $tag"
|
|
113
141
|
gh workflow run deploy-prerelease.yml --ref "$tag" -f tag="$tag"
|
|
114
142
|
done
|
|
@@ -119,19 +147,75 @@ jobs:
|
|
|
119
147
|
# 所以 dispatch-publish.sh 依每個單元自己的版號算階段,每個階段各派送一次 publish.yml,publish.yml 再逐單元核對
|
|
120
148
|
# 版號屬於這個階段。tag 不會觸發發布,有沒有 App token 都由這裡派送。
|
|
121
149
|
- name: Dispatch publish for released packages
|
|
122
|
-
if: steps.rp.outputs.releases_created == 'true'
|
|
150
|
+
if: steps.branch.outputs.exists == 'true' && steps.rp.outputs.releases_created == 'true'
|
|
123
151
|
env:
|
|
124
152
|
GH_TOKEN: ${{ github.token }}
|
|
125
153
|
PATHS: ${{ steps.rp.outputs.paths_released }}
|
|
126
154
|
run: bash scripts/release/dispatch-publish.sh
|
|
127
155
|
|
|
156
|
+
# 釘版:這次 run 建立或更新了 Release PR(prs_created 在建立與只更新時都是 'true',沒有變動時是 'false'),而且沒有建 tag。
|
|
157
|
+
# 釘版中途失敗後重跑同一個 job 時,release-please 沒有東西可更新,prs_created 是 'false',所以 run_attempt 大於 1
|
|
158
|
+
# 也做。其餘的 run 不裝相依套件。沒有 App 時略過,由合 Release PR 的 workflow 或本機的 merge-release-pr.sh 釘。
|
|
159
|
+
# 條件沒成立的情形(沒有開著的 Release PR、分支在 release-please 之後又前進、版號不符)由腳本判斷,結論都是成功。
|
|
160
|
+
- id: pin-conditions
|
|
161
|
+
if: steps.branch.outputs.exists == 'true' && vars.@@clientIdVariable@@ != '' && steps.rp.outputs.releases_created != 'true' && (steps.rp.outputs.prs_created == 'true' || github.run_attempt > 1)
|
|
162
|
+
run: echo "run=true" >> "$GITHUB_OUTPUT"
|
|
163
|
+
- uses: ./.github/actions/setup-workspace
|
|
164
|
+
if: steps.pin-conditions.outputs.run == 'true'
|
|
165
|
+
- name: Pin next to the versions of the Release PR
|
|
166
|
+
if: steps.pin-conditions.outputs.run == 'true'
|
|
167
|
+
env:
|
|
168
|
+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
|
169
|
+
BRANCH: ${{ github.ref_name }}
|
|
170
|
+
run: |
|
|
171
|
+
git config user.name "github-actions[bot]"
|
|
172
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
173
|
+
bash scripts/release/pin-release-pr.sh --line "${BRANCH#release/v}" --yes
|
|
174
|
+
|
|
175
|
+
# 合回:階段是 ga 而且這條線要的最終 tag 都齊了才輸出 true,下一個 job 以它為條件。tag 是上面 release-please 這次 run 才建的,
|
|
176
|
+
# 所以腳本先取回 tag。沒有單元升版的線也算齊,但它可能沒有這個事件,那條線靠手動的 merge-back workflow 補。
|
|
177
|
+
- id: ready
|
|
178
|
+
if: steps.branch.outputs.exists == 'true' && vars.@@clientIdVariable@@ != ''
|
|
179
|
+
run: bash scripts/release/merge-back-ready.sh >> "$GITHUB_OUTPUT"
|
|
180
|
+
|
|
181
|
+
# GA 之後開合回 PR:上一個 job 算出階段是 ga 且最終 tag 都齊了才啟動,條件沒成立時這個 job 不啟動,不佔 runner。
|
|
182
|
+
# 推送與開 PR 用 App 的權杖,不然合回 PR 的檢查不會跑。需要 App,所以沒有 App 的倉略過。
|
|
183
|
+
merge-back:
|
|
184
|
+
needs: release-please
|
|
185
|
+
if: needs.release-please.outputs.merge_back_ready == 'true' && vars.@@clientIdVariable@@ != ''
|
|
186
|
+
runs-on: self-hosted-linux
|
|
187
|
+
timeout-minutes: 15
|
|
188
|
+
permissions:
|
|
189
|
+
contents: read
|
|
190
|
+
steps:
|
|
191
|
+
- id: app-token
|
|
192
|
+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
|
193
|
+
with:
|
|
194
|
+
client-id: ${{ vars.@@clientIdVariable@@ }}
|
|
195
|
+
private-key: ${{ secrets.@@privateKeySecret@@ }}
|
|
196
|
+
- uses: actions/checkout@v7
|
|
197
|
+
with:
|
|
198
|
+
ref: ${{ github.ref_name }}
|
|
199
|
+
fetch-depth: 0
|
|
200
|
+
token: ${{ steps.app-token.outputs.token }}
|
|
201
|
+
- uses: ./.github/actions/setup-workspace
|
|
202
|
+
- name: Open the merge-back PR
|
|
203
|
+
env:
|
|
204
|
+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
|
205
|
+
BRANCH: ${{ github.ref_name }}
|
|
206
|
+
run: |
|
|
207
|
+
git config user.name "github-actions[bot]"
|
|
208
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
209
|
+
bash scripts/release/finalize-release.sh --line "${BRANCH#release/v}" --phase merge-back --yes
|
|
210
|
+
|
|
128
211
|
# 只在沒有 App token 的退路上需要。派送與發版在同一個 run,release 與 tag 建好之後 run 若因暫時性錯誤
|
|
129
212
|
# 失敗(實測 2026-09-09:GitHub GraphQL 回 "Something went wrong"),上面的派送步驟被略過,而
|
|
130
213
|
# GITHUB_TOKEN 建的 tag 不觸發 push 事件,預發布部署就永遠不會發生。此 job 在每次 run 之後(含失敗)依
|
|
131
214
|
# manifest 補派送缺漏的 prerelease 部署;可重複執行。有 App token 時 tag 事件本身就是那個保證。
|
|
215
|
+
# 發布分支已被刪掉時(branch_exists 為 false),沒有分支可補,這個 job 也略過。
|
|
132
216
|
ensure-stage-deploys:
|
|
133
217
|
needs: release-please
|
|
134
|
-
if: always() && needs.release-please.result != 'skipped' && vars.@@clientIdVariable@@ == ''
|
|
218
|
+
if: always() && needs.release-please.result != 'skipped' && needs.release-please.outputs.branch_exists != 'false' && vars.@@clientIdVariable@@ == ''
|
|
135
219
|
runs-on: self-hosted-linux
|
|
136
220
|
timeout-minutes: 5
|
|
137
221
|
permissions:
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
name: sync-release-tools
|
|
2
|
+
|
|
3
|
+
# 同步發布工具:main 上的 scripts/、.github/workflows/、.github/actions/ 有推送時,把開著的發布線上落後 main 的那幾個路徑
|
|
4
|
+
# 還原成 main 的版本,commit 後推到發布分支。發布期間 main 改了 workflow 或腳本是常態,發布分支不同步的話,推進階段前的
|
|
5
|
+
# 工具閘(advance-release.sh)會擋下來。邏輯在 scripts/release/sync-release-tools.sh,說明與略過的條件寫在那裡:
|
|
6
|
+
# 發布線已推了產品 commit 或合回 PR 開著時略過(產品 tag 打在發布分支的最後一個 commit,多一個同步 commit 會被一起發布),
|
|
7
|
+
# 發布線自己改過這些路徑時失敗並印出那些 commit,推送被拒時取回最新的分支再試一次。
|
|
8
|
+
# release-please.yml 讀的是發布分支上的檔,已開著的發布線要靠這支把 scripts/release/ 的新腳本帶過去,釘版與合回的步驟才找得到。
|
|
9
|
+
#
|
|
10
|
+
# 另可手動觸發(後備,事件沒接到時補做):輸入發布線,沒填就處理全部開著的線。手動觸發需要 GitHub App,沒有 App 的倉跑它會在
|
|
11
|
+
# create-github-app-token 失敗。事件觸發時沒有 App 的倉整個 job 略過、結論成功,照舊在本機跑 scripts/release/sync-release-tools.sh。
|
|
12
|
+
# 推送用 GitHub App 的權杖:GITHUB_TOKEN 推的分支不觸發 ci,推進階段的 CI 閘就等不到那個 commit 的 ci;
|
|
13
|
+
# 而且推 .github/workflows 的變更要 App 有 Workflows 的寫入權限(Contents、Pull requests、Issues、Workflows)。
|
|
14
|
+
# 手動觸發時先檢查觸發者(倉層變數 RELEASE_TRIGGER_ACTORS,逗號分隔的帳號,沒設時不限制,比對的是 github.triggering_actor),
|
|
15
|
+
# 檢查在取 App 權杖之前,用的是 main 的 checkout,所以名單外的人觸發時權杖不會被取出。
|
|
16
|
+
|
|
17
|
+
on:
|
|
18
|
+
push:
|
|
19
|
+
branches:
|
|
20
|
+
- main
|
|
21
|
+
paths:
|
|
22
|
+
- "scripts/**"
|
|
23
|
+
- ".github/workflows/**"
|
|
24
|
+
- ".github/actions/**"
|
|
25
|
+
workflow_dispatch:
|
|
26
|
+
inputs:
|
|
27
|
+
line:
|
|
28
|
+
description: "the release line, X.Y. Empty: every open release line"
|
|
29
|
+
required: false
|
|
30
|
+
default: ""
|
|
31
|
+
type: string
|
|
32
|
+
|
|
33
|
+
permissions:
|
|
34
|
+
contents: read
|
|
35
|
+
|
|
36
|
+
defaults:
|
|
37
|
+
run:
|
|
38
|
+
shell: bash
|
|
39
|
+
|
|
40
|
+
# one run at a time: two syncs would push to the same branches. A run that waits is not cancelled, and it reads main again when it starts
|
|
41
|
+
concurrency:
|
|
42
|
+
group: release-tool-sync
|
|
43
|
+
cancel-in-progress: false
|
|
44
|
+
|
|
45
|
+
env:
|
|
46
|
+
# a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
|
|
47
|
+
POLL_TRIES: "2"
|
|
48
|
+
CI_GATE_TRIES: "2"
|
|
49
|
+
CI_GATE_QUEUE_TRIES: "0"
|
|
50
|
+
|
|
51
|
+
jobs:
|
|
52
|
+
sync:
|
|
53
|
+
# the workflow of another branch would run with the key of the App; without the App an event does nothing, a manual run fails at the token
|
|
54
|
+
if: github.ref_name == github.event.repository.default_branch && (github.event_name == 'workflow_dispatch' || vars.@@clientIdVariable@@ != '')
|
|
55
|
+
runs-on: self-hosted-linux
|
|
56
|
+
timeout-minutes: 15
|
|
57
|
+
steps:
|
|
58
|
+
- name: Default branch, read only
|
|
59
|
+
uses: actions/checkout@v7
|
|
60
|
+
with:
|
|
61
|
+
fetch-depth: 1
|
|
62
|
+
persist-credentials: false
|
|
63
|
+
- name: Only the listed accounts may run this by hand
|
|
64
|
+
if: github.event_name == 'workflow_dispatch'
|
|
65
|
+
env:
|
|
66
|
+
TRIGGERING_ACTOR: ${{ github.triggering_actor }}
|
|
67
|
+
ALLOWED_ACTORS: ${{ vars.RELEASE_TRIGGER_ACTORS }}
|
|
68
|
+
run: bash scripts/release/check-trigger-actor.sh
|
|
69
|
+
- id: app-token
|
|
70
|
+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
|
71
|
+
with:
|
|
72
|
+
client-id: ${{ vars.@@clientIdVariable@@ }}
|
|
73
|
+
private-key: ${{ secrets.@@privateKeySecret@@ }}
|
|
74
|
+
# the whole history and every branch: train_commits_not_on_main reads origin/main and origin/release/*. The token stays in the
|
|
75
|
+
# checkout, so the push of the script is the one of the App
|
|
76
|
+
- name: Default branch with the history, pushing as the App
|
|
77
|
+
uses: actions/checkout@v7
|
|
78
|
+
with:
|
|
79
|
+
fetch-depth: 0
|
|
80
|
+
token: ${{ steps.app-token.outputs.token }}
|
|
81
|
+
- uses: ./.github/actions/setup-workspace
|
|
82
|
+
with:
|
|
83
|
+
install: "false"
|
|
84
|
+
- name: Sync the release tooling of the open release lines
|
|
85
|
+
env:
|
|
86
|
+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
|
87
|
+
LINE: ${{ inputs.line }}
|
|
88
|
+
run: |
|
|
89
|
+
git config user.name "github-actions[bot]"
|
|
90
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
91
|
+
bash scripts/release/sync-release-tools.sh ${LINE:+--line "$LINE"} --yes
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"product": { "name": "git-flow-template", "members": [] },
|
|
4
4
|
"access": "public",
|
|
5
5
|
"scope": "@@scope@@",
|
|
6
|
-
"targets": { "alpha": "dev", "beta": "
|
|
6
|
+
"targets": { "alpha": "dev", "beta": "stg", "rc": "stg", "ga": "prod" },
|
|
7
7
|
"units": {
|
|
8
8
|
"product-web": { "kind": "web", "stages": ["alpha", "beta", "rc", "ga"] },
|
|
9
9
|
"product-api": { "kind": "service", "stages": ["alpha", "beta", "rc", "ga"] },
|
|
@@ -4,12 +4,18 @@
|
|
|
4
4
|
"title": "release-policy.json",
|
|
5
5
|
"description": "Fixed release cadence of every release-please unit in a repository, where each stage ships to, and which product the repository belongs to. Explained in docs/release-policy.md.",
|
|
6
6
|
"type": "object",
|
|
7
|
-
"required": ["
|
|
7
|
+
"required": ["access"],
|
|
8
8
|
"additionalProperties": false,
|
|
9
9
|
"allOf": [
|
|
10
|
+
{
|
|
11
|
+
"description": "A repository of the organization layer belongs to no product and leaves product out. Every other repository names its product.",
|
|
12
|
+
"if": { "properties": { "layer": { "const": "organization" } }, "required": ["layer"] },
|
|
13
|
+
"then": { "not": { "required": ["product"] } },
|
|
14
|
+
"else": { "required": ["product"] }
|
|
15
|
+
},
|
|
10
16
|
{
|
|
11
17
|
"description": "A member repository (product.primary) lists its units.",
|
|
12
|
-
"if": { "properties": { "product": { "type": "object", "required": ["primary"] } } },
|
|
18
|
+
"if": { "properties": { "product": { "type": "object", "required": ["primary"] } }, "required": ["product"] },
|
|
13
19
|
"then": { "required": ["units"] }
|
|
14
20
|
},
|
|
15
21
|
{
|
|
@@ -33,8 +39,12 @@
|
|
|
33
39
|
],
|
|
34
40
|
"properties": {
|
|
35
41
|
"$schema": { "type": "string" },
|
|
42
|
+
"layer": {
|
|
43
|
+
"description": "The repository layer: organization for a repository the whole organization shares, product for one that belongs to a product. Left out, it is product. It is not the layer of fact-kit, nor a layer of the placement rules.",
|
|
44
|
+
"enum": ["organization", "product"]
|
|
45
|
+
},
|
|
36
46
|
"product": {
|
|
37
|
-
"description": "The product whose version sequence this repository shares. The primary repository holds the Release Plans under releases/ and lists the members: the product repository itself for a single-repository product, <product>-hub for one spread over several repositories. A member repository names the primary.",
|
|
47
|
+
"description": "The product whose version sequence this repository shares. The primary repository holds the Release Plans under releases/ and lists the members: the product repository itself for a single-repository product, <product>-hub for one spread over several repositories. A member repository names the primary. A repository of the organization layer leaves it out; every other repository writes it.",
|
|
38
48
|
"oneOf": [
|
|
39
49
|
{
|
|
40
50
|
"title": "primary",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Tell a workflow step whether the branch it was started for is still on origin, as a line for $GITHUB_OUTPUT:
|
|
3
|
+
# exists=true | exists=false
|
|
4
|
+
# A run can start after finalize-release.sh deleted the release branch (a push that queued behind longer runs). The
|
|
5
|
+
# steps that read the branch, release-please first, would then fail and leave a red run for a branch that is gone,
|
|
6
|
+
# so the job runs this first and skips its other steps on exists=false.
|
|
7
|
+
#
|
|
8
|
+
# ls-remote exits 2 when origin has no such ref. Any other failure (network, auth) is not "the branch is gone": it
|
|
9
|
+
# stops the script with that status, so a run does not skip its work because origin could not be reached.
|
|
10
|
+
#
|
|
11
|
+
# usage: branch-exists.sh
|
|
12
|
+
# env: BRANCH the branch to look for (default: GITHUB_REF_NAME)
|
|
13
|
+
# git must be able to read origin. The checkout of the job keeps its token for this step.
|
|
14
|
+
set -euo pipefail
|
|
15
|
+
branch="${BRANCH:-${GITHUB_REF_NAME:?BRANCH or GITHUB_REF_NAME is required}}"
|
|
16
|
+
rc=0
|
|
17
|
+
git ls-remote -q --exit-code origin "refs/heads/${branch}" >/dev/null || rc=$?
|
|
18
|
+
if [[ "$rc" -eq 2 ]]; then
|
|
19
|
+
printf '%s\n' >&2 "::warning::branch-exists: $branch 不存在於 origin(發布已收尾,分支已刪除),這次 run 的其餘步驟略過"
|
|
20
|
+
printf 'exists=false\n'
|
|
21
|
+
elif [[ "$rc" -ne 0 ]]; then
|
|
22
|
+
printf '%s\n' >&2 "branch-exists: 讀不到 origin(git ls-remote 結束碼 ${rc})"
|
|
23
|
+
exit "$rc"
|
|
24
|
+
else
|
|
25
|
+
printf '%s\n' >&2 "branch-exists: $branch 存在於 origin"
|
|
26
|
+
printf 'exists=true\n'
|
|
27
|
+
fi
|
|
@@ -17,10 +17,12 @@
|
|
|
17
17
|
# targets or the repository targets
|
|
18
18
|
# - a unit that deploys walks at least one pre-release stage when its own targets or the repository
|
|
19
19
|
# targets have one. Only after deploying does it show how it works with the other services, and a
|
|
20
|
-
# GA-only unit goes to
|
|
20
|
+
# GA-only unit goes to prod as soon as the train enters its first stage
|
|
21
21
|
# - a unit that ships to store channels (mobile, desktop) names a channel for each stage it walks
|
|
22
22
|
# - every dependsOn names a unit the policy lists
|
|
23
23
|
# A <product>-hub has no units and no release-please-config.json, so there is nothing to compare and it passes.
|
|
24
|
+
# A repository of the organization layer (layer: organization) belongs to no product, so product.members is not read.
|
|
25
|
+
# Without units it passes the same way; with units it is checked as a single repository, like any other.
|
|
24
26
|
#
|
|
25
27
|
# usage: check-release-policy.sh [--policy <file>] [--config <file>]
|
|
26
28
|
# defaults: release-policy.json and release-please-config.json at the repository root
|
|
@@ -41,6 +43,9 @@ jq -e 'type == "object"' "$policy" >/dev/null 2>&1 || { printf '%s\n' "✗ $poli
|
|
|
41
43
|
|
|
42
44
|
problems=()
|
|
43
45
|
if ! jq -e 'has("units")' "$policy" >/dev/null; then
|
|
46
|
+
if jq -e '.layer == "organization"' "$policy" >/dev/null; then
|
|
47
|
+
printf '%s\n' "✓ $policy 是組織層的倉,沒有單元可核對"; exit 0
|
|
48
|
+
fi
|
|
44
49
|
if jq -e '(.product.members // []) | length > 0' "$policy" >/dev/null && [[ ! -f "$config" ]]; then
|
|
45
50
|
printf '%s\n' "✓ $policy 是 hub,沒有單元可核對"; exit 0
|
|
46
51
|
fi
|
|
@@ -119,5 +124,11 @@ fi
|
|
|
119
124
|
if (( scoped )); then
|
|
120
125
|
printf '%s\n' "✓ 發布分支的設定已縮成本班單元,政策檔另列的單元不算錯;設定裡的單元都在政策檔,階段去處與 dependsOn 核對通過"
|
|
121
126
|
else
|
|
122
|
-
|
|
127
|
+
# a here-string of an empty list is one empty line, so count the non-empty lines
|
|
128
|
+
count="$(printf '%s\n' "$in_policy" | sed '/^$/d' | wc -l | tr -d ' ')"
|
|
129
|
+
if [[ "$count" == 0 ]]; then
|
|
130
|
+
printf '%s\n' "✓ 政策檔的 units 是空的,沒有單元可核對"
|
|
131
|
+
else
|
|
132
|
+
printf '%s\n' "✓ 政策檔與 release-please 單元一致:${count} 個單元,階段去處與 dependsOn 核對通過"
|
|
133
|
+
fi
|
|
123
134
|
fi
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Pin the "next" rows of the components named by FACT_KIT_TRAIN, in the working tree only. On a release branch
|
|
3
|
-
# the facts are pinned to the Release PR's versions
|
|
4
|
-
#
|
|
5
|
-
#
|
|
3
|
+
# the facts are pinned to the Release PR's versions before the PR merges: first by the release-please job, once
|
|
4
|
+
# it has written the Release PR (scripts/release/pin-release-pr.sh), and by merge-release-pr.sh just before the
|
|
5
|
+
# merge when that job did not (no App, or it missed it). Until the pin is pushed the branch still says "next"
|
|
6
|
+
# and `fact-kit check` reports train-next for a component in the train. This does the same pin in the CI
|
|
7
|
+
# checkout so that check passes. It does not commit and does not push.
|
|
6
8
|
# A component that is not in FACT_KIT_TRAIN is left alone.
|
|
7
9
|
#
|
|
8
10
|
# usage: pin-train.sh
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# The versions the open Release PR of a release branch is about to release, as a line for $GITHUB_ENV:
|
|
3
3
|
# FACT_KIT_TRAIN=--train <component>=<version> --train <component>=<version> ...
|
|
4
|
-
# On a release branch the facts are pinned to those versions before the Release PR merges
|
|
4
|
+
# On a release branch the facts are pinned to those versions before the Release PR merges (by the release-please
|
|
5
|
+
# job once it has written the Release PR, and by merge-release-pr.sh as the fallback), while `describes`
|
|
5
6
|
# still reads the old version from .release-please-manifest.json. `fact-kit check --train` lets since be as new as
|
|
6
|
-
# the train. Prints nothing when the branch has no Release PR.
|
|
7
|
+
# the train. Prints nothing when the branch has no Release PR. That includes a branch that no longer exists on origin:
|
|
8
|
+
# a CI run can start after the release was finalized and the branch deleted, so there is nothing to fetch and no Release PR.
|
|
7
9
|
#
|
|
8
10
|
# The set is release_pr_units (scripts/lib/release-pr.sh): the units whose manifest version on the Release PR's
|
|
9
11
|
# head differs from the release branch's, with the PR's version. Only units that have a component package in
|
|
@@ -18,7 +20,24 @@ source "$(dirname "${BASH_SOURCE[0]}")/../lib/common.sh"
|
|
|
18
20
|
cd "$REPO_ROOT"
|
|
19
21
|
branch="${BRANCH:?BRANCH is not set}"
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
# ls-remote exits 2 when origin has no such ref; any other failure (network, auth) stops the script.
|
|
24
|
+
# The branch is asked about before the fetch and again when the fetch fails: close can delete it between the two (the CI run of the
|
|
25
|
+
# last push to the branch is still going when the merge-back PR merges), and a branch deleted then is the same finalized release.
|
|
26
|
+
gone_or_stop() {
|
|
27
|
+
local rc=0
|
|
28
|
+
git ls-remote -q --exit-code origin "refs/heads/${branch}" >/dev/null || rc=$?
|
|
29
|
+
if [[ "$rc" -eq 2 ]]; then
|
|
30
|
+
warn "release-train: $branch 已不存在於 origin(發布已收尾),沒有開著的 Release PR,不帶 --train"
|
|
31
|
+
exit 0
|
|
32
|
+
elif [[ "$rc" -ne 0 ]]; then
|
|
33
|
+
exit "$rc"
|
|
34
|
+
fi
|
|
35
|
+
}
|
|
36
|
+
gone_or_stop
|
|
37
|
+
if ! git fetch -q origin "+refs/heads/${branch}:refs/remotes/origin/${branch}"; then
|
|
38
|
+
gone_or_stop
|
|
39
|
+
die "release-train: git fetch $branch 失敗,而 $branch 仍在 origin"
|
|
40
|
+
fi
|
|
22
41
|
if ! units="$(release_pr_units "$branch")" || [[ -z "$units" ]]; then
|
|
23
42
|
warn "release-train: $branch 沒有開著的 Release PR(或它沒有單元的版號變動),不帶 --train"
|
|
24
43
|
exit 0
|
|
@@ -26,6 +26,8 @@ ver_key() {
|
|
|
26
26
|
plan_dir() {
|
|
27
27
|
local primary d
|
|
28
28
|
policy_require
|
|
29
|
+
# A repository of the organization layer belongs to no product: its plans are its own, in its own releases/.
|
|
30
|
+
if jq -e '.layer == "organization"' "$(policy_file)" >/dev/null 2>&1; then printf '%s\n' "$REPO_ROOT/releases"; return 0; fi
|
|
29
31
|
primary="$(jq -r '.product.primary // empty' "$(policy_file)")"
|
|
30
32
|
if [[ -z "$primary" ]]; then printf '%s\n' "$REPO_ROOT/releases"; return 0; fi
|
|
31
33
|
d="${HUB_DIR:-$(dirname "$REPO_ROOT")/${primary#*/}}"
|
|
@@ -108,7 +110,7 @@ plan_write_maintenance() {
|
|
|
108
110
|
|
|
109
111
|
## Rollback
|
|
110
112
|
|
|
111
|
-
- 可回退:以 \`deploy-
|
|
113
|
+
- 可回退:以 \`deploy-prod.yml\` 的 \`workflow_dispatch\` 對舊產品 tag \`v${latest}\` 重跑。
|
|
112
114
|
- 不可回退:已推送的 tag 與已送審的行動端版本;補救走下一個維護型發布。
|
|
113
115
|
PLAN
|
|
114
116
|
printf '%s\n' "$f"
|