blueprint-shared-templates 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/.github/workflows/pr-message.yml +1 -1
- package/base/scripts/ci/ci-scope.sh +4 -4
- package/base/scripts/lib/common.sh +21 -3
- package/base/scripts/setup/github-repo-settings.sh +4 -4
- package/deploy/scripts/deploy/plan-prod.sh +1 -1
- package/deploy/scripts/deploy/publish-bundle.sh +3 -3
- package/deploy/scripts/deploy/writeback-ops.sh +4 -2
- package/hub/scripts/release/dispatch-release-lines.sh +10 -5
- package/hub/scripts/release/snapshot-members.sh +1 -1
- package/org/README.md +25 -0
- package/package.json +1 -1
- package/publish/scripts/release/publish-units.sh +2 -2
- package/release/.github/workflows/nightly.yml +2 -2
- package/release/.github/workflows/release-line-finalize.yml +3 -3
- package/release/.github/workflows/release-please.yml +2 -1
- package/release/scripts/ci/branch-exists.sh +1 -1
- package/release/scripts/ci/release-train.sh +2 -2
- package/release/scripts/lib/release-pr.sh +8 -8
- package/release/scripts/lib/release-stages.sh +9 -9
- package/release/scripts/release/close-ready.sh +5 -5
- package/release/scripts/release/cut-release.sh +1 -1
- package/release/scripts/release/ensure-stage-deploys.sh +14 -3
- package/release/scripts/release/finalize-release.sh +12 -12
- package/release/scripts/release/merge-back-ready.sh +1 -1
- package/release/scripts/release/merge-release-pr.sh +1 -1
- package/release/scripts/release/pin-release-pr.sh +1 -1
- package/release/scripts/release/product-release-notes.sh +3 -3
- package/release/scripts/release/sync-release-tools.sh +2 -2
- package/transform.mjs +1 -1
|
@@ -60,5 +60,5 @@ jobs:
|
|
|
60
60
|
run: |
|
|
61
61
|
only=()
|
|
62
62
|
if [[ "$HEAD_REF" == release/* ]]; then only=(--only attribution); fi
|
|
63
|
-
gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json body --jq .body \
|
|
63
|
+
node scripts/lib/retry.mjs read -- gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json body --jq .body \
|
|
64
64
|
| bash scripts/ci/check-commit-body.sh "${only[@]}" --message - --diff "origin/$BASE_REF...HEAD"
|
|
@@ -56,14 +56,14 @@ native_since() { # native_since <base>: true|false, true when there is no base t
|
|
|
56
56
|
|
|
57
57
|
last_green() { # last_green <branch>: head of the branch's latest successful ci run, when HEAD contains it
|
|
58
58
|
local sha
|
|
59
|
-
sha="$(gh run list --workflow "$CI_SCOPE_WORKFLOW" --branch "$1" --status success --limit 1 \
|
|
59
|
+
sha="$(node scripts/lib/retry.mjs read -- gh run list --workflow "$CI_SCOPE_WORKFLOW" --branch "$1" --status success --limit 1 \
|
|
60
60
|
--json headSha --jq '.[0].headSha // empty' 2>/dev/null || true)"
|
|
61
61
|
[[ -n "$sha" ]] && git merge-base --is-ancestor "$sha" HEAD 2>/dev/null && printf '%s\n' "$sha"
|
|
62
62
|
return 0
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
merged_pr_head() { # head of the merged pull request HEAD came from, if any
|
|
66
|
-
gh api "repos/${REPO:?}/commits/$(git rev-parse HEAD)/pulls" \
|
|
66
|
+
node scripts/lib/retry.mjs read -- gh api "repos/${REPO:?}/commits/$(git rev-parse HEAD)/pulls" \
|
|
67
67
|
--jq '[.[] | select(.merged_at != null)][0].head.sha // empty' 2>/dev/null || true
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -77,8 +77,8 @@ case "${EVENT:?}" in
|
|
|
77
77
|
if (( CI_SCOPE_PR_TREE )); then
|
|
78
78
|
head="$(merged_pr_head)"
|
|
79
79
|
if [[ -n "$head" ]]; then
|
|
80
|
-
tree="$(gh api "repos/${REPO:?}/git/commits/$head" --jq .tree.sha 2>/dev/null || true)"
|
|
81
|
-
green="$(gh run list --workflow "$CI_SCOPE_WORKFLOW" --commit "$head" --status success --limit 1 \
|
|
80
|
+
tree="$(node scripts/lib/retry.mjs read -- gh api "repos/${REPO:?}/git/commits/$head" --jq .tree.sha 2>/dev/null || true)"
|
|
81
|
+
green="$(node scripts/lib/retry.mjs read -- gh run list --workflow "$CI_SCOPE_WORKFLOW" --commit "$head" --status success --limit 1 \
|
|
82
82
|
--json databaseId --jq '.[0].databaseId // empty' 2>/dev/null || true)"
|
|
83
83
|
if [[ "$tree" == "$(git rev-parse 'HEAD^{tree}')" && -n "$green" ]]; then
|
|
84
84
|
decide false false "來源 PR 的 head ${head:0:7} 與 HEAD 同 tree,且 ci run ${green} 已通過"
|
|
@@ -107,6 +107,21 @@ external_retry() { # external_retry <push|merge> <target> <cmd>...
|
|
|
107
107
|
return 1
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
# A read of GitHub through retry.mjs (decision transient-error-shared-retry): a transient error is asked again (5 rounds, RETRY_SLEEP
|
|
111
|
+
# seconds apart), any other failure stops at once with the status and the text of the command as they were. Only for a command that
|
|
112
|
+
# reads: a write is never wrapped here, because a write that failed with a 5xx may have happened (use external_retry for the writes
|
|
113
|
+
# that are safe to repeat). A git read gets RETRY_TIMEOUT 600 unless the caller set one, because a fetch may run longer than the 120
|
|
114
|
+
# seconds that retry.mjs allows one attempt of a read by default.
|
|
115
|
+
read_retry() { # read_retry <gh|git> <args>...
|
|
116
|
+
if [[ "$1" == git && -z "${RETRY_TIMEOUT:-}" ]]; then RETRY_TIMEOUT="${GIT_READ_TIMEOUT:-600}" node "$RETRY_MJS" read -- "$@"
|
|
117
|
+
else node "$RETRY_MJS" read -- "$@"; fi
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
# run_read <cmd>...: run() for a read that may be asked again after a transient error (see read_retry). Same dry-run output as run().
|
|
121
|
+
run_read() {
|
|
122
|
+
if (( DRY_RUN )); then printf '%s\n' " [dry-run] $*"; else printf '%s\n' " \$ $*"; read_retry "$@"; fi
|
|
123
|
+
}
|
|
124
|
+
|
|
110
125
|
remote_target() { git remote get-url origin 2>/dev/null | sed -E 's#(git@|https://)([^/:]+)[:/]#\2/#; s#\.git$##; s#^[^@]+@##'; }
|
|
111
126
|
|
|
112
127
|
require_clean_tree() {
|
|
@@ -142,9 +157,12 @@ unit_component() { # unit_component packages/cli -> mainflow; the folder name wh
|
|
|
142
157
|
# permission, credentials) the script stops and prints git's error; "no tag" must never be a guess.
|
|
143
158
|
# Call it in the shell itself, not in $(...), so the stop ends the script.
|
|
144
159
|
unit_released() {
|
|
145
|
-
local out
|
|
146
|
-
out
|
|
147
|
-
|
|
160
|
+
local out out_err
|
|
161
|
+
# stderr goes to a file, not into $out: a retried read prints its failed rounds on stderr, and any text in $out means "released"
|
|
162
|
+
out_err="$(mktemp)"
|
|
163
|
+
out="$(read_retry git ls-remote --tags origin "refs/tags/$1/v*" 2>"$out_err")" \
|
|
164
|
+
|| die "查遠端 tag 失敗,無法判斷 $1 發過版沒有(git ls-remote --tags origin):$out$(cat "$out_err")"
|
|
165
|
+
rm -f "$out_err"
|
|
148
166
|
[[ -n "$out" ]]
|
|
149
167
|
}
|
|
150
168
|
|
|
@@ -39,7 +39,7 @@ while [[ $# -gt 0 ]]; do
|
|
|
39
39
|
*) repos+=("$1"); shift ;;
|
|
40
40
|
esac
|
|
41
41
|
done
|
|
42
|
-
if (( ${#repos[@]} == 0 )); then repos=("$(gh repo view --json nameWithOwner --jq .nameWithOwner)"); fi
|
|
42
|
+
if (( ${#repos[@]} == 0 )); then repos=("$(read_retry gh repo view --json nameWithOwner --jq .nameWithOwner)"); fi
|
|
43
43
|
|
|
44
44
|
settings="$(dirname "$0")/github-repo-settings.json"
|
|
45
45
|
squash="$(jq -r '.squash' "$settings")"
|
|
@@ -67,13 +67,13 @@ apply_repo() { # apply_repo <owner/repo>; returns 1 when a request failed
|
|
|
67
67
|
external "github.com/$repo" gh label create "$label" -R "$repo" --color "$label_color" --description "$label_desc" --force || return 1
|
|
68
68
|
return 0
|
|
69
69
|
fi
|
|
70
|
-
current="$(gh api "repos/$repo")" || return 1
|
|
70
|
+
current="$(read_retry gh api "repos/$repo")" || return 1
|
|
71
71
|
if jq -e "$merge_filter" <<<"$current" >/dev/null; then
|
|
72
72
|
info "合併設定已是只開 squash,不送"
|
|
73
73
|
else
|
|
74
74
|
external "github.com/$repo" gh api -X PATCH "repos/$repo" "${merge_args[@]}" || return 1
|
|
75
75
|
fi
|
|
76
|
-
current_days="$(gh api "repos/$repo/actions/permissions/artifact-and-log-retention" --jq .days)" || return 1
|
|
76
|
+
current_days="$(read_retry gh api "repos/$repo/actions/permissions/artifact-and-log-retention" --jq .days)" || return 1
|
|
77
77
|
if [[ "$current_days" == "$days" ]]; then
|
|
78
78
|
info "已是 ${days} 天,不送"
|
|
79
79
|
else
|
|
@@ -81,7 +81,7 @@ apply_repo() { # apply_repo <owner/repo>; returns 1 when a request failed
|
|
|
81
81
|
fi
|
|
82
82
|
local lab_err lab_json
|
|
83
83
|
lab_err="$(mktemp)"
|
|
84
|
-
if lab_json="$(gh api "repos/$repo/labels/$label" 2>"$lab_err")"; then
|
|
84
|
+
if lab_json="$(read_retry gh api "repos/$repo/labels/$label" 2>"$lab_err")"; then
|
|
85
85
|
if jq -e --arg c "$(tr 'A-F' 'a-f' <<<"$label_color")" --arg d "$label_desc" '(.color | ascii_downcase) == $c and .description == $d' <<<"$lab_json" >/dev/null; then
|
|
86
86
|
info "標籤 ${label} 已存在且相同,不送"
|
|
87
87
|
rm -f "$lab_err"; return 0
|
|
@@ -28,7 +28,7 @@ if [[ -n "$ops_root" ]]; then
|
|
|
28
28
|
declared="$(cat "$ops_root/ops/versions.json")" || die "找不到 $ops_root/ops/versions.json"
|
|
29
29
|
else
|
|
30
30
|
branch="${DEFAULT_BRANCH:-main}"
|
|
31
|
-
git fetch --quiet --no-tags origin "$branch" || die "無法從 origin 抓取 ${branch},讀不到 prod 的 ops 宣告"
|
|
31
|
+
read_retry git fetch --quiet --no-tags origin "$branch" || die "無法從 origin 抓取 ${branch},讀不到 prod 的 ops 宣告"
|
|
32
32
|
declared="$(git show "origin/$branch:ops/versions.json")" || die "origin/$branch 沒有 ops/versions.json,讀不到 prod 的 ops 宣告"
|
|
33
33
|
fi
|
|
34
34
|
paths=$(jq -r 'keys[]' "$MANIFEST")
|
|
@@ -16,12 +16,12 @@ bundle="${2:?missing bundle}"
|
|
|
16
16
|
[[ -f "$bundle" ]] || { printf '%s\n' >&2 "找不到 bundle:$bundle"; exit 1; }
|
|
17
17
|
sum="${bundle%.tgz}.sha256"
|
|
18
18
|
[[ -f "$sum" ]] || { printf '%s\n' >&2 "找不到雜湊檔:$sum"; exit 1; }
|
|
19
|
-
repo="${GITHUB_REPOSITORY:-$(gh repo view --json nameWithOwner --jq .nameWithOwner)}"
|
|
20
|
-
if ! gh release view "$tag" --repo "$repo" >/dev/null 2>&1; then
|
|
19
|
+
repo="${GITHUB_REPOSITORY:-$(node "$(dirname "$0")/../lib/retry.mjs" read -- gh repo view --json nameWithOwner --jq .nameWithOwner)}"
|
|
20
|
+
if ! node "$(dirname "$0")/../lib/retry.mjs" read -- gh release view "$tag" --repo "$repo" >/dev/null 2>&1; then
|
|
21
21
|
rc=0
|
|
22
22
|
gh release create "$tag" --repo "$repo" --verify-tag --title "$tag" --notes "bundles of $tag" || rc=$?
|
|
23
23
|
if (( rc != 0 )); then
|
|
24
|
-
gh release view "$tag" --repo "$repo" >/dev/null 2>&1 || exit "$rc"
|
|
24
|
+
node "$(dirname "$0")/../lib/retry.mjs" read -- gh release view "$tag" --repo "$repo" >/dev/null 2>&1 || exit "$rc"
|
|
25
25
|
printf '%s\n' >&2 "[publish-bundle] $tag 的 Release 已由另一個 workflow 建立,繼續上傳"
|
|
26
26
|
fi
|
|
27
27
|
fi
|
|
@@ -53,8 +53,10 @@ branch="${DEFAULT_BRANCH:?DEFAULT_BRANCH is required}"
|
|
|
53
53
|
root="${OPS_ROOT:-$(git rev-parse --show-toplevel)}"
|
|
54
54
|
g() { git -C "$root" "$@"; }
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
# The author is the bot of the organization's GitHub App (the push uses the token the workflow already has). The compose step
|
|
57
|
+
# writes the App name and the user id of its bot account in.
|
|
58
|
+
g config user.name "@@mergeBotApp@@[bot]"
|
|
59
|
+
g config user.email "@@mergeBotUserId@@+@@mergeBotApp@@[bot]@users.noreply.github.com"
|
|
58
60
|
|
|
59
61
|
# Reset ops to the newest branch and run every promotion on it. Returns 0 with changes staged, 10 with none.
|
|
60
62
|
# The caller runs this inside ||, where set -e is off, so every step returns on its own failure.
|
|
@@ -38,8 +38,11 @@ declare -A owner_of
|
|
|
38
38
|
# read stops with the member, the path and everything gh printed.
|
|
39
39
|
for m in "${members[@]}"; do
|
|
40
40
|
policy_path="repos/$m/contents/release-policy.json"
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
# stderr goes to a file, not into $policy: a retried read prints its failed rounds on stderr, which must not reach jq
|
|
42
|
+
policy_err="$(mktemp)"
|
|
43
|
+
policy="$(read_retry gh api -H 'Accept: application/vnd.github.raw+json' "$policy_path" 2>"$policy_err")" \
|
|
44
|
+
|| die "讀不到成員倉 ${m} 的政策檔(gh api ${policy_path}):${policy}$(cat "$policy_err")"
|
|
45
|
+
rm -f "$policy_err"
|
|
43
46
|
for u in "${plan_units[@]}"; do
|
|
44
47
|
if jq -e --arg u "$u" '(.units // {}) | has($u)' <<<"$policy" >/dev/null; then
|
|
45
48
|
[[ -z "${owner_of[$u]:-}" ]] || die "單元 $u 同時在 ${owner_of[$u]} 與 $m 的政策檔"
|
|
@@ -55,9 +58,11 @@ for u in "${plan_units[@]}"; do [[ -n "${owner_of[$u]:-}" ]] || die "plan 的單
|
|
|
55
58
|
release_branch="release/v${plan#v}"
|
|
56
59
|
release_branch="${release_branch%.*}"
|
|
57
60
|
line_is_open() { # line_is_open <member> → success when the member has the release branch
|
|
58
|
-
local refs
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
local refs refs_err
|
|
62
|
+
refs_err="$(mktemp)"
|
|
63
|
+
refs="$(read_retry gh api "repos/$1/git/matching-refs/heads/${release_branch}" --jq '.[].ref' 2>"$refs_err")" \
|
|
64
|
+
|| die "讀不到 ${1} 的分支清單,無法確認 ${release_branch} 開了沒有:${refs}$(cat "$refs_err")"
|
|
65
|
+
rm -f "$refs_err"
|
|
61
66
|
grep -qx "refs/heads/${release_branch}" <<<"$refs"
|
|
62
67
|
}
|
|
63
68
|
|
|
@@ -30,7 +30,7 @@ gh_read() {
|
|
|
30
30
|
local fallback="$1" out err_file rc=0 status
|
|
31
31
|
shift
|
|
32
32
|
err_file="$(mktemp)"
|
|
33
|
-
out="$(gh api "$@" 2>"$err_file")" || rc=$?
|
|
33
|
+
out="$(read_retry gh api "$@" 2>"$err_file")" || rc=$?
|
|
34
34
|
if [[ $rc -eq 0 ]]; then
|
|
35
35
|
rm -f "$err_file"
|
|
36
36
|
printf '%s\n' "$out"
|
package/org/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @@repoName@@
|
|
2
|
+
|
|
3
|
+
`@@organization@@` 組織在組織層的 `@@repoName@@` 倉。它是導入方的組織層倉,放這個組織的組織值與組織層的倉清單,不是管理中樞的複本。共用套件、範本與組織層倉範本由管理中樞發布,這個倉只放導入方該有的東西。
|
|
4
|
+
|
|
5
|
+
## 放什麼
|
|
6
|
+
|
|
7
|
+
- `facts/` 是 `@@aggregatePackageName@@`。它有兩筆 fact:組織值(`@@repoName@@.org-values`,欄位定義在共用 fact `blueprint-shared.org-values`,fact-kit 依那份 schema 驗證),以及組織層的倉清單(`@@repoName@@.org-layout.repos`)。
|
|
8
|
+
- `docs/` 是 `@@scope@@/@@repoName@@-docs`。它放組織層的文件,並引用上面的 fact 與共用 fact。`docs/@@repoName@@-docs/@@repoName@@/layer-names.doc.ts` 寫出各倉的 facts、docs 套件名怎麼從這一層推出。
|
|
9
|
+
- `scripts/ci/check-org-values.mjs` 逐欄位核對組織值,缺欄位、多欄位或型別不對時印出欄位名。
|
|
10
|
+
|
|
11
|
+
## 依賴
|
|
12
|
+
|
|
13
|
+
共用套件 `blueprint-shared-facts` 與 `blueprint-shared-docs` 從公開的 npm 安裝。`@@scope@@` scope 的套件發到 @@aggregateRegistry@@。
|
|
14
|
+
|
|
15
|
+
## GitHub App 的權限
|
|
16
|
+
|
|
17
|
+
組織的 bot App 要開這些 repository 權限,發版與合併的 workflow 才讀寫得動:Contents (write)、Pull requests (write)、Issues (write)、Workflows (write)、Actions (read)、Checks (read)、Statuses (read)、Variables (read)。有 workflow 要觸發另一個 workflow 的倉,另需 Actions (write)。依據是共用 fact `blueprint-shared.templates.github-app-placement` 的 `permissions`。
|
|
18
|
+
|
|
19
|
+
## 建置
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pnpm install
|
|
23
|
+
pnpm build
|
|
24
|
+
pnpm check
|
|
25
|
+
```
|
package/package.json
CHANGED
|
@@ -138,10 +138,10 @@ unit_tag() { printf '%s/v%s\n' "$(unit_component "$1")" "$2"; }
|
|
|
138
138
|
# for GITHUB_SERVER_URL passed through the environment of git (GIT_CONFIG_*): the token is not written to any file and
|
|
139
139
|
# is not in the arguments of a process. Without GH_TOKEN the command runs as it is.
|
|
140
140
|
origin_git() { # origin_git <git arguments>...
|
|
141
|
-
[[ -n "${GH_TOKEN:-}" ]] || { git "$@"; return; }
|
|
141
|
+
[[ -n "${GH_TOKEN:-}" ]] || { read_retry git "$@"; return; }
|
|
142
142
|
local basic; basic="$(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n')"
|
|
143
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 "$@"
|
|
144
|
+
GIT_CONFIG_VALUE_0="AUTHORIZATION: basic ${basic}" read_retry git "$@"
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
# A publish that failed after its tag was made can be dispatched again from the release branch once the fix lands
|
|
@@ -69,8 +69,8 @@ jobs:
|
|
|
69
69
|
- name: 發布分支與版號狀態
|
|
70
70
|
run: |
|
|
71
71
|
fail=0
|
|
72
|
-
rel=$(git ls-remote --heads origin 'refs/heads/release/*' | wc -l | tr -d ' ')
|
|
73
|
-
bot=$(git ls-remote --heads origin 'refs/heads/release-please--*' | wc -l | tr -d ' ')
|
|
72
|
+
rel=$(node scripts/lib/retry.mjs read -- git ls-remote --heads origin 'refs/heads/release/*' | wc -l | tr -d ' ')
|
|
73
|
+
bot=$(node scripts/lib/retry.mjs read -- git ls-remote --heads origin 'refs/heads/release-please--*' | wc -l | tr -d ' ')
|
|
74
74
|
if [ "$rel" -gt 1 ]; then echo "::error::有 $rel 條 release 分支,不變式要求任一時刻 ≤ 1"; fail=1
|
|
75
75
|
else echo "✓ release 分支 $rel 條"; fi
|
|
76
76
|
if [ "$bot" -gt 0 ] && [ "$rel" -eq 0 ]; then echo "::error::無發布分支卻殘留 $bot 條 release-please 工作分支"; fail=1
|
|
@@ -74,7 +74,7 @@ jobs:
|
|
|
74
74
|
echo "### governance sync"
|
|
75
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
76
|
# same head and version, as after a repository was reset), and pipefail then fails the step with 141 (SIGPIPE)
|
|
77
|
-
pr="$(gh pr list --state merged --base main --head "release/v${line}--to-main" --limit 20 --json number,title \
|
|
77
|
+
pr="$(node scripts/lib/retry.mjs read -- gh pr list --state merged --base main --head "release/v${line}--to-main" --limit 20 --json number,title \
|
|
78
78
|
--jq "first(.[] | select(.title | contains(\"product v${v} \"))) | \"#\\(.number) \\(.title)\"")"
|
|
79
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
|
|
80
80
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
@@ -92,11 +92,11 @@ jobs:
|
|
|
92
92
|
{
|
|
93
93
|
open=""
|
|
94
94
|
for _ in 1 2 3 4 5 6; do
|
|
95
|
-
open="$(gh issue list --label "release:v${v}" --state open --json number --jq '[.[].number | "#\(.)"] | join(", ")')"
|
|
95
|
+
open="$(node scripts/lib/retry.mjs read -- gh issue list --label "release:v${v}" --state open --json number --jq '[.[].number | "#\(.)"] | join(", ")')"
|
|
96
96
|
[ -z "$open" ] && break
|
|
97
97
|
sleep 10
|
|
98
98
|
done
|
|
99
|
-
total="$(gh issue list --label "release:v${v}" --state all --limit 500 --json number --jq length)"
|
|
99
|
+
total="$(node scripts/lib/retry.mjs read -- gh issue list --label "release:v${v}" --state all --limit 500 --json number --jq length)"
|
|
100
100
|
if [ -z "$open" ]; then echo "- ✓ release:v${v} 的 Issue ${total} 個全部關閉"
|
|
101
101
|
else echo "- ✗ release:v${v} 仍有 Issue 未關閉:${open}"; fail=1; fi
|
|
102
102
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
@@ -82,9 +82,10 @@ jobs:
|
|
|
82
82
|
merge_back_ready: ${{ steps.ready.outputs.ready }}
|
|
83
83
|
steps:
|
|
84
84
|
# Only when the App is configured; otherwise the step is skipped and its empty output falls
|
|
85
|
-
# through to GITHUB_TOKEN below. The App needs Contents, Pull requests, Issues and Workflows (write):
|
|
85
|
+
# through to GITHUB_TOKEN below. The App needs Contents, Pull requests, Issues and Workflows (write), and Actions (read):
|
|
86
86
|
# release-please labels its PRs, and PR labels go through the Issues API. Workflows is for sync-release-tools.yml,
|
|
87
87
|
# whose push to a release branch changes .github/workflows; a push of that path is refused without it.
|
|
88
|
+
# Actions (read) is for the release scripts, which list workflow runs with gh run list (scripts/lib/release-pr.sh).
|
|
88
89
|
# It comes before the checkout so that the checkout keeps the App token for the push of the pin step.
|
|
89
90
|
- id: app-token
|
|
90
91
|
if: vars.@@clientIdVariable@@ != ''
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
set -euo pipefail
|
|
15
15
|
branch="${BRANCH:-${GITHUB_REF_NAME:?BRANCH or GITHUB_REF_NAME is required}}"
|
|
16
16
|
rc=0
|
|
17
|
-
git ls-remote -q --exit-code origin "refs/heads/${branch}" >/dev/null || rc=$?
|
|
17
|
+
node "$(dirname "$0")/../lib/retry.mjs" read -- git ls-remote -q --exit-code origin "refs/heads/${branch}" >/dev/null || rc=$?
|
|
18
18
|
if [[ "$rc" -eq 2 ]]; then
|
|
19
19
|
printf '%s\n' >&2 "::warning::branch-exists: $branch 不存在於 origin(發布已收尾,分支已刪除),這次 run 的其餘步驟略過"
|
|
20
20
|
printf 'exists=false\n'
|
|
@@ -25,7 +25,7 @@ branch="${BRANCH:?BRANCH is not set}"
|
|
|
25
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
26
|
gone_or_stop() {
|
|
27
27
|
local rc=0
|
|
28
|
-
git ls-remote -q --exit-code origin "refs/heads/${branch}" >/dev/null || rc=$?
|
|
28
|
+
read_retry git ls-remote -q --exit-code origin "refs/heads/${branch}" >/dev/null || rc=$?
|
|
29
29
|
if [[ "$rc" -eq 2 ]]; then
|
|
30
30
|
warn "release-train: $branch 已不存在於 origin(發布已收尾),沒有開著的 Release PR,不帶 --train"
|
|
31
31
|
exit 0
|
|
@@ -34,7 +34,7 @@ gone_or_stop() {
|
|
|
34
34
|
fi
|
|
35
35
|
}
|
|
36
36
|
gone_or_stop
|
|
37
|
-
if ! git fetch -q origin "+refs/heads/${branch}:refs/remotes/origin/${branch}"; then
|
|
37
|
+
if ! read_retry git fetch -q origin "+refs/heads/${branch}:refs/remotes/origin/${branch}"; then
|
|
38
38
|
gone_or_stop
|
|
39
39
|
die "release-train: git fetch $branch 失敗,而 $branch 仍在 origin"
|
|
40
40
|
fi
|
|
@@ -14,7 +14,7 @@ POLL_TRIES="${POLL_TRIES:-180}" POLL_SLEEP="${POLL_SLEEP:-3}"
|
|
|
14
14
|
gh_read() {
|
|
15
15
|
local errf status=0
|
|
16
16
|
errf="$(mktemp)"
|
|
17
|
-
GH_READ_OUT="$(
|
|
17
|
+
GH_READ_OUT="$(read_retry gh "$@" 2>"$errf")" || status=$?
|
|
18
18
|
GH_READ_ERR="$(cat "$errf")"
|
|
19
19
|
rm -f "$errf"
|
|
20
20
|
return "$status"
|
|
@@ -75,7 +75,7 @@ release_please_settled() {
|
|
|
75
75
|
local branch="$1" sha="${2:-}" runs open latest conclusion paths
|
|
76
76
|
RELEASE_PLEASE_WAITING=""
|
|
77
77
|
# a failed gh call is not "no runs": it leaves the branch unsettled and the caller asks again
|
|
78
|
-
if ! runs="$(gh run list --workflow release-please.yml --branch "$branch" --limit 20 --json status,headSha,conclusion,url --jq '.[] | "\(.status) \(.headSha) \(.conclusion // "-") \(.url // "-")"' 2>/dev/null)"; then
|
|
78
|
+
if ! runs="$(read_retry gh run list --workflow release-please.yml --branch "$branch" --limit 20 --json status,headSha,conclusion,url --jq '.[] | "\(.status) \(.headSha) \(.conclusion // "-") \(.url // "-")"' 2>/dev/null)"; then
|
|
79
79
|
RELEASE_PLEASE_WAITING="release-please 的 run 清單查不到(gh run list 失敗)"
|
|
80
80
|
return 1
|
|
81
81
|
fi
|
|
@@ -122,7 +122,7 @@ release_please_settled() {
|
|
|
122
122
|
wait_release_please_idle() {
|
|
123
123
|
local branch="$1" sha="${2:-}" i
|
|
124
124
|
for ((i=1; i<=POLL_TRIES; i++)); do
|
|
125
|
-
git fetch -q origin "$branch" 2>/dev/null || true
|
|
125
|
+
read_retry git fetch -q origin "$branch" 2>/dev/null || true
|
|
126
126
|
release_please_settled "$branch" "$sha" && return 0
|
|
127
127
|
sleep "$POLL_SLEEP"
|
|
128
128
|
done
|
|
@@ -133,7 +133,7 @@ wait_release_please_idle() {
|
|
|
133
133
|
# manifest as it stands on the Release PR's head branch, i.e. the content a merge would land
|
|
134
134
|
release_pr_manifest() { # release_pr_manifest <base-branch>
|
|
135
135
|
local head="release-please--branches--$1"
|
|
136
|
-
git fetch -q origin "$head" 2>/dev/null || return 1
|
|
136
|
+
read_retry git fetch -q origin "$head" 2>/dev/null || return 1
|
|
137
137
|
git show "FETCH_HEAD:$MANIFEST" 2>/dev/null
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -195,7 +195,7 @@ release_pr_settle() {
|
|
|
195
195
|
prev="$sha"; sleep "$POLL_SLEEP"
|
|
196
196
|
done
|
|
197
197
|
RELEASE_PR_NUMBER="$n" RELEASE_PR_SHA="$sha"
|
|
198
|
-
info "Release PR #${n}:$(gh pr view "$n" --json title --jq .title)"
|
|
198
|
+
info "Release PR #${n}:$(read_retry gh pr view "$n" --json title --jq .title)"
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
# --- version check and pin, shared by scripts/release/merge-release-pr.sh and scripts/release/pin-release-pr.sh ---
|
|
@@ -204,7 +204,7 @@ release_pr_settle() {
|
|
|
204
204
|
# Found by its head branch, as wait_release_pr does. A failed gh call stops the script: it is not "no PR".
|
|
205
205
|
release_pr_open_number() {
|
|
206
206
|
local base="$1" out
|
|
207
|
-
out="$(gh pr list --base "$base" --head "release-please--branches--$base" --state open --json number --jq '.[0].number // empty')" \
|
|
207
|
+
out="$(read_retry gh pr list --base "$base" --head "release-please--branches--$base" --state open --json number --jq '.[0].number // empty')" \
|
|
208
208
|
|| die "查不到 ${base} 的 Release PR(gh pr list 失敗)"
|
|
209
209
|
printf '%s\n' "$out"
|
|
210
210
|
}
|
|
@@ -298,8 +298,8 @@ release_pin_open_pr() {
|
|
|
298
298
|
return 0
|
|
299
299
|
fi
|
|
300
300
|
head_ref="release-please--branches--$branch"
|
|
301
|
-
git fetch -q origin "$branch" || die "git fetch origin $branch 沒成功"
|
|
302
|
-
git fetch -q origin "$head_ref" || die "git fetch origin $head_ref 沒成功"
|
|
301
|
+
read_retry git fetch -q origin "$branch" || die "git fetch origin $branch 沒成功"
|
|
302
|
+
read_retry git fetch -q origin "$head_ref" || die "git fetch origin $head_ref 沒成功"
|
|
303
303
|
pr_sha="$(git rev-parse FETCH_HEAD)"
|
|
304
304
|
if ! git merge-base --is-ancestor "origin/$branch" HEAD; then
|
|
305
305
|
RELEASE_PIN_RESULT=skipped RELEASE_PIN_REASON="本機的 ${branch} 落後遠端,留給下一次 run"
|
|
@@ -614,7 +614,7 @@ main_has_train_base() {
|
|
|
614
614
|
# Bring the local train up to its remote. Fetch even under --dry-run; fetching only updates local refs.
|
|
615
615
|
train_sync() { # train_sync <branch>
|
|
616
616
|
local branch="$1"
|
|
617
|
-
git fetch --quiet --tags origin || die "無法從 origin 抓取 tag 與 main,起點閘需要遠端最新的產品 tag"
|
|
617
|
+
read_retry git fetch --quiet --tags origin || die "無法從 origin 抓取 tag 與 main,起點閘需要遠端最新的產品 tag"
|
|
618
618
|
# 明確用遠端追蹤 ref:release-please 的工作分支名尾端同樣是 "$branch",
|
|
619
619
|
# 以短 refname pull 會同時命中兩條而報 "Cannot fast-forward to multiple branches"
|
|
620
620
|
run git merge --ff-only "origin/$branch"
|
|
@@ -625,14 +625,14 @@ train_sync() { # train_sync <branch>
|
|
|
625
625
|
dg_need_slug() {
|
|
626
626
|
[[ -z "$dg_slug" ]] || return 0
|
|
627
627
|
dg_slug="${GITHUB_REPOSITORY:-}"
|
|
628
|
-
[[ -n "$dg_slug" ]] || dg_slug="$(gh repo view --json nameWithOwner --jq .nameWithOwner 2>/dev/null)" \
|
|
628
|
+
[[ -n "$dg_slug" ]] || dg_slug="$(read_retry gh repo view --json nameWithOwner --jq .nameWithOwner 2>/dev/null)" \
|
|
629
629
|
|| die "部署閘無法得知倉名,${1}(設 GITHUB_REPOSITORY,或在有 origin 的倉內執行;本機演練可用 DEPLOY_GATE=0 略過)"
|
|
630
630
|
}
|
|
631
631
|
# dg_ops_gh <gh args>...: gh for the calls that go to the ops repository. With DEPLOY_GATE_OPS_TOKEN set (advance-release.yml gets it from a
|
|
632
632
|
# second GitHub App token limited to the ops repository, read-only: the token of the release branch covers this repository alone, so
|
|
633
633
|
# a private ops repository answers 404 to it) the call uses that token; without it the environment's own GH_TOKEN, as before.
|
|
634
634
|
dg_ops_gh() {
|
|
635
|
-
if [[ -n "${DEPLOY_GATE_OPS_TOKEN:-}" ]]; then GH_TOKEN="$DEPLOY_GATE_OPS_TOKEN" gh "$@"; else gh "$@"; fi
|
|
635
|
+
if [[ -n "${DEPLOY_GATE_OPS_TOKEN:-}" ]]; then GH_TOKEN="$DEPLOY_GATE_OPS_TOKEN" read_retry gh "$@"; else read_retry gh "$@"; fi
|
|
636
636
|
}
|
|
637
637
|
# dg_variable <slug> <name>: the Actions variable <name> as a repository sees it, the repository's own first and the organization's only
|
|
638
638
|
# when the repository has none. Sets dg_val to "set:<value>" (empty when neither level has it) and dg_where to 倉層 or 組織層.
|
|
@@ -642,7 +642,7 @@ dg_variable() {
|
|
|
642
642
|
local slug="$1" name="$2" err text
|
|
643
643
|
if (( dg_repo_read == 0 )); then
|
|
644
644
|
err="$(mktemp)"
|
|
645
|
-
if ! dg_repo_vars="$(gh api --paginate "repos/${slug}/actions/variables" --jq '.variables[] | "\(.name)=\(.value)"' 2>"$err")"; then
|
|
645
|
+
if ! dg_repo_vars="$(read_retry gh api --paginate "repos/${slug}/actions/variables" --jq '.variables[] | "\(.name)=\(.value)"' 2>"$err")"; then
|
|
646
646
|
text="$(cat "$err")"; rm -f "$err"
|
|
647
647
|
die "部署閘無法讀 ${slug} 的倉層變數 ${name}:${text:-gh api 失敗}(查 GitHub App 的 Variables 讀取權限;本機演練可用 DEPLOY_GATE=0 略過)"
|
|
648
648
|
fi
|
|
@@ -653,7 +653,7 @@ dg_variable() {
|
|
|
653
653
|
[[ -z "$dg_val" ]] || return 0
|
|
654
654
|
if (( dg_org_read == 0 )); then
|
|
655
655
|
err="$(mktemp)"
|
|
656
|
-
if ! dg_org_vars="$(gh api --paginate "repos/${slug}/actions/organization-variables" --jq '.variables[] | "\(.name)=\(.value)"' 2>"$err")"; then
|
|
656
|
+
if ! dg_org_vars="$(read_retry gh api --paginate "repos/${slug}/actions/organization-variables" --jq '.variables[] | "\(.name)=\(.value)"' 2>"$err")"; then
|
|
657
657
|
text="$(cat "$err")"; rm -f "$err"
|
|
658
658
|
die "部署閘無法讀 ${slug} 可用的組織層變數 ${name}:${text:-gh api 失敗}(查 GitHub App 的 Variables 讀取權限;本機演練可用 DEPLOY_GATE=0 略過)"
|
|
659
659
|
fi
|
|
@@ -725,14 +725,14 @@ train_gates() { # train_gates <branch> <line> <stage>
|
|
|
725
725
|
# error. Only a successful query that finds no run keeps waiting.
|
|
726
726
|
gh_err="$(mktemp)"
|
|
727
727
|
if [[ -z "$run_id" ]]; then
|
|
728
|
-
if ! st="$(gh run list --workflow ci.yml --branch "$branch" --commit "$tip" --limit 1 --json status,conclusion,databaseId \
|
|
728
|
+
if ! st="$(read_retry gh run list --workflow ci.yml --branch "$branch" --commit "$tip" --limit 1 --json status,conclusion,databaseId \
|
|
729
729
|
--jq '.[0] | "\(.status)/\(.conclusion // "")/\(.databaseId)"' 2>"$gh_err")"; then
|
|
730
730
|
err_text="$(cat "$gh_err")"; rm -f "$gh_err"
|
|
731
731
|
die "${gate}無法查詢 ci 執行紀錄:${err_text:-gh run list 失敗}(查 gh 權限與 token;本機演練可用 CI_GATE=0 略過)"
|
|
732
732
|
fi
|
|
733
733
|
nrun=0
|
|
734
734
|
else
|
|
735
|
-
if ! st="$(gh run view "$run_id" --json status,conclusion,jobs \
|
|
735
|
+
if ! st="$(read_retry gh run view "$run_id" --json status,conclusion,jobs \
|
|
736
736
|
--jq '"\(.status)/\(.conclusion // "")/\([.jobs[] | select(.status == "in_progress")] | length)"' 2>"$gh_err")"; then
|
|
737
737
|
err_text="$(cat "$gh_err")"; rm -f "$gh_err"
|
|
738
738
|
die "${gate}無法查詢 ci run ${run_id}:${err_text:-gh run view 失敗}(查 gh 權限與 token;本機演練可用 CI_GATE=0 略過)"
|
|
@@ -811,10 +811,10 @@ train_gates() { # train_gates <branch> <line> <stage>
|
|
|
811
811
|
info "⊘ ${dg_tag} 部署沒啟用:${dg_slug} 的變數 DEPLOY_ENABLED ${dg_why},值不是 true,沒有部署可核對,放行"
|
|
812
812
|
continue
|
|
813
813
|
fi
|
|
814
|
-
git ls-remote --exit-code --tags origin "refs/tags/$dg_tag" >/dev/null 2>&1 \
|
|
814
|
+
read_retry git ls-remote --exit-code --tags origin "refs/tags/$dg_tag" >/dev/null 2>&1 \
|
|
815
815
|
|| die "部署閘未通過:${dg_tag} 的 tag 尚未建立,無法核對部署(本機演練可用 DEPLOY_GATE=0 略過)"
|
|
816
816
|
dg_err="$(mktemp)"
|
|
817
|
-
if ! dg_st="$(gh run list --workflow deploy-prerelease.yml --branch "$dg_tag" --limit 1 --json status,conclusion,databaseId \
|
|
817
|
+
if ! dg_st="$(read_retry gh run list --workflow deploy-prerelease.yml --branch "$dg_tag" --limit 1 --json status,conclusion,databaseId \
|
|
818
818
|
--jq '.[0] | "\(.status)/\(.conclusion // "")/\(.databaseId)"' 2>"$dg_err")"; then
|
|
819
819
|
dg_text="$(cat "$dg_err")"; rm -f "$dg_err"
|
|
820
820
|
die "部署閘無法查詢 ${dg_tag} 的 deploy-prerelease 執行紀錄:${dg_text:-gh run list 失敗}(查 gh 權限與 token;本機演練可用 DEPLOY_GATE=0 略過)"
|
|
@@ -45,22 +45,22 @@ not_ready() { # not_ready <reason>
|
|
|
45
45
|
|
|
46
46
|
if [[ -z "$pr" ]]; then
|
|
47
47
|
[[ "$line" =~ ^[0-9]+\.[0-9]+$ ]] || die "--pr 或 --line X.Y 要給一個"
|
|
48
|
-
pr="$(gh pr list --base main --head "release/v${line}--to-main" --state open --json number --jq '.[0].number // empty')"
|
|
48
|
+
pr="$(read_retry gh pr list --base main --head "release/v${line}--to-main" --state open --json number --jq '.[0].number // empty')"
|
|
49
49
|
[[ -n "$pr" ]] || not_ready "release/v${line}--to-main 沒有開著的合回 PR:先開合回 PR(merge-back),或它已經合併了"
|
|
50
50
|
fi
|
|
51
51
|
[[ "$pr" =~ ^[0-9]+$ ]] || not_ready "沒有 PR 編號(${pr})"
|
|
52
52
|
|
|
53
|
-
checked_sha="$(gh pr view "$pr" --json headRefOid --jq .headRefOid)"
|
|
53
|
+
checked_sha="$(read_retry gh pr view "$pr" --json headRefOid --jq .headRefOid)"
|
|
54
54
|
# gh pr checks exits 1 for a failed check and 8 for a pending one, and the decision reads both from the output
|
|
55
|
-
rc=0; gh pr checks "$pr" --json name,bucket > "$out/checks.json" 2> "$out/checks.err" || rc=$?
|
|
55
|
+
rc=0; read_retry gh pr checks "$pr" --json name,bucket > "$out/checks.json" 2> "$out/checks.err" || rc=$?
|
|
56
56
|
cat "$out/checks.err" >&2
|
|
57
57
|
# a PR without any check yet: exit 1, nothing on stdout, "no checks reported" on stderr; the decision reads that as "has not run"
|
|
58
58
|
if (( rc == 1 )) && [[ ! -s "$out/checks.json" ]] && grep -q 'no checks reported on the' "$out/checks.err"; then printf '[]\n' > "$out/checks.json"; fi
|
|
59
59
|
(( rc == 0 || rc == 1 || rc == 8 )) || die "gh pr checks 結束碼 $rc"
|
|
60
60
|
# an empty or non-array output means the checks could not be read; it must not reach the decision as "no check ran"
|
|
61
61
|
jq -e 'type == "array"' "$out/checks.json" > /dev/null || die "gh pr checks 結束碼 ${rc},也沒有印出 checks 的 JSON 陣列"
|
|
62
|
-
gh pr diff "$pr" --name-only | jq -R . | jq -s . > "$out/files.json"
|
|
63
|
-
gh pr view "$pr" --json number,state,isDraft,headRefOid,headRefName,baseRefName,isCrossRepository \
|
|
62
|
+
read_retry gh pr diff "$pr" --name-only | jq -R . | jq -s . > "$out/files.json"
|
|
63
|
+
read_retry gh pr view "$pr" --json number,state,isDraft,headRefOid,headRefName,baseRefName,isCrossRepository \
|
|
64
64
|
| jq --arg sha "$checked_sha" --arg event "$head_sha" --slurpfile checks "$out/checks.json" --slurpfile files "$out/files.json" \
|
|
65
65
|
'{pr: ., checkedSha: $sha, eventHeadSha: (if $event == "" then null else $event end), checks: $checks[0], changedFiles: $files[0]}' > "$out/input.json"
|
|
66
66
|
node "$(dirname "$0")/close-ready.mjs" --input "$out/input.json" --config "$config" > "$out/decision.json"
|
|
@@ -94,7 +94,7 @@ fi
|
|
|
94
94
|
plan_check "$plan_file"
|
|
95
95
|
|
|
96
96
|
require_clean_tree
|
|
97
|
-
|
|
97
|
+
run_read git fetch --prune --tags origin
|
|
98
98
|
declare -a existing=()
|
|
99
99
|
while IFS= read -r b; do [[ -n "$b" ]] && existing+=("$b"); done < <(release_branches)
|
|
100
100
|
[[ -z "${existing[0]:-}" ]] || die "遠端已有 release 分支:${existing[*]}(不變式:任一時刻 ≤ 1 條)"
|
|
@@ -14,9 +14,16 @@
|
|
|
14
14
|
# deploy at its stage (no environment declared for the unit, scripts/deploy/route-tag.sh) is skipped, not
|
|
15
15
|
# dispatched. A repository without apps/ or services/ units has nothing to look at, so it never reaches route-tag.sh.
|
|
16
16
|
#
|
|
17
|
+
# The reads of the remote (the tag, the runs) are asked again after a transient error (read_retry of scripts/lib/common.sh). A read
|
|
18
|
+
# that still fails stops the script with the error of git or gh: a failed read is not "no tag" or "no run", because reading it as
|
|
19
|
+
# one dispatches a deploy that may already exist, or skips one that is missing.
|
|
20
|
+
#
|
|
17
21
|
# usage: ensure-stage-deploys.sh (env: GH_TOKEN)
|
|
18
22
|
set -euo pipefail
|
|
23
|
+
source "$(dirname "$0")/../lib/common.sh"
|
|
19
24
|
cd "$(git rev-parse --show-toplevel)"
|
|
25
|
+
err="$(mktemp)"
|
|
26
|
+
trap 'rm -f "$err"' EXIT
|
|
20
27
|
# unit 名稱一律取設定的 component,設定沒有時才退回資料夾名稱(ADR-004 第 36 項)
|
|
21
28
|
units="$(jq -r --slurpfile cfg release-please-config.json '
|
|
22
29
|
($cfg[0].packages) as $pkgs
|
|
@@ -29,14 +36,18 @@ rc=0
|
|
|
29
36
|
while read -r unit ver; do
|
|
30
37
|
[[ -n "$unit" ]] || continue
|
|
31
38
|
tag="$unit/v$ver"
|
|
32
|
-
|
|
39
|
+
# stderr goes to a file: a retried read prints its failed rounds on stderr, and any text on stdout means the tag exists
|
|
40
|
+
found="$(read_retry git ls-remote --tags origin "refs/tags/$tag" 2>"$err")" \
|
|
41
|
+
|| die "讀不到 $tag 有沒有建立(git ls-remote --tags origin),沒有派送:$(cat "$err")"
|
|
42
|
+
if [[ -z "$found" ]]; then printf '%s\n' " ⊘ $tag 尚未建立,略過"; continue; fi
|
|
33
43
|
route="$(bash scripts/deploy/route-tag.sh "$tag")"
|
|
34
44
|
if [[ "$(sed -n 's/^skip=//p' <<<"$route")" == true ]]; then
|
|
35
45
|
printf '%s\n' " ⊘ $tag 無需部署:$(sed -n 's/^reason=//p' <<<"$route")"; continue
|
|
36
46
|
fi
|
|
37
47
|
# a run dispatched with --ref <tag> carries the tag as its head branch. The two newest runs, newest first: one
|
|
38
|
-
# failed run is dispatched again, two in a row are not. A
|
|
39
|
-
runs="$(gh run list --workflow deploy-prerelease.yml --branch "$tag" --limit 2 --json status,conclusion,databaseId 2
|
|
48
|
+
# failed run is dispatched again, two in a row are not. A tag with no run gives [] and exit 0; a query that fails stops here.
|
|
49
|
+
runs="$(read_retry gh run list --workflow deploy-prerelease.yml --branch "$tag" --limit 2 --json status,conclusion,databaseId 2>"$err")" \
|
|
50
|
+
|| die "讀不到 $tag 的 deploy-prerelease run(gh run list),沒有派送:$(cat "$err")"
|
|
40
51
|
verdict="$(jq -r 'def bad: .status == "completed" and .conclusion != "success";
|
|
41
52
|
if length == 0 then "none"
|
|
42
53
|
elif (.[0] | bad) then (if length > 1 and (.[1] | bad) then "failed2 \(.[0].databaseId) \(.[1].databaseId)" else "failed1 \(.[0].databaseId) \(.[0].conclusion)" end)
|
|
@@ -106,7 +106,7 @@ case "$phase" in
|
|
|
106
106
|
merge-back)
|
|
107
107
|
require_clean_tree
|
|
108
108
|
[[ "$(current_branch)" == "$branch" ]] || die "請在 $branch 上執行"
|
|
109
|
-
|
|
109
|
+
run_read git fetch --prune --tags origin
|
|
110
110
|
run git merge --ff-only "origin/$branch"
|
|
111
111
|
resolve_product
|
|
112
112
|
# 這條線還有開著的 Release PR,代表 GA 的 Release PR 沒合併:此時合回,發布分支之後還會有 release-please 的 commit
|
|
@@ -232,7 +232,7 @@ ${refs:+$refs
|
|
|
232
232
|
Release-Plan: v$product
|
|
233
233
|
BODY
|
|
234
234
|
)"
|
|
235
|
-
existing="$(gh pr list --base main --head "$sync_branch" --state open --json number --jq '.[0].number // empty')"
|
|
235
|
+
existing="$(read_retry gh pr list --base main --head "$sync_branch" --state open --json number --jq '.[0].number // empty')"
|
|
236
236
|
if [[ -n "$existing" ]]; then
|
|
237
237
|
info "release PR #$existing 已存在,更新內文"
|
|
238
238
|
external "$target" gh pr edit "$existing" --title "$title" --body "$body"
|
|
@@ -247,7 +247,7 @@ BODY
|
|
|
247
247
|
# 收尾只讀 origin/main,不切到 main:main 常在另一個 worktree 被檢出,切換會失敗。試跑與正式執行
|
|
248
248
|
# 走同一套核對,差別只在對外寫入是否執行。
|
|
249
249
|
require_clean_tree
|
|
250
|
-
|
|
250
|
+
run_read git fetch --prune --tags origin
|
|
251
251
|
resolve_product
|
|
252
252
|
train_open_release_pr_check "$branch" || die "不收尾:${branch} 的 Release PR 還開著,沒有合併、打 tag 或刪分支"
|
|
253
253
|
sync_branch="${branch}--to-main"
|
|
@@ -267,15 +267,15 @@ BODY
|
|
|
267
267
|
# 1. 合併 release PR。合併訊息由這裡指定:GitHub 預設的 squash 訊息會在 PR 內文後面接上各 commit 的
|
|
268
268
|
# 標題,Release-Train-Base 就不在最後一段,git 讀不成 trailer(v0.5.0 實際發生,見待辦 i030)。
|
|
269
269
|
# 讀開著的合回 PR 失敗要停下:把 gh 的錯誤當成「沒有 PR」,PR 明明開著卻不合併,後面會誤報成找不到合併後的 commit。
|
|
270
|
-
# 讀取走
|
|
270
|
+
# 讀取走 read_retry(暫時性錯誤會重試)。空值只在 gh 成功、真的沒有開著的 PR 時出現(例如 PR 已被另一次 close 合併)。
|
|
271
271
|
pr_err="$(mktemp)"
|
|
272
|
-
pr="$(
|
|
272
|
+
pr="$(read_retry gh pr list --base main --head "$sync_branch" --state open --json number --jq '.[0].number // empty' 2>"$pr_err")" || {
|
|
273
273
|
pr_msg="$(cat "$pr_err")"; rm -f "$pr_err"
|
|
274
274
|
die "讀不到開著的 release PR(gh 失敗),沒有合併、打 tag 或刪分支:${pr_msg}"
|
|
275
275
|
}
|
|
276
276
|
rm -f "$pr_err"
|
|
277
277
|
if [[ -n "$pr" ]]; then
|
|
278
|
-
pr_json="$(gh pr view "$pr" --json body,headRefOid,mergeable)"
|
|
278
|
+
pr_json="$(read_retry gh pr view "$pr" --json body,headRefOid,mergeable)"
|
|
279
279
|
body="$(jq -r .body <<<"$pr_json")"
|
|
280
280
|
pr_head="$(jq -r .headRefOid <<<"$pr_json")"
|
|
281
281
|
# The head of the PR must be the commit that was checked. Merging another head would put into main a commit that no check ran for.
|
|
@@ -290,7 +290,7 @@ BODY
|
|
|
290
290
|
fi
|
|
291
291
|
log "以 squash 合併 release PR #${pr}(head ${pr_head:0:7}),合併訊息為 PR 標題與內文,Release-Train-Base 在最後一行"
|
|
292
292
|
external_retry merge "$target" gh pr merge "$pr" --squash --match-head-commit "${head_sha:-$pr_head}" --subject "$title (#$pr)" --body "$body"
|
|
293
|
-
|
|
293
|
+
run_read git fetch --prune --tags origin
|
|
294
294
|
fi
|
|
295
295
|
if [[ -z "$(git log origin/main --format=%H --grep="product v$product" -n 1)" ]]; then
|
|
296
296
|
(( DRY_RUN )) && [[ -n "$pr" ]] && info "[dry-run] release PR #$pr 尚未合併,以下核對僅供參考" \
|
|
@@ -318,7 +318,7 @@ Release-Train-Units: $fix_units}"
|
|
|
318
318
|
-m "Release-Train-Base: $base${fix_units_line}
|
|
319
319
|
Release-Plan: v$product")"
|
|
320
320
|
external_retry push "$target" git push origin "$fix:refs/heads/main"
|
|
321
|
-
|
|
321
|
+
run_read git fetch origin
|
|
322
322
|
else
|
|
323
323
|
info "[dry-run] 補上 Release-Train-Base: $base"
|
|
324
324
|
fi
|
|
@@ -342,7 +342,7 @@ Release-Plan: v$product")"
|
|
|
342
342
|
log "打產品 tag v$product 於發布分支的最後一個 commit ${train_tip:0:7}"
|
|
343
343
|
run git tag -a "v$product" "$train_tip" -m "product v$product"
|
|
344
344
|
fi
|
|
345
|
-
if [[ -z "$(git ls-remote --tags origin "refs/tags/v$product")" ]]; then
|
|
345
|
+
if [[ -z "$(read_retry git ls-remote --tags origin "refs/tags/v$product")" ]]; then
|
|
346
346
|
external_retry push "$target" git push origin "v$product"
|
|
347
347
|
else
|
|
348
348
|
info "v$product 已在遠端"
|
|
@@ -351,7 +351,7 @@ Release-Plan: v$product")"
|
|
|
351
351
|
# 4. 刪除發布分支與流程產生的暫時分支(不變式:兩次發布之間 0 條)。本機分支正被檢出時先切離。
|
|
352
352
|
log "刪除 release 分支與暫時分支"
|
|
353
353
|
for extra in "$branch" "release-please--branches--$branch" "$sync_branch"; do
|
|
354
|
-
if [[ -n "$(git ls-remote --heads origin "refs/heads/$extra")" ]]; then
|
|
354
|
+
if [[ -n "$(read_retry git ls-remote --heads origin "refs/heads/$extra")" ]]; then
|
|
355
355
|
external "$target" git push origin --delete "$extra"
|
|
356
356
|
fi
|
|
357
357
|
done
|
|
@@ -359,7 +359,7 @@ Release-Plan: v$product")"
|
|
|
359
359
|
for local_branch in "$branch" "$sync_branch"; do
|
|
360
360
|
git rev-parse -q --verify "refs/heads/$local_branch" >/dev/null && run git branch -D "$local_branch"
|
|
361
361
|
done
|
|
362
|
-
|
|
362
|
+
run_read git fetch --prune --tags origin
|
|
363
363
|
|
|
364
364
|
# 5. 關閉核對,全部讀遠端與 origin/main。
|
|
365
365
|
printf '\n'
|
|
@@ -367,7 +367,7 @@ Release-Plan: v$product")"
|
|
|
367
367
|
ok=1
|
|
368
368
|
n="$(release_branches | grep -c . || true)"
|
|
369
369
|
[[ "$n" == 0 ]] && info "✓ release 分支數 = 0" || { info "✗ 仍有 release 分支:$(release_branches)"; ok=0; }
|
|
370
|
-
leftover="$(git ls-remote --heads origin 'refs/heads/release-please--*' | wc -l | tr -d ' ')"
|
|
370
|
+
leftover="$(read_retry git ls-remote --heads origin 'refs/heads/release-please--*' | wc -l | tr -d ' ')"
|
|
371
371
|
[[ "$leftover" == 0 ]] && info "✓ 無殘留的 release-please 工作分支" || { info "✗ 仍有 $leftover 條 release-please 工作分支"; ok=0; }
|
|
372
372
|
if git rev-parse -q --verify "refs/tags/v$product" >/dev/null; then
|
|
373
373
|
[[ "$(git show "v$product:package.json" | jq -r .version)" == "$product" ]] \
|
|
@@ -18,7 +18,7 @@ if ! [[ "$branch" =~ ^release/v[0-9]+\.[0-9]+$ ]]; then
|
|
|
18
18
|
echo "ready=false"
|
|
19
19
|
exit 0
|
|
20
20
|
fi
|
|
21
|
-
git fetch -q --tags origin main "$branch" || die "git fetch origin 沒成功,無法判斷最終 tag 齊了沒"
|
|
21
|
+
read_retry git fetch -q --tags origin main "$branch" || die "git fetch origin 沒成功,無法判斷最終 tag 齊了沒"
|
|
22
22
|
if train_merge_back_ready; then
|
|
23
23
|
echo "ready=true"
|
|
24
24
|
else
|
|
@@ -98,7 +98,7 @@ declare -a units=()
|
|
|
98
98
|
read_units() {
|
|
99
99
|
units=()
|
|
100
100
|
local out row
|
|
101
|
-
git fetch -q origin "$branch" || die "取 manifest 失敗:git fetch origin $branch 沒成功"
|
|
101
|
+
read_retry git fetch -q origin "$branch" || die "取 manifest 失敗:git fetch origin $branch 沒成功"
|
|
102
102
|
out="$(release_pr_units "$branch")" || die "取 manifest 失敗:讀不到 Release PR 或 origin/${branch} 的 manifest,不是「沒有差異」"
|
|
103
103
|
while IFS= read -r row; do [[ -z "$row" ]] || units+=("$row"); done < <(sort <<<"$out")
|
|
104
104
|
}
|
|
@@ -44,7 +44,7 @@ for attempt in 1 2; do
|
|
|
44
44
|
(( status != 0 )) || exit 0
|
|
45
45
|
(( attempt == 1 )) || die "推送 ${branch} 被拒兩次,不再重試。等下一次 run"
|
|
46
46
|
warn "推送 ${branch} 被拒,取回最新的分支再試一次"
|
|
47
|
-
git fetch -q origin "$branch" || die "git fetch origin $branch 沒成功"
|
|
47
|
+
read_retry git fetch -q origin "$branch" || die "git fetch origin $branch 沒成功"
|
|
48
48
|
while IFS= read -r subject; do
|
|
49
49
|
[[ "$subject" == "chore(facts): "* || "$subject" == "chore(docs): "* ]] \
|
|
50
50
|
|| die "本機領先遠端的 commit 不全是釘版 commit(${subject}),不丟掉它們"
|
|
@@ -14,15 +14,15 @@ set -euo pipefail
|
|
|
14
14
|
tag="${1:?usage: product-release-notes.sh <tag> <snapshot.md>}"
|
|
15
15
|
notes="${2:?missing snapshot file}"
|
|
16
16
|
[[ -f "$notes" ]] || { printf '%s\n' >&2 "找不到 Snapshot 檔:$notes"; exit 1; }
|
|
17
|
-
repo="${GITHUB_REPOSITORY:-$(gh repo view --json nameWithOwner --jq .nameWithOwner)}"
|
|
18
|
-
if ! gh release view "$tag" --repo "$repo" >/dev/null 2>&1; then
|
|
17
|
+
repo="${GITHUB_REPOSITORY:-$(node "$(dirname "$0")/../lib/retry.mjs" read -- gh repo view --json nameWithOwner --jq .nameWithOwner)}"
|
|
18
|
+
if ! node "$(dirname "$0")/../lib/retry.mjs" read -- gh release view "$tag" --repo "$repo" >/dev/null 2>&1; then
|
|
19
19
|
rc=0
|
|
20
20
|
gh release create "$tag" --repo "$repo" --title "$tag" --notes-file "$notes" || rc=$?
|
|
21
21
|
if (( rc == 0 )); then
|
|
22
22
|
printf '%s\n' "[product-release-notes] ${tag}:已建立 Release,內文是 Snapshot"
|
|
23
23
|
exit 0
|
|
24
24
|
fi
|
|
25
|
-
gh release view "$tag" --repo "$repo" >/dev/null 2>&1 || exit "$rc"
|
|
25
|
+
node "$(dirname "$0")/../lib/retry.mjs" read -- gh release view "$tag" --repo "$repo" >/dev/null 2>&1 || exit "$rc"
|
|
26
26
|
fi
|
|
27
27
|
gh release edit "$tag" --repo "$repo" --notes-file "$notes"
|
|
28
28
|
printf '%s\n' "[product-release-notes] ${tag}:Release 已存在,內文改成 Snapshot"
|
|
@@ -40,7 +40,7 @@ done
|
|
|
40
40
|
target="$(remote_target)"
|
|
41
41
|
|
|
42
42
|
fetch_all() {
|
|
43
|
-
git fetch -q --prune origin '+refs/heads/main:refs/remotes/origin/main' '+refs/heads/release/*:refs/remotes/origin/release/*' \
|
|
43
|
+
read_retry git fetch -q --prune origin '+refs/heads/main:refs/remotes/origin/main' '+refs/heads/release/*:refs/remotes/origin/release/*' \
|
|
44
44
|
|| die "git fetch origin 沒成功,無法判斷發布工具落後多少"
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -72,7 +72,7 @@ sync_line() {
|
|
|
72
72
|
info "⊘ $branch 已推了產品 commit ${product},產品 tag 會打在它的最後一個 commit,不再同步"
|
|
73
73
|
return 0
|
|
74
74
|
fi
|
|
75
|
-
pr="$(gh pr list --base main --head "${branch}--to-main" --state open --json number --jq '.[0].number // empty')" \
|
|
75
|
+
pr="$(read_retry gh pr list --base main --head "${branch}--to-main" --state open --json number --jq '.[0].number // empty')" \
|
|
76
76
|
|| die "gh pr list 沒成功,無法判斷 ${branch} 的合回 PR 是不是開著"
|
|
77
77
|
if [[ -n "$pr" ]]; then
|
|
78
78
|
info "⊘ ${branch} 的合回 PR #${pr} 開著,產品 tag 會打在發布分支的最後一個 commit,不再同步"
|
package/transform.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// not a text conversion and stays with the code that composes a repository.
|
|
9
9
|
|
|
10
10
|
// The fields of the templates, the same list as the fact blueprint-shared.templates.fields (a test compares them).
|
|
11
|
-
export const FIELDS = ["clientIdVariable", "licenseHolder", "mergeLabel", "privateKeySecret", "scope"];
|
|
11
|
+
export const FIELDS = ["aggregatePackageName", "aggregateRegistry", "clientIdVariable", "licenseHolder", "mergeBotApp", "mergeBotUserId", "mergeLabel", "organization", "privateKeySecret", "repoName", "scope"];
|
|
12
12
|
|
|
13
13
|
const FIELD = /@@(\w+)@@/g;
|
|
14
14
|
|