blueprint-shared-templates 0.3.1 → 0.4.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/workflows/auto-merge.yml +14 -4
- 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/lib/retry.mjs +46 -6
- 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/ops/schemas/targets.schema.json +4 -39
- 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 -0
- 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 +35 -12
- 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 +18 -11
- 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
|
@@ -18,6 +18,10 @@ name: auto-merge
|
|
|
18
18
|
# pull_request_target runs this file and the scripts from the base branch, never from the pull request, so the
|
|
19
19
|
# App token is not handed to code of the pull request. A pull request from a fork is never merged.
|
|
20
20
|
# The names of the GitHub App variable and secret are written in when the repository is composed.
|
|
21
|
+
# run-name: a run of the workflow_run event has the head commit and branch of main, so its head sha says nothing about the pull request.
|
|
22
|
+
# The name carries the head sha of the pull request for both events, and the scenario finds the auto-merge runs of a pull request by it.
|
|
23
|
+
run-name: "auto-merge ${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha }}"
|
|
24
|
+
|
|
21
25
|
on:
|
|
22
26
|
pull_request_target:
|
|
23
27
|
types: [labeled]
|
|
@@ -76,15 +80,21 @@ jobs:
|
|
|
76
80
|
GH_TOKEN: ${{ github.token }}
|
|
77
81
|
GH_REPO: ${{ github.repository }}
|
|
78
82
|
PR_NUMBER: ${{ github.event.pull_request.number || github.event.workflow_run.pull_requests[0].number }}
|
|
83
|
+
# the token of this job was made when the job started, so a repository that is not found is asked again (scripts/lib/retry.mjs)
|
|
84
|
+
RETRY_FRESH_TOKEN: "1"
|
|
79
85
|
run: |
|
|
80
86
|
if [[ -z "$PR_NUMBER" ]]; then
|
|
81
87
|
echo "action=skip" >> "$GITHUB_OUTPUT"; echo "no pull request belongs to this event"; exit 0
|
|
82
88
|
fi
|
|
89
|
+
# Every gh call below is a read, so scripts/lib/retry.mjs read asks again after a transient error of GitHub (HTTP 500, 502, 503,
|
|
90
|
+
# 504, a connect timeout such as `dial tcp ...: i/o timeout`), up to 5 attempts RETRY_SLEEP seconds apart (decision
|
|
91
|
+
# transient-error-shared-retry). Any other failure comes back as it was, with the exit status of gh, so the exit status 1 and 8
|
|
92
|
+
# of gh pr checks reach the judgement below unchanged.
|
|
83
93
|
fields=number,state,isDraft,headRefOid,headRefName,baseRefName,isCrossRepository,labels,author,latestReviews
|
|
84
94
|
mkdir -p "$RUNNER_TEMP/merge"
|
|
85
|
-
checked_sha="$(gh pr view "$PR_NUMBER" --json headRefOid --jq .headRefOid)"
|
|
95
|
+
checked_sha="$(node scripts/lib/retry.mjs read -- gh pr view "$PR_NUMBER" --json headRefOid --jq .headRefOid)"
|
|
86
96
|
# gh pr checks exits 1 for a failed check and 8 for a pending one; the decision reads both from the output
|
|
87
|
-
rc=0; gh pr checks "$PR_NUMBER" --json name,bucket > "$RUNNER_TEMP/merge/checks.json" 2> "$RUNNER_TEMP/merge/checks.err" || rc=$?
|
|
97
|
+
rc=0; node scripts/lib/retry.mjs read -- gh pr checks "$PR_NUMBER" --json name,bucket > "$RUNNER_TEMP/merge/checks.json" 2> "$RUNNER_TEMP/merge/checks.err" || rc=$?
|
|
88
98
|
cat "$RUNNER_TEMP/merge/checks.err" >&2
|
|
89
99
|
# a pull request without any check yet: exit 1, nothing on stdout, "no checks reported" on stderr; the decision reads that as "has not run"
|
|
90
100
|
if (( rc == 1 )) && [[ ! -s "$RUNNER_TEMP/merge/checks.json" ]] && grep -q 'no checks reported on the' "$RUNNER_TEMP/merge/checks.err"; then
|
|
@@ -93,8 +103,8 @@ jobs:
|
|
|
93
103
|
(( rc == 0 || rc == 1 || rc == 8 )) || { echo "::error::gh pr checks exited $rc"; exit 1; }
|
|
94
104
|
# an empty or non-array output means the checks could not be read; it must not reach the decision as "no check ran"
|
|
95
105
|
jq -e 'type == "array"' "$RUNNER_TEMP/merge/checks.json" > /dev/null || { echo "::error::gh pr checks exited $rc and printed no JSON array of checks"; exit 1; }
|
|
96
|
-
gh pr diff "$PR_NUMBER" --name-only | jq -R . | jq -s . > "$RUNNER_TEMP/merge/files.json"
|
|
97
|
-
gh pr view "$PR_NUMBER" --json "$fields" \
|
|
106
|
+
node scripts/lib/retry.mjs read -- gh pr diff "$PR_NUMBER" --name-only | jq -R . | jq -s . > "$RUNNER_TEMP/merge/files.json"
|
|
107
|
+
node scripts/lib/retry.mjs read -- gh pr view "$PR_NUMBER" --json "$fields" \
|
|
98
108
|
| jq --arg sha "$checked_sha" --slurpfile checks "$RUNNER_TEMP/merge/checks.json" --slurpfile files "$RUNNER_TEMP/merge/files.json" \
|
|
99
109
|
'{pr: ., checkedSha: $sha, checks: $checks[0], changedFiles: $files[0]}' > "$RUNNER_TEMP/merge/input.json"
|
|
100
110
|
node scripts/merge/decide.mjs --input "$RUNNER_TEMP/merge/input.json" | tee "$RUNNER_TEMP/merge/decision.json"
|
|
@@ -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
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The one place that asks again after a transient error of GitHub (decision transient-error-shared-retry).
|
|
2
|
-
// A transient error is HTTP 500, 502, 503 or 504 (gh and git word it differently
|
|
2
|
+
// A transient error is HTTP 500, 502, 503 or 504 (gh and git word it differently; gh also words a bad answer of a request it makes itself
|
|
3
|
+
// as `non-200 OK status code: 503 Service Unavailable`, with no `HTTP` before the code), a connect timeout (Linux, macOS and Go wordings), a
|
|
3
4
|
// connection that could not be made at all (gh's `error connecting to <host>`, git's `Could not resolve host`) and a break of the connection itself:
|
|
4
|
-
// a TLS handshake timeout, a connection reset by the peer, and a Go net/http read that ends in EOF (`Get "<url>": EOF`, `unexpected EOF`).
|
|
5
|
+
// a TLS handshake timeout, a socket the host could not open (no local address, no network, no route), a connection reset by the peer, and a Go net/http read that ends in EOF (`Get "<url>": EOF`, `unexpected EOF`).
|
|
5
6
|
// Nothing else counts: another 5xx, a 4xx, a refused write, a dropped credential and a text that only has the letters EOF in it (a
|
|
6
7
|
// heredoc marker, EOFError) do not get better by asking again.
|
|
7
8
|
//
|
|
@@ -11,14 +12,22 @@
|
|
|
11
12
|
// CLI node retry.mjs <read|push|merge> -- <cmd> [args...]
|
|
12
13
|
//
|
|
13
14
|
// What each kind retries (a failure of any other text stops at once, with the error as it was):
|
|
14
|
-
// read a transient error,
|
|
15
|
+
// read a transient error, the GraphQL timeout of GitHub (`Something went wrong while executing your query`), a command of the CLI
|
|
16
|
+
// that ran past its timeout (`Command Timeout`), in the CLI with RETRY_FRESH_TOKEN=1 a repository that is not found
|
|
17
|
+
// (FRESH_NOT_FOUND: the token was just made and not every GitHub server knows it yet; with a token that is not new it is the answer),
|
|
18
|
+
// what the caller adds through `also` (local.mjs adds the HTTP 404 of a run that was just dispatched), and
|
|
15
19
|
// in the CLI an answer of a command with --json (and no --jq or --template) that exits 0 but is not whole JSON: gh has cut such
|
|
16
20
|
// an answer short now and then, and asking again gets the whole of it
|
|
17
|
-
// push a transient error, and never a force or a delete (--force, -f, --force-with-lease, --force-if-includes, --delete, -d, +refspec,
|
|
21
|
+
// push a transient error (not `unexpected end of JSON input`: a write may have happened), and never a force or a delete (--force, -f, --force-with-lease, --force-if-includes, --delete, -d, +refspec,
|
|
18
22
|
// :ref, --mirror, --prune): the retry of a write that rewrites or removes history is a decision, not a reflex
|
|
19
|
-
// merge a transient error and "Base branch was modified" (the base moved between the pull request being opened and merged)
|
|
23
|
+
// merge a transient error (not `unexpected end of JSON input`) and "Base branch was modified" (the base moved between the pull request being opened and merged)
|
|
20
24
|
// dispatch a transient error, but first `exists()` asks whether the dispatch made its run; a run that is there is returned and the
|
|
21
25
|
// dispatch is not made again. Without a nonce `exists` cannot be written, so such a dispatch is not retried at all.
|
|
26
|
+
// In the CLI every attempt of a read has a timeout of RETRY_TIMEOUT seconds (120 by default); a push or a merge has one only when
|
|
27
|
+
// RETRY_TIMEOUT is set, because a push runs the pre-push hook of the repository, which may build and check for longer than any default
|
|
28
|
+
// (attemptTimeoutOf). A command that runs longer is killed with SIGKILL
|
|
29
|
+
// (a gh that hangs may ignore SIGTERM, and then the sequence would still wait), one line on stderr says so, and the failure text is
|
|
30
|
+
// `Command Timeout`. Only a read asks again after it; a push or a merge stops, because the write may have happened.
|
|
22
31
|
// The pause between rounds is the caller's (`pause`): this file sleeps only in the CLI, whose interval is RETRY_SLEEP seconds.
|
|
23
32
|
import { spawnSync } from "node:child_process";
|
|
24
33
|
import { resolve } from "node:path";
|
|
@@ -33,6 +42,8 @@ const CODES = ["500", "502", "503", "504"];
|
|
|
33
42
|
export function transientOf(text) {
|
|
34
43
|
const s = String(text ?? "");
|
|
35
44
|
const codes = [...s.matchAll(/\bHTTP\/?\s*(\d{3})\b/gi), ...s.matchAll(/requested URL returned error:\s*(\d{3})\b/gi)].map((m) => m[1]);
|
|
45
|
+
// gh's `error fetching labels: non-200 OK status code: 503 Service Unavailable`: the same error as `HTTP 503`
|
|
46
|
+
codes.push(...[...s.matchAll(/non-200 OK status code:\s*(\d{3})\b/gi)].map((m) => m[1]));
|
|
36
47
|
const code = codes.find((c) => CODES.includes(c));
|
|
37
48
|
if (code) return `HTTP ${code}`;
|
|
38
49
|
// the connect timeout in its three wordings: Linux `connect: connection timed out`, macOS `connect: operation timed out`, and Go's
|
|
@@ -41,6 +52,9 @@ export function transientOf(text) {
|
|
|
41
52
|
// a connection that was not made: gh prints `error connecting to api.github.com` for a failed dial or lookup, git and curl print
|
|
42
53
|
// `Could not resolve host: github.com`
|
|
43
54
|
if (/\berror connecting to [\w-]+(?:\.[\w-]+)+|Could not resolve host:/i.test(s)) return "Connect Failure";
|
|
55
|
+
// a socket the host could not open, only after the `connect:`, `read:` or `write:` of a Go socket error: no free local address (macOS
|
|
56
|
+
// `can't assign requested address`, Linux `cannot assign requested address`), no network and no route
|
|
57
|
+
if (/\b(?:connect|read|write): (?:can't|cannot) assign requested address|\bconnect: (?:network is unreachable|no route to host)/i.test(s)) return "Connect Failure";
|
|
44
58
|
if (/TLS handshake timeout/i.test(s)) return "TLS Handshake Timeout";
|
|
45
59
|
// EOF only in the shape of a dropped connection: after the quoted URL of a Go request, after `read tcp ...:`, or as `unexpected EOF`
|
|
46
60
|
if (/connection reset by peer|"\s*:\s*(?:unexpected\s+)?EOF\b|\b(?:read|write) tcp [^\n]*:\s*EOF\b|\bunexpected EOF\b/i.test(s)) return "Connection Reset";
|
|
@@ -49,6 +63,22 @@ export function transientOf(text) {
|
|
|
49
63
|
|
|
50
64
|
export const BASE_MODIFIED = "Base branch was modified";
|
|
51
65
|
export const INCOMPLETE_JSON = "Incomplete JSON";
|
|
66
|
+
// what gh prints when it cannot parse the answer of a request (exit status non-zero); only a read asks again after it
|
|
67
|
+
export const GH_JSON_END = "unexpected end of JSON input";
|
|
68
|
+
// the GraphQL errors of GitHub that go away when asked again (a read only: a write may have happened)
|
|
69
|
+
export const GRAPHQL_TRANSIENT = ["Something went wrong while executing your query"];
|
|
70
|
+
// what git and gh answer for a repository the token cannot see yet: asked again only for a token that was just made (RETRY_FRESH_TOKEN=1 in
|
|
71
|
+
// the CLI, notFoundOfFreshToken in scripts/sync/sync.mjs), because a 404 of a token that is not new is the answer
|
|
72
|
+
export const FRESH_NOT_FOUND = /Repository not found|Could not resolve to a Repository|HTTP 404/i;
|
|
73
|
+
export const FRESH_NOT_FOUND_REASON = "Repository not found (fresh token)";
|
|
74
|
+
// the failure text of an attempt of the CLI that ran past its timeout
|
|
75
|
+
export const COMMAND_TIMEOUT = "Command Timeout";
|
|
76
|
+
export const TIMEOUT_SECONDS = 120;
|
|
77
|
+
// The timeout of one attempt of the CLI in seconds, or 0 for none: RETRY_TIMEOUT when it is set, else TIMEOUT_SECONDS for a read and none for a write
|
|
78
|
+
export function attemptTimeoutOf(kind, env = {}) {
|
|
79
|
+
if (env.RETRY_TIMEOUT !== undefined && env.RETRY_TIMEOUT !== "") return Number(env.RETRY_TIMEOUT);
|
|
80
|
+
return kind === "read" ? TIMEOUT_SECONDS : 0;
|
|
81
|
+
}
|
|
52
82
|
|
|
53
83
|
// For a read whose command asks for JSON (--json) and prints it as it is (no --jq, -q, --template, -t): the parse error of what it printed,
|
|
54
84
|
// or null when it is whole JSON or the command does not ask for JSON
|
|
@@ -84,6 +114,9 @@ export function retryMove({ kind, text, round, rounds = ROUNDS, argv = [], also
|
|
|
84
114
|
let reason = transientOf(text);
|
|
85
115
|
if (reason === null && kind === "merge" && new RegExp(BASE_MODIFIED, "i").test(String(text ?? ""))) reason = BASE_MODIFIED;
|
|
86
116
|
if (reason === null && kind === "read" && String(text ?? "").includes(INCOMPLETE_JSON)) reason = INCOMPLETE_JSON;
|
|
117
|
+
if (reason === null && kind === "read" && String(text ?? "").includes(GH_JSON_END)) reason = GH_JSON_END;
|
|
118
|
+
if (reason === null && kind === "read") reason = GRAPHQL_TRANSIENT.find((g) => String(text ?? "").includes(g)) ?? null;
|
|
119
|
+
if (reason === null && kind === "read" && String(text ?? "").includes(COMMAND_TIMEOUT)) reason = COMMAND_TIMEOUT;
|
|
87
120
|
if (reason === null && kind === "read" && also) reason = also(String(text ?? "")) ?? null;
|
|
88
121
|
if (reason === null) return { move: "stop", reason: null, why: "not-transient" };
|
|
89
122
|
if (kind === "push" && rewritesRemote(argv)) return { move: "stop", reason, why: "force" };
|
|
@@ -173,8 +206,14 @@ export async function main(args, { env = process.env, out = process.stdout, err
|
|
|
173
206
|
return 2;
|
|
174
207
|
}
|
|
175
208
|
const seconds = Number(env.RETRY_SLEEP ?? SLEEP_SECONDS);
|
|
209
|
+
const limit = attemptTimeoutOf(kind, env);
|
|
176
210
|
const attempt = async () => {
|
|
177
|
-
const r = spawnSync(cmd[0], cmd.slice(1), { encoding: "utf8", stdio: ["inherit", "pipe", "pipe"], maxBuffer: 256 * 1024 * 1024, env });
|
|
211
|
+
const r = spawnSync(cmd[0], cmd.slice(1), { encoding: "utf8", stdio: ["inherit", "pipe", "pipe"], maxBuffer: 256 * 1024 * 1024, env, ...(limit > 0 ? { timeout: limit * 1000, killSignal: "SIGKILL" } : {}) });
|
|
212
|
+
if (r.error?.code === "ETIMEDOUT") {
|
|
213
|
+
const stderr = `${r.stderr ?? ""}${cmd[0]} 超過 ${limit} 秒沒有結束,已終止\n${COMMAND_TIMEOUT}\n`;
|
|
214
|
+
err.write(`${cmd[0]} 超過 ${limit} 秒沒有結束,已終止\n`);
|
|
215
|
+
throw new CommandFailed({ status: 124, stderr });
|
|
216
|
+
}
|
|
178
217
|
if (r.error) throw new CommandFailed({ status: 127, stderr: `${cmd[0]}: ${r.error.message}\n` });
|
|
179
218
|
const cut = kind === "read" && r.status === 0 ? jsonProblem(cmd, r.stdout ?? "") : null;
|
|
180
219
|
if (cut !== null) {
|
|
@@ -190,6 +229,7 @@ export async function main(args, { env = process.env, out = process.stdout, err
|
|
|
190
229
|
try {
|
|
191
230
|
await retryTransient({
|
|
192
231
|
kind, attempt, argv: cmd,
|
|
232
|
+
also: kind === "read" && env.RETRY_FRESH_TOKEN === "1" ? (text) => (FRESH_NOT_FOUND.test(text) ? FRESH_NOT_FOUND_REASON : null) : null,
|
|
193
233
|
pause: async (round, reason) => {
|
|
194
234
|
err.write(`! 第 ${round} 次失敗(${reason}),${seconds} 秒後重試\n`);
|
|
195
235
|
await sleep(seconds);
|
|
@@ -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"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "`ops/targets.json` 的格式,組織層與產品層共用。`hosts` 宣告位置與它的能力,`instances` 宣告實例。實例的位置二選一:自己寫 `host`(放在母叢集或租戶裡時加 `cluster`),或用 `ref` 指向別的倉宣告的實例。`host` 指向別的倉宣告的位置時加 `<RepoName>:`
|
|
2
|
+
"description": "`ops/targets.json` 的格式,組織層與產品層共用。`hosts` 宣告位置與它的能力,`instances` 宣告實例。實例的位置二選一:自己寫 `host`(放在母叢集或租戶裡時加 `cluster`),或用 `ref` 指向別的倉宣告的實例。`host` 指向別的倉宣告的位置時加 `<RepoName>:` 前綴。這份 schema 驗證鍵的格式、`host` 與 `ref` 二選一、`provider` 是 `orbstack` 時只能有一個母叢集。三項由程式檢查:`ref` 指到的實例 `kind` 相同、`host` 與 `cluster` 指到的位置與母叢集存在、帶環境後綴的上層裡實例環境相同。",
|
|
3
3
|
"type": "object",
|
|
4
4
|
"additionalProperties": false,
|
|
5
5
|
"properties": {
|
|
@@ -99,31 +99,9 @@
|
|
|
99
99
|
"pattern": "^(hosts|clusters)/"
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
"$ref": "#/$defs/instance"
|
|
107
|
-
}
|
|
108
|
-
],
|
|
109
|
-
"required": [
|
|
110
|
-
"serves"
|
|
111
|
-
]
|
|
112
|
-
},
|
|
113
|
-
"^[a-z0-9][a-z0-9-]*/(dev|stg|prod)$": {
|
|
114
|
-
"allOf": [
|
|
115
|
-
{
|
|
116
|
-
"$ref": "#/$defs/instance"
|
|
117
|
-
}
|
|
118
|
-
],
|
|
119
|
-
"not": {
|
|
120
|
-
"required": [
|
|
121
|
-
"serves"
|
|
122
|
-
]
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
"additionalProperties": false
|
|
102
|
+
"additionalProperties": {
|
|
103
|
+
"$ref": "#/$defs/instance"
|
|
104
|
+
}
|
|
127
105
|
}
|
|
128
106
|
},
|
|
129
107
|
"$defs": {
|
|
@@ -158,19 +136,6 @@
|
|
|
158
136
|
"type": "string",
|
|
159
137
|
"pattern": "^[A-Za-z0-9_.-]+:[a-z0-9][a-z0-9-]*/(dev|stg|prod|shared)$",
|
|
160
138
|
"description": "別的倉宣告的實例 `<RepoName>:<用途>/<環境>`"
|
|
161
|
-
},
|
|
162
|
-
"serves": {
|
|
163
|
-
"type": "array",
|
|
164
|
-
"minItems": 1,
|
|
165
|
-
"uniqueItems": true,
|
|
166
|
-
"items": {
|
|
167
|
-
"enum": [
|
|
168
|
-
"dev",
|
|
169
|
-
"stg",
|
|
170
|
-
"prod"
|
|
171
|
-
]
|
|
172
|
-
},
|
|
173
|
-
"description": "`shared` 實例服務的環境"
|
|
174
139
|
}
|
|
175
140
|
},
|
|
176
141
|
"oneOf": [
|
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"
|
|
@@ -141,6 +141,7 @@ jobs:
|
|
|
141
141
|
gh workflow run deploy-prerelease.yml --ref "$tag" -f tag="$tag"
|
|
142
142
|
done
|
|
143
143
|
|
|
144
|
+
# @if publish
|
|
144
145
|
# packages/*、libs/*、facts 與 docs 匯總套件 → 每個階段都發布(publish.yml)。哪些路徑真的是要發布的單元,
|
|
145
146
|
# 由 publish.yml 的 plan job 判斷(libs/* 有的不發布)。alpha、beta、rc 掛在階段名的 npm dist-tag,GA 才進
|
|
146
147
|
# latest,所以使用者要明確指定才會裝到預發布版。同一條發布線的單元可以停在不同階段(docs/versioning.md),
|
|
@@ -152,6 +153,7 @@ jobs:
|
|
|
152
153
|
GH_TOKEN: ${{ github.token }}
|
|
153
154
|
PATHS: ${{ steps.rp.outputs.paths_released }}
|
|
154
155
|
run: bash scripts/release/dispatch-publish.sh
|
|
156
|
+
# @end
|
|
155
157
|
|
|
156
158
|
# 釘版:這次 run 建立或更新了 Release PR(prs_created 在建立與只更新時都是 'true',沒有變動時是 'false'),而且沒有建 tag。
|
|
157
159
|
# 釘版中途失敗後重跑同一個 job 時,release-please 沒有東西可更新,prs_created 是 'false',所以 run_attempt 大於 1
|
|
@@ -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
|
|
@@ -8,15 +8,34 @@
|
|
|
8
8
|
# 好幾個迴圈,每個各自有這個上限。
|
|
9
9
|
POLL_TRIES="${POLL_TRIES:-180}" POLL_SLEEP="${POLL_SLEEP:-3}"
|
|
10
10
|
|
|
11
|
-
#
|
|
11
|
+
# gh_read <gh args...>: a read of gh through retry.mjs (a transient error is asked again). Sets GH_READ_OUT (stdout) and GH_READ_ERR
|
|
12
|
+
# (stderr), returns the status. Call it in the shell itself, not in $(...), to keep the variables. A caller that gets a non-zero status
|
|
13
|
+
# must stop: a failed read is not "nothing there".
|
|
14
|
+
gh_read() {
|
|
15
|
+
local errf status=0
|
|
16
|
+
errf="$(mktemp)"
|
|
17
|
+
GH_READ_OUT="$(read_retry gh "$@" 2>"$errf")" || status=$?
|
|
18
|
+
GH_READ_ERR="$(cat "$errf")"
|
|
19
|
+
rm -f "$errf"
|
|
20
|
+
return "$status"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# wait_release_pr <base-branch> → prints PR number. Returns 1 when none appeared in time, and 2 when gh could not be read
|
|
24
|
+
# (it then prints the reason instead of a number).
|
|
12
25
|
# Identify the Release PR by its head branch, not by the "autorelease: pending" label: release-please
|
|
13
26
|
# opens the PR first and labels it afterwards, so a run that fails in between leaves a real, usable
|
|
14
27
|
# Release PR with no label at all (observed 2026-09-07).
|
|
15
28
|
wait_release_pr() {
|
|
16
29
|
local base="$1" n="" i
|
|
17
30
|
for ((i=1; i<=POLL_TRIES; i++)); do
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
gh_read pr list --base "$base" --head "release-please--branches--$base" --state open --json number --jq '.[0].number // empty' \
|
|
32
|
+
|| { printf '%s\n' "讀不到 ${base} 的 Release PR(gh pr list 失敗):${GH_READ_ERR}"; return 2; }
|
|
33
|
+
n="$GH_READ_OUT"
|
|
34
|
+
if [[ -z "$n" ]]; then
|
|
35
|
+
gh_read pr list --base "$base" --label 'autorelease: pending' --state open --json number --jq '.[0].number // empty' \
|
|
36
|
+
|| { printf '%s\n' "讀不到 ${base} 的 Release PR(gh pr list 失敗):${GH_READ_ERR}"; return 2; }
|
|
37
|
+
n="$GH_READ_OUT"
|
|
38
|
+
fi
|
|
20
39
|
[[ -n "$n" ]] && { printf '%s\n' "$n"; return 0; }
|
|
21
40
|
sleep "$POLL_SLEEP"
|
|
22
41
|
done
|
|
@@ -56,7 +75,7 @@ release_please_settled() {
|
|
|
56
75
|
local branch="$1" sha="${2:-}" runs open latest conclusion paths
|
|
57
76
|
RELEASE_PLEASE_WAITING=""
|
|
58
77
|
# a failed gh call is not "no runs": it leaves the branch unsettled and the caller asks again
|
|
59
|
-
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
|
|
60
79
|
RELEASE_PLEASE_WAITING="release-please 的 run 清單查不到(gh run list 失敗)"
|
|
61
80
|
return 1
|
|
62
81
|
fi
|
|
@@ -103,7 +122,7 @@ release_please_settled() {
|
|
|
103
122
|
wait_release_please_idle() {
|
|
104
123
|
local branch="$1" sha="${2:-}" i
|
|
105
124
|
for ((i=1; i<=POLL_TRIES; i++)); do
|
|
106
|
-
git fetch -q origin "$branch" 2>/dev/null || true
|
|
125
|
+
read_retry git fetch -q origin "$branch" 2>/dev/null || true
|
|
107
126
|
release_please_settled "$branch" "$sha" && return 0
|
|
108
127
|
sleep "$POLL_SLEEP"
|
|
109
128
|
done
|
|
@@ -114,7 +133,7 @@ wait_release_please_idle() {
|
|
|
114
133
|
# manifest as it stands on the Release PR's head branch, i.e. the content a merge would land
|
|
115
134
|
release_pr_manifest() { # release_pr_manifest <base-branch>
|
|
116
135
|
local head="release-please--branches--$1"
|
|
117
|
-
git fetch -q origin "$head" 2>/dev/null || return 1
|
|
136
|
+
read_retry git fetch -q origin "$head" 2>/dev/null || return 1
|
|
118
137
|
git show "FETCH_HEAD:$MANIFEST" 2>/dev/null
|
|
119
138
|
}
|
|
120
139
|
|
|
@@ -155,13 +174,17 @@ release_pr_settle() {
|
|
|
155
174
|
log "等待 $base 上的 release-please 執行完畢(避免合併過期的 Release PR)…"
|
|
156
175
|
wait_release_please_idle "$base" "$pushed" || die "release-please 還沒處理完 ${base},不繼續。等它處理完再重跑"
|
|
157
176
|
log "等待 release-please 在 $base 開 Release PR…"
|
|
158
|
-
|
|
177
|
+
local wait_status=0
|
|
178
|
+
n="$(wait_release_pr "$base")" || wait_status=$?
|
|
179
|
+
if (( wait_status == 2 )); then die "$n"; fi
|
|
180
|
+
if (( wait_status != 0 )); then
|
|
159
181
|
(( optional )) && { info "$base 目前沒有可發版的變更,略過"; return 1; }
|
|
160
182
|
die "逾時:$base 上沒有 Release PR(查 gh run list --workflow release-please.yml)"
|
|
161
183
|
fi
|
|
162
184
|
for ((i=1; i<=POLL_TRIES; i++)); do
|
|
163
185
|
wait_release_please_idle "$base" "$pushed" || die "release-please 還沒處理完 ${base},不繼續。等它處理完再重跑"
|
|
164
|
-
|
|
186
|
+
gh_read pr view "$n" --json headRefOid --jq .headRefOid || die "讀不到 Release PR #${n} 的 head(gh pr view 失敗):${GH_READ_ERR}"
|
|
187
|
+
sha="$GH_READ_OUT"
|
|
165
188
|
if [[ -n "$sha" && "$sha" == "$prev" ]]; then
|
|
166
189
|
(( expect_stable )) || break
|
|
167
190
|
mf="$(release_pr_manifest "$base" || true)"
|
|
@@ -172,7 +195,7 @@ release_pr_settle() {
|
|
|
172
195
|
prev="$sha"; sleep "$POLL_SLEEP"
|
|
173
196
|
done
|
|
174
197
|
RELEASE_PR_NUMBER="$n" RELEASE_PR_SHA="$sha"
|
|
175
|
-
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)"
|
|
176
199
|
}
|
|
177
200
|
|
|
178
201
|
# --- version check and pin, shared by scripts/release/merge-release-pr.sh and scripts/release/pin-release-pr.sh ---
|
|
@@ -181,7 +204,7 @@ release_pr_settle() {
|
|
|
181
204
|
# Found by its head branch, as wait_release_pr does. A failed gh call stops the script: it is not "no PR".
|
|
182
205
|
release_pr_open_number() {
|
|
183
206
|
local base="$1" out
|
|
184
|
-
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')" \
|
|
185
208
|
|| die "查不到 ${base} 的 Release PR(gh pr list 失敗)"
|
|
186
209
|
printf '%s\n' "$out"
|
|
187
210
|
}
|
|
@@ -275,8 +298,8 @@ release_pin_open_pr() {
|
|
|
275
298
|
return 0
|
|
276
299
|
fi
|
|
277
300
|
head_ref="release-please--branches--$branch"
|
|
278
|
-
git fetch -q origin "$branch" || die "git fetch origin $branch 沒成功"
|
|
279
|
-
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 沒成功"
|
|
280
303
|
pr_sha="$(git rev-parse FETCH_HEAD)"
|
|
281
304
|
if ! git merge-base --is-ancestor "origin/$branch" HEAD; then
|
|
282
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"
|
|
@@ -266,9 +266,16 @@ BODY
|
|
|
266
266
|
|
|
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
|
+
# 讀取走 read_retry(暫時性錯誤會重試)。空值只在 gh 成功、真的沒有開著的 PR 時出現(例如 PR 已被另一次 close 合併)。
|
|
271
|
+
pr_err="$(mktemp)"
|
|
272
|
+
pr="$(read_retry gh pr list --base main --head "$sync_branch" --state open --json number --jq '.[0].number // empty' 2>"$pr_err")" || {
|
|
273
|
+
pr_msg="$(cat "$pr_err")"; rm -f "$pr_err"
|
|
274
|
+
die "讀不到開著的 release PR(gh 失敗),沒有合併、打 tag 或刪分支:${pr_msg}"
|
|
275
|
+
}
|
|
276
|
+
rm -f "$pr_err"
|
|
270
277
|
if [[ -n "$pr" ]]; then
|
|
271
|
-
pr_json="$(gh pr view "$pr" --json body,headRefOid,mergeable)"
|
|
278
|
+
pr_json="$(read_retry gh pr view "$pr" --json body,headRefOid,mergeable)"
|
|
272
279
|
body="$(jq -r .body <<<"$pr_json")"
|
|
273
280
|
pr_head="$(jq -r .headRefOid <<<"$pr_json")"
|
|
274
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.
|
|
@@ -283,7 +290,7 @@ BODY
|
|
|
283
290
|
fi
|
|
284
291
|
log "以 squash 合併 release PR #${pr}(head ${pr_head:0:7}),合併訊息為 PR 標題與內文,Release-Train-Base 在最後一行"
|
|
285
292
|
external_retry merge "$target" gh pr merge "$pr" --squash --match-head-commit "${head_sha:-$pr_head}" --subject "$title (#$pr)" --body "$body"
|
|
286
|
-
|
|
293
|
+
run_read git fetch --prune --tags origin
|
|
287
294
|
fi
|
|
288
295
|
if [[ -z "$(git log origin/main --format=%H --grep="product v$product" -n 1)" ]]; then
|
|
289
296
|
(( DRY_RUN )) && [[ -n "$pr" ]] && info "[dry-run] release PR #$pr 尚未合併,以下核對僅供參考" \
|
|
@@ -311,7 +318,7 @@ Release-Train-Units: $fix_units}"
|
|
|
311
318
|
-m "Release-Train-Base: $base${fix_units_line}
|
|
312
319
|
Release-Plan: v$product")"
|
|
313
320
|
external_retry push "$target" git push origin "$fix:refs/heads/main"
|
|
314
|
-
|
|
321
|
+
run_read git fetch origin
|
|
315
322
|
else
|
|
316
323
|
info "[dry-run] 補上 Release-Train-Base: $base"
|
|
317
324
|
fi
|
|
@@ -335,7 +342,7 @@ Release-Plan: v$product")"
|
|
|
335
342
|
log "打產品 tag v$product 於發布分支的最後一個 commit ${train_tip:0:7}"
|
|
336
343
|
run git tag -a "v$product" "$train_tip" -m "product v$product"
|
|
337
344
|
fi
|
|
338
|
-
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
|
|
339
346
|
external_retry push "$target" git push origin "v$product"
|
|
340
347
|
else
|
|
341
348
|
info "v$product 已在遠端"
|
|
@@ -344,7 +351,7 @@ Release-Plan: v$product")"
|
|
|
344
351
|
# 4. 刪除發布分支與流程產生的暫時分支(不變式:兩次發布之間 0 條)。本機分支正被檢出時先切離。
|
|
345
352
|
log "刪除 release 分支與暫時分支"
|
|
346
353
|
for extra in "$branch" "release-please--branches--$branch" "$sync_branch"; do
|
|
347
|
-
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
|
|
348
355
|
external "$target" git push origin --delete "$extra"
|
|
349
356
|
fi
|
|
350
357
|
done
|
|
@@ -352,7 +359,7 @@ Release-Plan: v$product")"
|
|
|
352
359
|
for local_branch in "$branch" "$sync_branch"; do
|
|
353
360
|
git rev-parse -q --verify "refs/heads/$local_branch" >/dev/null && run git branch -D "$local_branch"
|
|
354
361
|
done
|
|
355
|
-
|
|
362
|
+
run_read git fetch --prune --tags origin
|
|
356
363
|
|
|
357
364
|
# 5. 關閉核對,全部讀遠端與 origin/main。
|
|
358
365
|
printf '\n'
|
|
@@ -360,7 +367,7 @@ Release-Plan: v$product")"
|
|
|
360
367
|
ok=1
|
|
361
368
|
n="$(release_branches | grep -c . || true)"
|
|
362
369
|
[[ "$n" == 0 ]] && info "✓ release 分支數 = 0" || { info "✗ 仍有 release 分支:$(release_branches)"; ok=0; }
|
|
363
|
-
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 ' ')"
|
|
364
371
|
[[ "$leftover" == 0 ]] && info "✓ 無殘留的 release-please 工作分支" || { info "✗ 仍有 $leftover 條 release-please 工作分支"; ok=0; }
|
|
365
372
|
if git rev-parse -q --verify "refs/tags/v$product" >/dev/null; then
|
|
366
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 = ["clientIdVariable", "licenseHolder", "mergeBotApp", "mergeBotUserId", "mergeLabel", "privateKeySecret", "scope"];
|
|
12
12
|
|
|
13
13
|
const FIELD = /@@(\w+)@@/g;
|
|
14
14
|
|