blueprint-shared-templates 0.6.2 → 0.8.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/scripts/lib/retry.mjs +31 -12
- package/base/scripts/merge/decide.mjs +7 -4
- package/deploy/scripts/deploy/route-tag.sh +4 -0
- package/ops/.github/workflows/ops-deploy.yml +0 -2
- package/ops/scripts/deploy/apply-ops.sh +6 -2
- package/package.json +2 -8
- package/publish/.github/workflows/publish.yml +114 -5
- package/publish/scripts/release/binary-units.sh +272 -0
- package/publish/scripts/release/image-units.sh +171 -0
- package/publish/scripts/release/publish-units.sh +90 -21
- package/release/.github/workflows/release-please.yml +2 -1
- package/release/schemas/release-policy.schema.json +50 -0
- package/release/scripts/ci/check-release-policy.sh +28 -3
- package/release/scripts/lib/release-stages.sh +16 -0
- package/release/scripts/release/dispatch-publish.sh +12 -2
- package/facts-describes.ts +0 -53
- package/facts-skeleton.mjs +0 -84
- package/transform.mjs +0 -63
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The one place that asks again after a transient error of GitHub (decision transient-error-shared-retry).
|
|
2
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
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
|
|
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
|
+
// connection that could not be made at all (gh's `error connecting to <host>`, git's `Could not resolve host` and `Couldn't connect to server`) and a break of the connection itself:
|
|
5
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`).
|
|
6
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
|
|
7
7
|
// heredoc marker, EOFError) do not get better by asking again.
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
// that ran past its timeout (`Command Timeout`), in the CLI with RETRY_FRESH_TOKEN=1 a repository that is not found
|
|
17
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
18
|
// what the caller adds through `also` (local.mjs adds the HTTP 404 of a run that was just dispatched), and
|
|
19
|
-
// in the CLI an answer of a command with --json
|
|
20
|
-
// an answer short now and then, and asking again gets the whole of it
|
|
19
|
+
// in the CLI an answer that exits 0 but is not whole JSON, of a command with --json or of a `gh api` that prints the body as it
|
|
20
|
+
// is (both with no --jq or --template; jsonProblem): gh has cut such an answer short now and then, and asking again gets the whole of it
|
|
21
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,
|
|
22
22
|
// :ref, --mirror, --prune): the retry of a write that rewrites or removes history is a decision, not a reflex
|
|
23
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)
|
|
@@ -50,8 +50,9 @@ export function transientOf(text) {
|
|
|
50
50
|
// `dial tcp <addr>: i/o timeout`; only the text after `connect:` or `dial tcp ...:` counts, not any text that says timed out
|
|
51
51
|
if (/Connect Timeout|connect: (?:connection|operation) timed out|Connection timed out|\bdial tcp [^\n]*:\s*i\/o timeout\b/i.test(s)) return "Connect Timeout";
|
|
52
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
|
|
53
|
-
// `Could not resolve host: github.com
|
|
54
|
-
|
|
53
|
+
// `Could not resolve host: github.com`, and for a connect that failed without a timeout in the text (curl error 7)
|
|
54
|
+
// `Failed to connect to github.com port 443 after 136308 ms: Couldn't connect to server`
|
|
55
|
+
if (/\berror connecting to [\w-]+(?:\.[\w-]+)+|Could not resolve host:|Couldn't connect to server/i.test(s)) return "Connect Failure";
|
|
55
56
|
// 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
57
|
// `can't assign requested address`, Linux `cannot assign requested address`), no network and no route
|
|
57
58
|
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";
|
|
@@ -80,11 +81,27 @@ export function attemptTimeoutOf(kind, env = {}) {
|
|
|
80
81
|
return kind === "read" ? TIMEOUT_SECONDS : 0;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
//
|
|
84
|
-
//
|
|
84
|
+
// Whether a `gh api` command line prints the JSON body of GitHub as it is: no --include, --silent or --verbose (other text around the
|
|
85
|
+
// body), no --paginate without --slurp (one JSON document per page), and no Accept header other than JSON (a raw file, a diff or a patch).
|
|
86
|
+
// argv may start with `gh` or with `api`.
|
|
87
|
+
export function ghApiPrintsJson(argv = []) {
|
|
88
|
+
if (argv[argv[0] === "gh" ? 1 : 0] !== "api") return false;
|
|
89
|
+
if (argv.some((a) => /^(?:-i|--include|--silent|--verbose)$/.test(a))) return false;
|
|
90
|
+
if (argv.includes("--paginate") && !argv.includes("--slurp")) return false;
|
|
91
|
+
const headers = argv.flatMap((a, i) => (a === "-H" || a === "--header" ? [argv[i + 1] ?? ""] : a.startsWith("--header=") ? [a.slice(9)] : []));
|
|
92
|
+
return headers.every((h) => !/^\s*accept\s*:/i.test(h) || /^\s*accept\s*:\s*application\/(?:vnd\.github(?:\.v3)?\+)?json\s*$/i.test(h));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// For a read that prints the JSON it was given as it is (no --jq, -q, --template, -t): the parse error of what it printed, or null when it
|
|
96
|
+
// is whole JSON or the command does not print JSON. Two kinds of command print JSON: one that asks for it (--json), whose empty answer
|
|
97
|
+
// is cut too, and `gh api` (ghApiPrintsJson), whose empty answer is a body GitHub did not send (HTTP 204) and so is whole. gh has cut an
|
|
98
|
+
// answer of the first kind short now and then, and `gh api` has exited 0 with a text of a proxy (`upstream connect error ...`) or a body
|
|
99
|
+
// followed by more text; asking again gets the whole of it.
|
|
85
100
|
export function jsonProblem(argv = [], stdout = "") {
|
|
86
|
-
if (!argv.some((a) => a === "--json" || a.startsWith("--json="))) return null;
|
|
87
101
|
if (argv.some((a) => /^(?:--jq|-q|--template|-t)(?:=.*)?$/.test(a))) return null;
|
|
102
|
+
const asksJson = argv.some((a) => a === "--json" || a.startsWith("--json="));
|
|
103
|
+
if (!asksJson && !ghApiPrintsJson(argv)) return null;
|
|
104
|
+
if (!asksJson && String(stdout).trim() === "") return null;
|
|
88
105
|
try { JSON.parse(stdout); return null; } catch (e) { return e.message; }
|
|
89
106
|
}
|
|
90
107
|
|
|
@@ -196,9 +213,10 @@ class CommandFailed extends Error {
|
|
|
196
213
|
}
|
|
197
214
|
}
|
|
198
215
|
|
|
199
|
-
// Runs the command
|
|
200
|
-
//
|
|
201
|
-
// caller never gets
|
|
216
|
+
// Runs the command and asks again after a failure the kind retries. The exit status is the status of the last run. stderr of every run
|
|
217
|
+
// is printed as it comes; stdout is printed once, of the last run: a run that failed and was asked again prints nothing on stdout, so
|
|
218
|
+
// the caller never gets the body of an error (`gh api` prints the body of an HTTP 5xx on stdout) or a cut answer in front of the whole
|
|
219
|
+
// one. A read whose JSON is not whole is a failure with status 1 whose stdout is not passed on even when it is the last run. `sleep` is how the CLI waits (seconds); the default really waits.
|
|
202
220
|
export async function main(args, { env = process.env, out = process.stdout, err = process.stderr, sleep = (s) => new Promise((r) => setTimeout(r, s * 1000)) } = {}) {
|
|
203
221
|
const [kind, sep, ...cmd] = args;
|
|
204
222
|
if (!CLI_KINDS.includes(kind) || sep !== "--" || cmd.length === 0) {
|
|
@@ -221,9 +239,9 @@ export async function main(args, { env = process.env, out = process.stdout, err
|
|
|
221
239
|
err.write(stderr);
|
|
222
240
|
throw new CommandFailed({ status: 1, stderr });
|
|
223
241
|
}
|
|
224
|
-
out.write(r.stdout ?? "");
|
|
225
242
|
err.write(r.stderr ?? "");
|
|
226
243
|
if (r.status !== 0) throw new CommandFailed(r);
|
|
244
|
+
out.write(r.stdout ?? "");
|
|
227
245
|
return r;
|
|
228
246
|
};
|
|
229
247
|
try {
|
|
@@ -238,6 +256,7 @@ export async function main(args, { env = process.env, out = process.stdout, err
|
|
|
238
256
|
return 0;
|
|
239
257
|
} catch (e) {
|
|
240
258
|
const failed = e instanceof RetryExhausted ? e.cause : e;
|
|
259
|
+
out.write(failed?.stdout ?? "");
|
|
241
260
|
if (e instanceof RetryExhausted) err.write(`✗ 重試 ${e.tries} 次仍失敗,最後的理由:${e.reason}\n`);
|
|
242
261
|
return failed?.status ?? 1;
|
|
243
262
|
}
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
// from blueprint-shared.merge.required-checks. pathFiltered maps a check name to the path globs of the workflow that
|
|
14
14
|
// has a path filter: when none of the changed files matches, that workflow did not run and the check
|
|
15
15
|
// counts as skipped. reviewPaths are the CODEOWNERS style paths (blueprint-shared.git-flow.review-paths) that need
|
|
16
|
-
// a review; empty or missing means no pull request needs one here. syncPr is { author, branch }:
|
|
17
|
-
//
|
|
16
|
+
// a review; empty or missing means no pull request needs one here. syncPr is { author, branch }: a kind of pull
|
|
17
|
+
// request the repository declares itself (its author is a named App and its head branch has a given name), which
|
|
18
|
+
// needs no review; a repository that declares none has no such pull request (blueprint-shared.templates.auto-merge,
|
|
19
|
+
// configFrom and reviewGate).
|
|
18
20
|
// pr also needs author ({ login, is_bot }) and latestReviews ([{ state }]) from `gh pr view --json`.
|
|
19
21
|
// Output: one JSON line { action, reason, ... }. action is "merge", "merge-release-pr" or "skip". A skip because a
|
|
20
22
|
// required check failed also lists those checks in failed.
|
|
@@ -96,8 +98,9 @@ export function decide({ pr, checkedSha, checks = [], changedFiles = [] }, confi
|
|
|
96
98
|
if (missing.length > 0) return skip(`required check has not run: ${missing.join(", ")}`, { pr: number });
|
|
97
99
|
|
|
98
100
|
const release = pr.headRefName.startsWith(RELEASE_PR_HEAD);
|
|
99
|
-
// A change to a review path needs an approving review, except a
|
|
100
|
-
// and a Release PR, which merge-release-pr.sh merges on a machine.
|
|
101
|
+
// A change to a review path (blueprint-shared.git-flow.review-paths) needs an approving review, except a pull request that matches
|
|
102
|
+
// config.syncPr and a Release PR, which merge-release-pr.sh merges on a machine (blueprint-shared.templates.auto-merge, reviewGate).
|
|
103
|
+
// The required checks above still have to pass for all of them.
|
|
101
104
|
if (!release && !isSyncPr(pr, config.syncPr) && touchesReviewPath(changedFiles, config.reviewPaths)) {
|
|
102
105
|
const states = (pr.latestReviews ?? []).map((r) => r.state);
|
|
103
106
|
if (states.includes("CHANGES_REQUESTED")) return skip("a review asks for changes on a pull request that changes a review path", { pr: number });
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
# wrangler.toml holds no environment (the settings of each environment live in ops)
|
|
11
11
|
# - anything else (package, sdk, mobile, desktop): nothing to deploy here. Packages are published by
|
|
12
12
|
# publish.yml, and native apps are not part of the first version (decision native-apps-not-in-first-version)
|
|
13
|
+
# A unit whose publish.to in the policy file is image publishes a container image and is skipped here, whatever its kind.
|
|
13
14
|
# The directory of the unit tells whether it is built here, because the policy kind alone does not: an InfraName unit is kind
|
|
14
15
|
# backend too. A unit under apps/ or services/ is kind=service (the deploy role builds it). A unit under infra/ only publishes an
|
|
15
16
|
# interface, and the cloud resources are created by the iac steps of ops (decision ops-declares-cloud-resources), so it is skipped.
|
|
@@ -42,6 +43,9 @@ if ! is_stage "$stage" || [[ "$stage" == ga ]]; then
|
|
|
42
43
|
skip_with "版號 $version 的預發布階段「${stage}」不是 ${RELEASE_STAGES[*]:0:3} 之一"
|
|
43
44
|
fi
|
|
44
45
|
policy_unit_exists "$unit" || skip_with "$unit 不在政策檔($(basename "$(policy_file)"))的 units 裡,不是發布單元"
|
|
46
|
+
# a unit that publishes a container image (publish.to image) is not deployed by its tag: publish.yml pushes the image, and
|
|
47
|
+
# the deployment mounts the configuration and pulls it
|
|
48
|
+
[[ "$(policy_unit_publish_to "$unit")" != image ]] || skip_with "$unit 發布容器映像(政策檔的 publish.to 是 image),不經 tag 部署,映像由 publish.yml 推到 ghcr"
|
|
45
49
|
|
|
46
50
|
case "$(policy_unit_kind "$unit")" in
|
|
47
51
|
service|backend|web)
|
|
@@ -61,7 +61,6 @@ env:
|
|
|
61
61
|
|
|
62
62
|
jobs:
|
|
63
63
|
iac:
|
|
64
|
-
if: vars.DEPLOY_ENABLED == 'true'
|
|
65
64
|
# 例外(特殊原因):tofu apply 要在每次都是空的 GitHub-hosted runner 上跑,和 Workers 的 self-hosted job 分開權限,用另一把 R2 token
|
|
66
65
|
runs-on: ubuntu-latest
|
|
67
66
|
timeout-minutes: 20
|
|
@@ -126,7 +125,6 @@ jobs:
|
|
|
126
125
|
|
|
127
126
|
workloads:
|
|
128
127
|
needs: iac
|
|
129
|
-
if: vars.DEPLOY_ENABLED == 'true'
|
|
130
128
|
runs-on: self-hosted-linux
|
|
131
129
|
timeout-minutes: 20
|
|
132
130
|
steps:
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
# Put what ops/versions.json declares for an environment online. Per declared unit: download its bundle from the
|
|
3
3
|
# GitHub Release that ops/versions.lock.json names, check the bundle hash against the lock, join the settings of the
|
|
4
4
|
# environment (ops/workloads/<purpose>/<env>/<unit>/wrangler.toml) to the wrangler.toml of the bundle, `wrangler versions upload`,
|
|
5
|
-
# then `wrangler versions deploy <id>@100
|
|
6
|
-
# hash of the joined settings is skipped, so a rerun
|
|
5
|
+
# then `wrangler versions deploy <id>@100` and `wrangler triggers deploy` (the routes, custom domains and workers_dev of the settings).
|
|
6
|
+
# A unit whose /healthz already reports the declared version, the bundle hash and the hash of the joined settings is skipped, so a rerun
|
|
7
|
+
# changes nothing.
|
|
7
8
|
#
|
|
8
9
|
# Each environment is a separate Worker (<unit>-<env>), and a version id belongs to one Worker, so an
|
|
9
10
|
# environment never reuses the id of another: what carries over is the bundle, and the hash tells it is the same.
|
|
@@ -146,6 +147,9 @@ for step in "${steps[@]:-}"; do
|
|
|
146
147
|
id="$(jq -r 'select(.type == "version-upload") | .version_id' "$out" 2>/dev/null | tail -1)"
|
|
147
148
|
[[ -n "$id" ]] || { printf '%s\n' >&2 "✗ ${unit}:wrangler 的輸出檔沒有 version-upload 的 version_id"; exit 1; }
|
|
148
149
|
(cd "$dir/bundle" && "${wrangler[@]}" versions deploy "$id@100" --env "$env_name" --yes --message "$unit $version")
|
|
150
|
+
# `wrangler versions deploy` moves traffic to the version only. It does not apply routes, custom domains or workers_dev of the
|
|
151
|
+
# settings, which `wrangler deploy` would; `wrangler triggers deploy` does, and it changes nothing when they are in place.
|
|
152
|
+
(cd "$dir/bundle" && "${wrangler[@]}" triggers deploy --env "$env_name")
|
|
149
153
|
n=$(( n + 1 ))
|
|
150
154
|
printf '%s\n' "$(date -u '+%Y-%m-%d %H:%M') | $env_name | $unit | $version | apply | $id | sha256:$sha | config:${cfg:0:12}" >> "$log_dir/$env_name.log"
|
|
151
155
|
printf '%s\n' " [$n] $worker ← ${version}(版本 ${id},雜湊 ${sha:0:12}…,設定 ${cfg:0:12}…)"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blueprint-shared-templates",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "A public reference implementation and specification of the shared templates, pinnable and readable, not a source to fetch files from",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Carlos Space",
|
|
7
7
|
"type": "module",
|
|
@@ -15,9 +15,6 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"LICENSE",
|
|
18
|
-
"transform.mjs",
|
|
19
|
-
"facts-skeleton.mjs",
|
|
20
|
-
"facts-describes.ts",
|
|
21
18
|
"base",
|
|
22
19
|
"deploy",
|
|
23
20
|
"hub",
|
|
@@ -28,9 +25,6 @@
|
|
|
28
25
|
"verify"
|
|
29
26
|
],
|
|
30
27
|
"exports": {
|
|
31
|
-
"./transform.mjs": "./transform.mjs",
|
|
32
|
-
"./facts-skeleton.mjs": "./facts-skeleton.mjs",
|
|
33
|
-
"./facts-describes.ts": "./facts-describes.ts",
|
|
34
28
|
"./package.json": "./package.json"
|
|
35
29
|
}
|
|
36
30
|
}
|
|
@@ -4,8 +4,10 @@ name: publish
|
|
|
4
4
|
# npm、PyPI、crates.io Trusted Publishing(OIDC),不讀任何 registry token
|
|
5
5
|
# GitHub Packages 私有套件,用 GITHUB_TOKEN
|
|
6
6
|
# Go、Swift 沒有 registry,mirror job 推到公開鏡像倉並打 tag
|
|
7
|
+
# 執行檔 政策檔 publish.to 是 binary 的單元,binary job 交叉編譯後發到公開發布倉的 GitHub release,GA 才更新 Homebrew formula
|
|
8
|
+
# 容器映像 政策檔 publish.to 是 image 的單元,image job 推到 ghcr,digest 附在來源倉單元 tag 的 Release
|
|
7
9
|
# npm 以階段名作 dist-tag,GA 才是 latest;PyPI 用 PEP 440 版號,crates.io 用 SemVer,兩者的預發布版預設都不會被安裝。
|
|
8
|
-
# 判斷集中在 scripts/release/publish-units.sh 與
|
|
10
|
+
# 判斷集中在 scripts/release/publish-units.sh、mirror-units.sh、binary-units.sh 與 image-units.sh。版號不屬於派送的階段時,
|
|
9
11
|
# plan job 在任何 registry 被寫入前就停下。
|
|
10
12
|
#
|
|
11
13
|
# 這是閉源倉庫以 Trusted Publishing 發公開套件的結構:build job 跑 self-hosted,打包 npm tgz、PyPI dist 並驗證
|
|
@@ -74,6 +76,8 @@ jobs:
|
|
|
74
76
|
tp: ${{ steps.reg.outputs.tp }}
|
|
75
77
|
mirror: ${{ steps.reg.outputs.mirror }}
|
|
76
78
|
mirrors: ${{ steps.reg.outputs.mirrors }}
|
|
79
|
+
binary: ${{ steps.reg.outputs.binary }}
|
|
80
|
+
image: ${{ steps.reg.outputs.image }}
|
|
77
81
|
steps:
|
|
78
82
|
- uses: actions/checkout@v7
|
|
79
83
|
with:
|
|
@@ -108,7 +112,7 @@ jobs:
|
|
|
108
112
|
# 建置 job:打包與驗證都在這裡,沒有 id-token,也不碰任何 registry 的憑證。
|
|
109
113
|
build:
|
|
110
114
|
needs: plan
|
|
111
|
-
if: needs.plan.outputs.tp == 'true'
|
|
115
|
+
if: needs.plan.outputs.tp == 'true'
|
|
112
116
|
runs-on: self-hosted-linux
|
|
113
117
|
timeout-minutes: 30
|
|
114
118
|
permissions:
|
|
@@ -149,7 +153,7 @@ jobs:
|
|
|
149
153
|
# 獨立發布 job:只下載 build job 的產物並上傳,不再建置。
|
|
150
154
|
publish:
|
|
151
155
|
needs: [plan, build]
|
|
152
|
-
if: needs.plan.outputs.tp == 'true'
|
|
156
|
+
if: needs.plan.outputs.tp == 'true'
|
|
153
157
|
# 獨立發布 job:讓建置不佔用託管 runner 時數;Trusted Publishing 只接受 GitHub 託管 runner 簽發的 OIDC token
|
|
154
158
|
runs-on: ubuntu-latest
|
|
155
159
|
timeout-minutes: 20
|
|
@@ -232,7 +236,7 @@ jobs:
|
|
|
232
236
|
# 前面任一個 job 失敗或被取消就不上傳。
|
|
233
237
|
publish-github-packages:
|
|
234
238
|
needs: [plan, build, publish]
|
|
235
|
-
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && needs.plan.outputs.github-packages == 'true'
|
|
239
|
+
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && needs.plan.outputs.github-packages == 'true'
|
|
236
240
|
runs-on: self-hosted-linux
|
|
237
241
|
timeout-minutes: 20
|
|
238
242
|
permissions:
|
|
@@ -265,7 +269,7 @@ jobs:
|
|
|
265
269
|
# 範圍只有這些鏡像倉的 contents: write。App 的名稱由 compose 依 fact 寫入。dry_run 不需要權杖。
|
|
266
270
|
mirror:
|
|
267
271
|
needs: plan
|
|
268
|
-
if: needs.plan.outputs.mirror == 'true'
|
|
272
|
+
if: needs.plan.outputs.mirror == 'true'
|
|
269
273
|
runs-on: self-hosted-linux
|
|
270
274
|
timeout-minutes: 10
|
|
271
275
|
permissions:
|
|
@@ -306,3 +310,108 @@ jobs:
|
|
|
306
310
|
echo "::error::no GitHub App token, so nothing can be pushed to the mirror repositories"; exit 1
|
|
307
311
|
fi
|
|
308
312
|
bash scripts/release/mirror-units.sh ${flags[@]+"${flags[@]}"} "${paths[@]}"
|
|
313
|
+
|
|
314
|
+
# 政策檔 publish.to 是 binary 的單元:依政策檔的平台交叉編譯,連同 checksum 發到公開發布倉的 GitHub release,GA 才更新
|
|
315
|
+
# Homebrew formula(binary-units.sh)。跑預設 label 的 self-hosted runner,用 setup-go 裝 go.mod 指定的版本。
|
|
316
|
+
# 寫發布倉用 GitHub App 的權杖,範圍只有發布倉的 contents: write。發布倉名稱是組織值 binaryReleaseRepository,只寫倉庫名,
|
|
317
|
+
# owner 和這個倉相同;組織沒填這個值時,第一步就停下並寫原因,不讓空的 repositories 把權杖開到整個組織。
|
|
318
|
+
# 一次一個寫入者,兩次發版不會搶同一個 formula。dry_run 不需要權杖。
|
|
319
|
+
binary:
|
|
320
|
+
needs: plan
|
|
321
|
+
if: needs.plan.outputs.binary == 'true'
|
|
322
|
+
runs-on: self-hosted-linux
|
|
323
|
+
timeout-minutes: 30
|
|
324
|
+
permissions:
|
|
325
|
+
contents: read
|
|
326
|
+
concurrency:
|
|
327
|
+
group: binary
|
|
328
|
+
cancel-in-progress: false
|
|
329
|
+
steps:
|
|
330
|
+
# 要 tag:binary-units.sh 讀單元 tag 的 commit。
|
|
331
|
+
- uses: actions/checkout@v7
|
|
332
|
+
with:
|
|
333
|
+
fetch-depth: 0
|
|
334
|
+
fetch-tags: true
|
|
335
|
+
persist-credentials: false
|
|
336
|
+
- id: release-repo
|
|
337
|
+
env:
|
|
338
|
+
BINARY_RELEASE_REPOSITORY: "@@binaryReleaseRepository@@"
|
|
339
|
+
PATHS: ${{ needs.plan.outputs.paths }}
|
|
340
|
+
run: |
|
|
341
|
+
if [[ -z "$BINARY_RELEASE_REPOSITORY" ]]; then
|
|
342
|
+
echo "::error::the organization gives no binaryReleaseRepository, so there is no repository to release the executables to"
|
|
343
|
+
exit 1
|
|
344
|
+
fi
|
|
345
|
+
mapfile -t paths < <(jq -r '.[]' <<<"$PATHS")
|
|
346
|
+
file=""
|
|
347
|
+
for p in "${paths[@]}"; do
|
|
348
|
+
if [[ "$(bash scripts/release/publish-units.sh --report "$p")" == "unit $p -> binary" ]]; then file="$p/go.mod"; break; fi
|
|
349
|
+
done
|
|
350
|
+
echo "go-mod=$file" >> "$GITHUB_OUTPUT"
|
|
351
|
+
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
|
352
|
+
with:
|
|
353
|
+
go-version-file: ${{ steps.release-repo.outputs.go-mod }}
|
|
354
|
+
cache: false
|
|
355
|
+
- id: app-token
|
|
356
|
+
if: ${{ !inputs.dry_run }}
|
|
357
|
+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
|
358
|
+
with:
|
|
359
|
+
client-id: ${{ vars.@@clientIdVariable@@ }}
|
|
360
|
+
private-key: ${{ secrets.@@privateKeySecret@@ }}
|
|
361
|
+
owner: ${{ github.repository_owner }}
|
|
362
|
+
repositories: "@@binaryReleaseRepository@@"
|
|
363
|
+
permission-contents: write
|
|
364
|
+
- name: 發布執行檔
|
|
365
|
+
env:
|
|
366
|
+
PATHS: ${{ needs.plan.outputs.paths }}
|
|
367
|
+
BINARY_RELEASE_TOKEN: ${{ steps.app-token.outputs.token }}
|
|
368
|
+
BINARY_RELEASE_REPOSITORY: "@@binaryReleaseRepository@@"
|
|
369
|
+
BINARY_RELEASE_OWNER: ${{ github.repository_owner }}
|
|
370
|
+
BINARY_OUT: ${{ runner.temp }}/binary
|
|
371
|
+
DRY_RUN: ${{ inputs.dry_run && '1' || '0' }}
|
|
372
|
+
run: |
|
|
373
|
+
mapfile -t paths < <(jq -r '.[]' <<<"$PATHS")
|
|
374
|
+
flags=()
|
|
375
|
+
if [[ "$DRY_RUN" == 1 ]]; then flags=(--dry-run)
|
|
376
|
+
elif [[ -z "$BINARY_RELEASE_TOKEN" ]]; then
|
|
377
|
+
echo "::error::no GitHub App token, so nothing can be released to the release repository"; exit 1
|
|
378
|
+
fi
|
|
379
|
+
bash scripts/release/binary-units.sh ${flags[@]+"${flags[@]}"} "${paths[@]}"
|
|
380
|
+
|
|
381
|
+
# 政策檔 publish.to 是 image 的單元:用單元目錄的 Dockerfile 依政策檔平台建置,推到 ghcr.io/<owner>/<單元名>:<版號>,
|
|
382
|
+
# 把 digest 附在來源倉單元 tag 的 Release 並印在摘要(image-units.sh)。要 docker,所以跑組織值 selfHostedRunnerLabels.docker
|
|
383
|
+
# 的 runner;組織沒填這個值時,image-units.sh 在沒有 docker 的 runner 上停下並寫原因。
|
|
384
|
+
# 推映像和附 digest 都用這個 job 的 GITHUB_TOKEN:GitHub App 沒有 packages 權限,Release 在這個倉,contents: write 就夠。
|
|
385
|
+
# DOCKER_CONFIG 放在 job 的暫存目錄,image-units.sh 結束時刪掉。套件第一次推送是私有,要公開時由人改一次,改了收不回。
|
|
386
|
+
image:
|
|
387
|
+
needs: plan
|
|
388
|
+
if: needs.plan.outputs.image == 'true'
|
|
389
|
+
runs-on: "@@dockerRunnerLabel@@"
|
|
390
|
+
timeout-minutes: 60
|
|
391
|
+
permissions:
|
|
392
|
+
contents: write
|
|
393
|
+
packages: write
|
|
394
|
+
concurrency:
|
|
395
|
+
group: image
|
|
396
|
+
cancel-in-progress: false
|
|
397
|
+
steps:
|
|
398
|
+
# 要 tag:image-units.sh 讀單元 tag 的 commit。
|
|
399
|
+
- uses: actions/checkout@v7
|
|
400
|
+
with:
|
|
401
|
+
fetch-depth: 0
|
|
402
|
+
fetch-tags: true
|
|
403
|
+
persist-credentials: false
|
|
404
|
+
- name: 推映像
|
|
405
|
+
env:
|
|
406
|
+
PATHS: ${{ needs.plan.outputs.paths }}
|
|
407
|
+
GH_TOKEN: ${{ github.token }}
|
|
408
|
+
IMAGE_TOKEN: ${{ github.token }}
|
|
409
|
+
IMAGE_ACTOR: ${{ github.actor }}
|
|
410
|
+
IMAGE_OWNER: ${{ github.repository_owner }}
|
|
411
|
+
IMAGE_OUT: ${{ runner.temp }}/image
|
|
412
|
+
DRY_RUN: ${{ inputs.dry_run && '1' || '0' }}
|
|
413
|
+
run: |
|
|
414
|
+
mapfile -t paths < <(jq -r '.[]' <<<"$PATHS")
|
|
415
|
+
flags=()
|
|
416
|
+
if [[ "$DRY_RUN" == 1 ]]; then flags=(--dry-run); fi
|
|
417
|
+
bash scripts/release/image-units.sh ${flags[@]+"${flags[@]}"} "${paths[@]}"
|