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
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
# Publish the units a release created, at every stage of a train. publish.yml calls it with the unit paths of the
|
|
3
3
|
# release and the stage; release-please.yml dispatches publish.yml after each release.
|
|
4
4
|
#
|
|
5
|
-
# The target of a unit
|
|
5
|
+
# The target of a unit comes from publish.to of the unit in release-policy.json when it has one: binary (binary-units.sh
|
|
6
|
+
# releases executables), image (image-units.sh pushes a container image) or none (not published, whatever files it has).
|
|
7
|
+
# A unit without publish.to follows from the file its directory carries:
|
|
6
8
|
# package.json npm publishConfig.registry unset or https://registry.npmjs.org. Public package,
|
|
7
9
|
# Trusted Publishing (OIDC, npm >= 11.5.1), no token is read. dist-tag is the stage
|
|
8
10
|
# (alpha | beta | rc), latest at ga: latest must only ever point at a GA. pnpm packs
|
|
@@ -20,6 +22,10 @@
|
|
|
20
22
|
# published by hand (--crate-exists).
|
|
21
23
|
# go.mod go nothing is uploaded: mirror-units.sh pushes the unit to its mirror repository and
|
|
22
24
|
# Package.swift swift tags it there (vX.Y.Z for Go, X.Y.Z for Swift). This script only checks the unit.
|
|
25
|
+
# (publish.to) binary a Go unit (go.mod) built for the platforms of the policy and released to the public release
|
|
26
|
+
# repository, with its formula at a GA version. binary-units.sh does it, this script only
|
|
27
|
+
# checks the unit: version.txt equals the manifest and the unit tag exists.
|
|
28
|
+
# (publish.to) image a unit with a Dockerfile, pushed to ghcr by image-units.sh. This script only checks it.
|
|
23
29
|
# Every unit's version must belong to <stage> (version_stage in scripts/lib/release-stages.sh), so a dispatch with the
|
|
24
30
|
# wrong stage stops instead of publishing a prerelease under latest. A version that is already on the registry is
|
|
25
31
|
# skipped, so a re-run is safe. The unit's own file must carry the version of .release-please-manifest.json, and a
|
|
@@ -32,17 +38,20 @@
|
|
|
32
38
|
#
|
|
33
39
|
# usage: publish-units.sh [pack|upload] <alpha|beta|rc|ga> <path>...
|
|
34
40
|
# publish-units.sh --registries <path>... print npm=true / github-packages=true / pypi=true / crates=true /
|
|
35
|
-
# go=true / swift=true for the targets the paths need
|
|
41
|
+
# go=true / swift=true / binary=true / image=true for the targets the paths need
|
|
42
|
+
# ($GITHUB_OUTPUT format)
|
|
36
43
|
# publish-units.sh --filter <path>... print the paths that are units to publish, one per line
|
|
37
44
|
# publish-units.sh --report <path>... print one line per path, once each: "unit <path> -> <target>" for a unit to
|
|
38
|
-
# publish, "unit <path> -> not-published" for any other path (the plan job log)
|
|
45
|
+
# publish, "unit <path> -> not-published" for any other path (the plan job log). A
|
|
46
|
+
# unit whose target cannot be told (for example publish.to binary without go.mod)
|
|
47
|
+
# prints the reason on stderr and the exit status is 1 after the last path.
|
|
39
48
|
# publish-units.sh --mirrors <path>... print the mirror repository names of the Go and Swift units, comma separated
|
|
40
49
|
# publish-units.sh --crate-exists <path>... exit 0 when every crates.io unit among the paths already has its crate
|
|
41
50
|
# on crates.io, 1 when one has not, 2 when crates.io cannot be asked
|
|
42
51
|
# PUBLISH_DRY_RUN 1 prints one line per unit (target, name@version, registry, dist-tag) and the command that would
|
|
43
52
|
# run, and runs nothing: nothing is packed, built or uploaded. A version the registry already has
|
|
44
53
|
# is printed as skipped.
|
|
45
|
-
# PUBLISH_REGISTRIES comma list of targets (npm,github-packages,pypi,crates,go,swift): act only on the units of these
|
|
54
|
+
# PUBLISH_REGISTRIES comma list of targets (npm,github-packages,pypi,crates,go,swift,binary,image): act only on the units of these
|
|
46
55
|
# targets. The checks still run for every unit. publish.yml has one job per kind of target.
|
|
47
56
|
# PUBLISH_CHECK_ONLY 1 stops after the checks (file version, stage, same content as the tag)
|
|
48
57
|
# GH_TOKEN a token that can read origin (publish.yml gives github.token). Only the git commands that read the
|
|
@@ -77,9 +86,30 @@ npm_dist_tag() { if [[ "$1" == ga ]]; then printf '%s\n' latest; else printf '%s
|
|
|
77
86
|
|
|
78
87
|
summary() { [[ -z "${GITHUB_STEP_SUMMARY:-}" ]] || printf '%s\n' "- $*" >> "$GITHUB_STEP_SUMMARY"; }
|
|
79
88
|
|
|
80
|
-
#
|
|
89
|
+
# unit_publish_to <path> → binary | image | none, the publish.to of the unit in release-policy.json; nothing when it has none
|
|
90
|
+
unit_publish_to() {
|
|
91
|
+
local to
|
|
92
|
+
to="$(policy_unit_publish_to "$(unit_component "$1")")"
|
|
93
|
+
case "$to" in
|
|
94
|
+
"" | binary | image | none) printf '%s\n' "$to" ;;
|
|
95
|
+
*) die "$1:政策檔的 publish.to 是 ${to},只能是 binary、image 或 none" ;;
|
|
96
|
+
esac
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# unit_target <path> → npm | github-packages | pypi | crates | go | swift | binary | image. publish.to of the unit
|
|
100
|
+
# decides when it has one (none has no target, so it fails); otherwise the file the unit carries does.
|
|
81
101
|
unit_target() {
|
|
82
|
-
local reg
|
|
102
|
+
local reg to
|
|
103
|
+
to="$(unit_publish_to "$1")" || return 1
|
|
104
|
+
case "$to" in
|
|
105
|
+
binary)
|
|
106
|
+
[[ -f "$1/go.mod" ]] || { echo "$1:publish.to 是 binary,但單元沒有 go.mod;這一版的執行檔發布只支援 Go" >&2; return 1; }
|
|
107
|
+
printf '%s\n' binary; return 0 ;;
|
|
108
|
+
image)
|
|
109
|
+
[[ -f "$1/Dockerfile" ]] || { echo "$1:publish.to 是 image,但單元目錄沒有 Dockerfile" >&2; return 1; }
|
|
110
|
+
printf '%s\n' image; return 0 ;;
|
|
111
|
+
none) return 1 ;;
|
|
112
|
+
esac
|
|
83
113
|
if [[ -f "$1/package.json" ]]; then
|
|
84
114
|
reg="$(jq -r '.publishConfig.registry // empty' "$1/package.json")"
|
|
85
115
|
case "${reg%/}" in
|
|
@@ -94,13 +124,17 @@ unit_target() {
|
|
|
94
124
|
else return 1; fi
|
|
95
125
|
}
|
|
96
126
|
|
|
97
|
-
target_of() { # target_of <path> → the target, or stop
|
|
98
|
-
unit_target "$1"
|
|
127
|
+
target_of() { # target_of <path> → the target, or stop. A unit that names its target in the policy has already said why it fails.
|
|
128
|
+
unit_target "$1" && return 0
|
|
129
|
+
[[ -z "$(unit_publish_to "$1")" ]] && die "$1 沒有 package.json(publishConfig.registry 只能是 npmjs 或 GitHub Packages)、pyproject.toml、Cargo.toml、go.mod 或 Package.swift,不知道要發布到哪裡"
|
|
130
|
+
return 1
|
|
99
131
|
}
|
|
100
132
|
|
|
101
|
-
# a unit is published when
|
|
102
|
-
#
|
|
133
|
+
# a unit is published when its publish.to is binary or image; with none it is not, whatever files it has. Without publish.to it
|
|
134
|
+
# is published when it carries one of those files, and a package.json only when it has a publishConfig: a unit that is not
|
|
135
|
+
# published (a shared library of the repository) has none
|
|
103
136
|
publishable() { # publishable <path>
|
|
137
|
+
case "$(unit_publish_to "$1")" in binary | image) return 0 ;; none) return 1 ;; esac
|
|
104
138
|
if [[ -f "$1/package.json" ]]; then jq -e 'has("publishConfig")' "$1/package.json" >/dev/null
|
|
105
139
|
else [[ -f "$1/pyproject.toml" || -f "$1/Cargo.toml" || -f "$1/go.mod" || -f "$1/Package.swift" ]]; fi
|
|
106
140
|
}
|
|
@@ -111,17 +145,21 @@ unit_name() { # unit_name <path> <target>
|
|
|
111
145
|
pypi) toml_get "$1/pyproject.toml" project name ;;
|
|
112
146
|
crates) toml_get "$1/Cargo.toml" package name ;;
|
|
113
147
|
go) sed -n 's/^module //p' "$1/go.mod" | head -1 ;;
|
|
148
|
+
binary) policy_unit_publish_field "$(unit_component "$1")" command ;;
|
|
149
|
+
image) unit_component "$1" ;;
|
|
114
150
|
swift) sed -n 's/^ *name: *"\([^"]*\)".*/\1/p' "$1/Package.swift" | head -1 ;;
|
|
115
151
|
esac
|
|
116
152
|
}
|
|
117
153
|
|
|
118
|
-
# the version the unit's own file carries; empty for a Go unit (no file) and for a Swift unit without version.txt
|
|
154
|
+
# the version the unit's own file carries; empty for a Go unit (no file) and for a Swift unit without version.txt. A binary unit
|
|
155
|
+
# carries it in version.txt, and a missing file reads as an empty version.
|
|
119
156
|
file_version() { # file_version <path> <target> → "<file>\t<version>"
|
|
120
157
|
case "$2" in
|
|
121
158
|
npm | github-packages) printf '%s\t%s\n' "$1/package.json" "$(jq -r .version "$1/package.json")" ;;
|
|
122
159
|
pypi) printf '%s\t%s\n' "$1/pyproject.toml" "$(toml_get "$1/pyproject.toml" project version)" ;;
|
|
123
160
|
crates) printf '%s\t%s\n' "$1/Cargo.toml" "$(toml_get "$1/Cargo.toml" package version)" ;;
|
|
124
161
|
swift) [[ ! -f "$1/version.txt" ]] || printf '%s\t%s\n' "$1/version.txt" "$(tr -d '[:space:]' < "$1/version.txt")" ;;
|
|
162
|
+
binary) printf '%s\t%s\n' "$1/version.txt" "$([[ ! -f "$1/version.txt" ]] || tr -d '[:space:]' < "$1/version.txt")" ;;
|
|
125
163
|
esac
|
|
126
164
|
}
|
|
127
165
|
|
|
@@ -181,6 +219,14 @@ mirror_name() { # mirror_name <path>
|
|
|
181
219
|
else die "$1: 不知道鏡像倉的 owner,請設 GITHUB_REPOSITORY(owner/repo)或 MIRROR_REMOTE"; fi
|
|
182
220
|
}
|
|
183
221
|
|
|
222
|
+
# the owner of the repository this run is in (GITHUB_REPOSITORY is owner/repo)
|
|
223
|
+
github_owner() {
|
|
224
|
+
local owner="${GITHUB_REPOSITORY:-}"
|
|
225
|
+
owner="${owner%%/*}"
|
|
226
|
+
[[ -n "$owner" ]] || die "不知道 owner,請設 GITHUB_REPOSITORY(owner/repo)"
|
|
227
|
+
printf '%s\n' "$owner"
|
|
228
|
+
}
|
|
229
|
+
|
|
184
230
|
# the registry a line names: the host, or the mirror repository (mirror_name) for Go and Swift
|
|
185
231
|
registry_name() { # registry_name <target> <path>
|
|
186
232
|
case "$1" in
|
|
@@ -189,6 +235,8 @@ registry_name() { # registry_name <target> <path>
|
|
|
189
235
|
pypi) echo pypi.org ;;
|
|
190
236
|
crates) echo crates.io ;;
|
|
191
237
|
go | swift) mirror_name "$2" ;;
|
|
238
|
+
binary) echo github-release ;;
|
|
239
|
+
image) echo "ghcr.io/$(github_owner)/$(unit_component "$2")" ;;
|
|
192
240
|
esac
|
|
193
241
|
}
|
|
194
242
|
|
|
@@ -270,6 +318,10 @@ plan_unit() { # plan_unit <path> <version> <stage> <target>
|
|
|
270
318
|
plan_line dry-run "$t" "$name" "$ver" "$reg" "" "cargo publish --locked --no-verify --manifest-path $p/Cargo.toml" ;;
|
|
271
319
|
go | swift)
|
|
272
320
|
plan_line dry-run "$t" "$name" "$ver" "$reg" "mirror tag $([[ "$t" == go ]] && echo "v$ver" || echo "$ver")" "bash scripts/release/mirror-units.sh $p" ;;
|
|
321
|
+
binary)
|
|
322
|
+
plan_line dry-run "$t" "$name" "$ver" "$reg" "release tag $(unit_tag "$p" "$ver")" "bash scripts/release/binary-units.sh $p" ;;
|
|
323
|
+
image)
|
|
324
|
+
plan_line dry-run "$t" "$name" "$ver" "$reg" "image tag $ver" "bash scripts/release/image-units.sh $p" ;;
|
|
273
325
|
esac
|
|
274
326
|
}
|
|
275
327
|
|
|
@@ -400,17 +452,23 @@ publish_crates() { # publish_crates <path> <version>
|
|
|
400
452
|
summary "crates.io \`$name $ver\`"
|
|
401
453
|
}
|
|
402
454
|
|
|
403
|
-
# --- Go and
|
|
404
|
-
# release-please creates the unit tag when the Release PR merges
|
|
405
|
-
# repository.
|
|
455
|
+
# --- Go, Swift, binary and image: nothing to upload here --------------------------------------------------------------
|
|
456
|
+
# release-please creates the unit tag when the Release PR merges. mirror-units.sh pushes a Go or Swift unit to its mirror
|
|
457
|
+
# repository, binary-units.sh releases the executables of a binary unit, and image-units.sh pushes the image of an image unit.
|
|
458
|
+
# A real run requires the unit tag to exist.
|
|
406
459
|
publish_tag() { # publish_tag <path> <version> <target>
|
|
407
|
-
local p="$1" ver="$2" t
|
|
460
|
+
local p="$1" ver="$2" t by
|
|
408
461
|
t="$(unit_tag "$p" "$ver")"
|
|
409
462
|
if ! git rev-parse -q --verify "refs/tags/$t" >/dev/null 2>&1; then
|
|
410
463
|
origin_git fetch -q --depth=1 origin "refs/tags/$t:refs/tags/$t" 2>/dev/null || true
|
|
411
464
|
git rev-parse -q --verify "refs/tags/$t" >/dev/null 2>&1 || die "tag $t 不存在,所以 $p $ver 還沒有發版"
|
|
412
465
|
fi
|
|
413
|
-
|
|
466
|
+
case "$3" in
|
|
467
|
+
binary) by="binary-units.sh 發到發布倉" ;;
|
|
468
|
+
image) by="image-units.sh 推到 ghcr" ;;
|
|
469
|
+
*) by="mirror-units.sh 推到鏡像倉" ;;
|
|
470
|
+
esac
|
|
471
|
+
log "${3}:$(unit_name "$p" "$3") ${ver},tag $t 即發布紀錄,由 ${by},這裡不上傳"
|
|
414
472
|
summary "$3 \`$(unit_name "$p" "$3") $ver\`,tag \`$t\`(不上傳)"
|
|
415
473
|
}
|
|
416
474
|
|
|
@@ -419,7 +477,11 @@ case "$1" in
|
|
|
419
477
|
--registries)
|
|
420
478
|
shift
|
|
421
479
|
regs=()
|
|
422
|
-
for p in "$@"; do
|
|
480
|
+
for p in "$@"; do
|
|
481
|
+
p="${p%/}"
|
|
482
|
+
[[ "$(unit_publish_to "$p")" != none ]] || continue # a unit that is not published needs no target
|
|
483
|
+
r="$(target_of "$p")"; regs+=("$r=true")
|
|
484
|
+
done
|
|
423
485
|
printf '%s\n' "${regs[@]}" | sort -u
|
|
424
486
|
exit 0 ;;
|
|
425
487
|
--filter)
|
|
@@ -429,13 +491,16 @@ case "$1" in
|
|
|
429
491
|
--report)
|
|
430
492
|
shift
|
|
431
493
|
declare -A reported=()
|
|
494
|
+
rc=0
|
|
432
495
|
for p in "$@"; do
|
|
433
496
|
p="${p%/}"
|
|
434
497
|
[[ -z "${reported[$p]:-}" ]] || continue
|
|
435
498
|
reported[$p]=1
|
|
436
|
-
if publishable "$p"; then
|
|
499
|
+
if publishable "$p"; then
|
|
500
|
+
if t="$(target_of "$p")"; then printf 'unit %s -> %s\n' "$p" "$t"; else rc=1; fi
|
|
501
|
+
else printf 'unit %s -> not-published\n' "$p"; fi
|
|
437
502
|
done
|
|
438
|
-
exit
|
|
503
|
+
exit "$rc" ;;
|
|
439
504
|
--mirrors)
|
|
440
505
|
shift
|
|
441
506
|
names=()
|
|
@@ -471,6 +536,10 @@ fi
|
|
|
471
536
|
for phase in "${phases[@]}"; do
|
|
472
537
|
for p in "$@"; do
|
|
473
538
|
p="${p%/}"
|
|
539
|
+
if [[ "$(unit_publish_to "$p")" == none ]]; then
|
|
540
|
+
[[ "$phase" == pack ]] && info "${p}:政策檔的 publish.to 是 none,不發布" >&2
|
|
541
|
+
continue
|
|
542
|
+
fi
|
|
474
543
|
ver="$(manifest_version "$p")"
|
|
475
544
|
[[ -n "$ver" ]] || die "$p 不在 $MANIFEST"
|
|
476
545
|
vs="$(version_stage "$ver")" || die "$p 的版號 $ver 不是 X.Y.Z 或 X.Y.Z-<alpha|beta|rc>.N,無法決定發布階段"
|
|
@@ -497,7 +566,7 @@ for phase in "${phases[@]}"; do
|
|
|
497
566
|
printf '%s %s\n' "$p" "$ver" >> "$PUBLISH_OUT/packed.txt"
|
|
498
567
|
else
|
|
499
568
|
# an upload job that got a different artifact than the build job made stops instead of publishing it
|
|
500
|
-
case "$target" in go | swift) ;; *)
|
|
569
|
+
case "$target" in go | swift | binary | image) ;; *)
|
|
501
570
|
grep -qxF "$p $ver" "$PUBLISH_OUT/packed.txt" 2>/dev/null \
|
|
502
571
|
|| die "$p $ver 不在 $PUBLISH_OUT/packed.txt:建置階段沒有打包這個單元,或下載的 artifact 不是這次建置的" ;;
|
|
503
572
|
esac
|
|
@@ -505,7 +574,7 @@ for phase in "${phases[@]}"; do
|
|
|
505
574
|
npm | github-packages) publish_npm "$p" "$ver" "$stage" "$target" ;;
|
|
506
575
|
pypi) publish_pypi "$p" "$ver" ;;
|
|
507
576
|
crates) publish_crates "$p" "$ver" ;;
|
|
508
|
-
go | swift) publish_tag "$p" "$ver" "$target" ;;
|
|
577
|
+
go | swift | binary | image) publish_tag "$p" "$ver" "$target" ;;
|
|
509
578
|
esac
|
|
510
579
|
fi
|
|
511
580
|
done
|
|
@@ -146,7 +146,8 @@ jobs:
|
|
|
146
146
|
done
|
|
147
147
|
|
|
148
148
|
# @if publish
|
|
149
|
-
# packages/*、libs/*、facts 與 docs
|
|
149
|
+
# packages/*、libs/*、facts 與 docs 匯總套件,以及政策檔 publish.to 是 binary 或 image 的單元(不論它在哪個目錄,
|
|
150
|
+
# 例如 services/)→ 每個階段都發布(publish.yml)。哪些路徑真的是要發布的單元,
|
|
150
151
|
# 由 publish.yml 的 plan job 判斷(libs/* 有的不發布)。alpha、beta、rc 掛在階段名的 npm dist-tag,GA 才進
|
|
151
152
|
# latest,所以使用者要明確指定才會裝到預發布版。同一條發布線的單元可以停在不同階段(docs/versioning.md),
|
|
152
153
|
# 所以 dispatch-publish.sh 依每個單元自己的版號算階段,每個階段各派送一次 publish.yml,publish.yml 再逐單元核對
|
|
@@ -105,6 +105,45 @@
|
|
|
105
105
|
"propertyNames": { "$ref": "#/definitions/stage" },
|
|
106
106
|
"additionalProperties": { "type": "string", "minLength": 1 }
|
|
107
107
|
},
|
|
108
|
+
"publish": {
|
|
109
|
+
"description": "Where the unit is published. Left out, the target follows the files of the unit.",
|
|
110
|
+
"type": "object",
|
|
111
|
+
"required": ["to"],
|
|
112
|
+
"additionalProperties": false,
|
|
113
|
+
"properties": {
|
|
114
|
+
"to": {
|
|
115
|
+
"description": "binary: a compiled executable released to the public release repository. image: a container image pushed to ghcr. none: the unit is not published.",
|
|
116
|
+
"enum": ["binary", "image", "none"]
|
|
117
|
+
},
|
|
118
|
+
"command": {
|
|
119
|
+
"description": "The name of the executable and of its formula. Required for binary.",
|
|
120
|
+
"type": "string",
|
|
121
|
+
"pattern": "^[a-z0-9][a-z0-9._-]*$"
|
|
122
|
+
},
|
|
123
|
+
"description": {
|
|
124
|
+
"description": "One line that says what the executable does, written into the formula. Required for binary.",
|
|
125
|
+
"type": "string",
|
|
126
|
+
"minLength": 1
|
|
127
|
+
},
|
|
128
|
+
"platforms": {
|
|
129
|
+
"description": "The platforms to build for, as <os>/<arch>, for example linux/amd64. Required for binary and image.",
|
|
130
|
+
"type": "array",
|
|
131
|
+
"minItems": 1,
|
|
132
|
+
"uniqueItems": true,
|
|
133
|
+
"items": { "type": "string", "pattern": "^[a-z0-9]+/[a-z0-9]+$" }
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"allOf": [
|
|
137
|
+
{
|
|
138
|
+
"if": { "required": ["to"], "properties": { "to": { "const": "binary" } } },
|
|
139
|
+
"then": { "required": ["command", "description", "platforms"] }
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"if": { "required": ["to"], "properties": { "to": { "const": "image" } } },
|
|
143
|
+
"then": { "required": ["platforms"] }
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
},
|
|
108
147
|
"unit": {
|
|
109
148
|
"type": "object",
|
|
110
149
|
"required": ["kind", "stages"],
|
|
@@ -139,6 +178,7 @@
|
|
|
139
178
|
"description": "Destination of each stage for this unit, overriding the repository targets. Store channels for mobile and desktop.",
|
|
140
179
|
"$ref": "#/definitions/targets"
|
|
141
180
|
},
|
|
181
|
+
"publish": { "$ref": "#/definitions/publish" },
|
|
142
182
|
"dependsOn": {
|
|
143
183
|
"description": "Same-repository units this unit depends on that its package manifest cannot express, e.g. a binding across languages.",
|
|
144
184
|
"type": "array",
|
|
@@ -154,6 +194,16 @@
|
|
|
154
194
|
{
|
|
155
195
|
"if": { "properties": { "kind": { "enum": ["package", "sdk"] } } },
|
|
156
196
|
"then": { "not": { "required": ["targets"] } }
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"description": "A unit that publishes executables is a package.",
|
|
200
|
+
"if": { "required": ["publish"], "properties": { "publish": { "required": ["to"], "properties": { "to": { "const": "binary" } } } } },
|
|
201
|
+
"then": { "properties": { "kind": { "const": "package" } } }
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"description": "A unit that publishes a container image is a service or a backend.",
|
|
205
|
+
"if": { "required": ["publish"], "properties": { "publish": { "required": ["to"], "properties": { "to": { "const": "image" } } } } },
|
|
206
|
+
"then": { "properties": { "kind": { "enum": ["service", "backend"] } } }
|
|
157
207
|
}
|
|
158
208
|
]
|
|
159
209
|
}
|
|
@@ -14,12 +14,16 @@
|
|
|
14
14
|
# config of its own to compare with, so this check lives here, on the release side. On a release branch
|
|
15
15
|
# whose config was cut down to the train, a component the config no longer has is skipped.
|
|
16
16
|
# - a unit that deploys (service, backend, web) finds a target for each stage it walks, in its own
|
|
17
|
-
# targets or the repository targets
|
|
17
|
+
# targets or the repository targets. A unit whose publish.to is image is left out: it publishes a container
|
|
18
|
+
# image and is not deployed by its tag, so it needs no targets
|
|
18
19
|
# - a unit that deploys walks at least one pre-release stage when its own targets or the repository
|
|
19
20
|
# targets have one. Only after deploying does it show how it works with the other services, and a
|
|
20
21
|
# GA-only unit goes to prod as soon as the train enters its first stage
|
|
21
22
|
# - a unit that ships to store channels (mobile, desktop) names a channel for each stage it walks
|
|
22
23
|
# - every dependsOn names a unit the policy lists
|
|
24
|
+
# - a unit whose publish.to is binary has the kind package, names command, description and platforms, and has a go.mod in
|
|
25
|
+
# its directory (this version supports Go only); a unit whose publish.to is image has the kind service or backend and
|
|
26
|
+
# names platforms
|
|
23
27
|
# A <product>-hub has no units and no release-please-config.json, so there is nothing to compare and it passes.
|
|
24
28
|
# A repository of the organization layer (layer: organization) belongs to no product, so product.members is not read.
|
|
25
29
|
# Without units it passes the same way; with units it is checked as a single repository, like any other.
|
|
@@ -93,9 +97,10 @@ fi
|
|
|
93
97
|
while IFS= read -r line; do [[ -n "$line" ]] && problems+=("$line"); done < <(jq -r '
|
|
94
98
|
. as $p
|
|
95
99
|
| (.units // {}) | to_entries[] | .key as $u | .value as $v
|
|
100
|
+
| (($v.kind | IN("service", "backend", "web")) and (($v.publish.to // "") != "image")) as $deploys
|
|
96
101
|
| (
|
|
97
102
|
($v.stages // [])[] as $s
|
|
98
|
-
| if
|
|
103
|
+
| if $deploys then
|
|
99
104
|
select((($v.targets // {})[$s] // ($p.targets // {})[$s]) == null)
|
|
100
105
|
| "\($u)(\($v.kind))的階段 \($s) 找不到去處:units.\($u).targets 與 targets 都沒有 \($s)"
|
|
101
106
|
elif ($v.kind | IN("mobile", "desktop")) then
|
|
@@ -104,7 +109,7 @@ while IFS= read -r line; do [[ -n "$line" ]] && problems+=("$line"); done < <(jq
|
|
|
104
109
|
else empty end
|
|
105
110
|
),
|
|
106
111
|
(
|
|
107
|
-
select($
|
|
112
|
+
select($deploys)
|
|
108
113
|
| ([($v.targets // {}), ($p.targets // {})] | map(keys[]) | map(select(IN("alpha", "beta", "rc"))) | unique) as $pre
|
|
109
114
|
| select(($pre | length) > 0 and ([($v.stages // [])[] | select(. != "ga")] | length) == 0)
|
|
110
115
|
| "\($u)(\($v.kind))只發 GA,但 targets 有預發布階段 \($pre | join("、")):部署型單元要至少走一個預發布階段"
|
|
@@ -113,9 +118,29 @@ while IFS= read -r line; do [[ -n "$line" ]] && problems+=("$line"); done < <(jq
|
|
|
113
118
|
($v.dependsOn // [])[] as $d
|
|
114
119
|
| select(($p.units | has($d)) | not)
|
|
115
120
|
| "\($u) 的 dependsOn 指到不存在的單元:\($d)"
|
|
121
|
+
),
|
|
122
|
+
(
|
|
123
|
+
select(($v.publish.to // "") == "binary")
|
|
124
|
+
| (select($v.kind != "package") | "\($u) 的 publish.to 是 binary,kind 要是 package(現在是 \($v.kind))"),
|
|
125
|
+
(([ "command", "description", "platforms" ] - ($v.publish | keys)) | select(length > 0) | "\($u) 的 publish.to 是 binary,publish 要寫 \(join("、"))")
|
|
126
|
+
),
|
|
127
|
+
(
|
|
128
|
+
select(($v.publish.to // "") == "image")
|
|
129
|
+
| (select($v.kind | IN("service", "backend") | not) | "\($u) 的 publish.to 是 image,kind 要是 service 或 backend(現在是 \($v.kind))"),
|
|
130
|
+
(select(($v.publish | has("platforms")) | not) | "\($u) 的 publish.to 是 image,publish 要寫 platforms")
|
|
116
131
|
)
|
|
117
132
|
' "$policy")
|
|
118
133
|
|
|
134
|
+
# 3. a unit that publishes executables is a Go unit: this version has no other way to build one
|
|
135
|
+
if [[ -f "$config" ]]; then
|
|
136
|
+
while IFS= read -r u; do
|
|
137
|
+
[[ -n "$u" ]] || continue
|
|
138
|
+
path="$(jq -r --arg c "$u" '.packages | to_entries[] | select((.value.component // (.key | split("/")[1])) == $c) | .key' "$config" | head -n 1)"
|
|
139
|
+
[[ -n "$path" ]] || continue
|
|
140
|
+
[[ -f "$REPO_ROOT/$path/go.mod" ]] || problems+=("${u} 的 publish.to 是 binary,但 ${path}/ 沒有 go.mod:這一版的執行檔發布只支援 Go")
|
|
141
|
+
done < <(jq -r '(.units // {}) | to_entries[] | select(.value.publish.to == "binary") | .key' "$policy")
|
|
142
|
+
fi
|
|
143
|
+
|
|
119
144
|
if (( ${#problems[@]} )); then
|
|
120
145
|
printf '%s\n' "✗ 政策檔與倉庫不一致(${policy}):" >&2
|
|
121
146
|
for p in "${problems[@]}"; do printf '%s\n' " - $p" >&2; done
|
|
@@ -64,6 +64,22 @@ stages_override_policy() {
|
|
|
64
64
|
|
|
65
65
|
policy_unit_kind() { policy_require; jq -r --arg u "$1" '.units[$u].kind // empty' "$(policy_file)"; }
|
|
66
66
|
|
|
67
|
+
# policy_unit_publish_to <unit> → binary | image | none, the publish.to the policy gives the unit; prints nothing when the unit
|
|
68
|
+
# has none, when the policy does not list it, and when there is no policy file at all (a repository that only publishes
|
|
69
|
+
# has the policy of its release role, but a script that only reads where to publish must not stop on a missing file).
|
|
70
|
+
# A unit without it follows the files of its directory (publish-units.sh, blueprint-shared.publishing.target-selection).
|
|
71
|
+
policy_unit_publish_to() {
|
|
72
|
+
[[ -f "$(policy_file)" ]] || return 0
|
|
73
|
+
jq -r --arg u "$1" '.units[$u].publish.to // empty' "$(policy_file)"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
# policy_unit_publish_field <unit> <command|description|platforms> → that field of publish in the policy, an array one element per line;
|
|
77
|
+
# prints nothing when the unit has no such field.
|
|
78
|
+
policy_unit_publish_field() {
|
|
79
|
+
[[ -f "$(policy_file)" ]] || return 0
|
|
80
|
+
jq -r --arg u "$1" --arg f "$2" '.units[$u].publish[$f] // empty | if type == "array" then .[] else . end' "$(policy_file)"
|
|
81
|
+
}
|
|
82
|
+
|
|
67
83
|
# policy_unit_independent <unit> → succeeds when the policy marks the unit "independent": true, which means the
|
|
68
84
|
# unit releases on its own and does not follow the product line's cadence. A unit the policy does not list, or
|
|
69
85
|
# one without the field, is not independent.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Dispatch publish.yml for the packages a release created, one dispatch per stage of the versions.
|
|
3
|
-
# release-please.yml calls it after each release.
|
|
3
|
+
# release-please.yml calls it after each release. It dispatches packages/*, libs/*, the facts and docs aggregate packages, and the
|
|
4
|
+
# units whose publish.to in release-policy.json is binary or image, wherever their directory is. The units of one release line may stand at different
|
|
4
5
|
# stages (docs/versioning.md): a unit that only walks ga is at its final version while the line is in
|
|
5
6
|
# alpha. publish-units.sh stops when a version does not belong to the stage it is given, so the units are
|
|
6
7
|
# grouped by the stage of their own version in .release-please-manifest.json and each group is dispatched
|
|
@@ -16,7 +17,16 @@ cd "$REPO_ROOT"
|
|
|
16
17
|
paths="${PATHS:?PATHS is required (JSON array of released paths)}"
|
|
17
18
|
ref="${GITHUB_REF_NAME:?GITHUB_REF_NAME is required}"
|
|
18
19
|
pkgs="$(jq -r '.[]' <<<"$paths" | while IFS= read -r p; do
|
|
19
|
-
case "$p" in
|
|
20
|
+
case "$p" in
|
|
21
|
+
packages/*|libs/*) printf '%s\n' "$p" ;;
|
|
22
|
+
*)
|
|
23
|
+
# a unit whose publish.to is binary or image is dispatched wherever its directory is, services/ for example; a unit without
|
|
24
|
+
# publish.to or with none is not, so a service that is only deployed is left out
|
|
25
|
+
case "$(policy_unit_publish_to "$(unit_component "$p")")" in
|
|
26
|
+
binary|image) printf '%s\n' "$p" ;;
|
|
27
|
+
*) ! is_aggregate_path "$p" || printf '%s\n' "$p" ;;
|
|
28
|
+
esac ;;
|
|
29
|
+
esac
|
|
20
30
|
done | jq -Rsc 'split("\n") | map(select(length > 0))')"
|
|
21
31
|
if [[ "$pkgs" == "[]" ]]; then echo "no packages in this release"; exit 0; fi
|
|
22
32
|
pairs=""
|
package/facts-describes.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// The version a component package describes: the latest released version of the unit it describes, read from the version
|
|
2
|
-
// file in that unit's directory. A release changes that file in the same commit as the release itself, so `describes` and
|
|
3
|
-
// the version actually released never need a second edit. The directory comes from the entry that calls describesOf; no
|
|
4
|
-
// release manifest or config is read here, and a check on the release side keeps the directory equal to the unit's path there.
|
|
5
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
6
|
-
|
|
7
|
-
const root = new URL('../../', import.meta.url)
|
|
8
|
-
|
|
9
|
-
// The version of a `[section]` key of a TOML file: only the plain `version = "x"` form of that table counts.
|
|
10
|
-
function tomlVersion(text: string, section: string): string | undefined {
|
|
11
|
-
let current = ''
|
|
12
|
-
for (const line of text.split(/\r?\n/)) {
|
|
13
|
-
// an array table `[[x]]` leaves the current section, and its keys never belong to a plain `[section]`
|
|
14
|
-
if (/^\s*\[\[[^\]]+\]\]\s*(?:#.*)?$/.test(line)) {
|
|
15
|
-
current = ''
|
|
16
|
-
continue
|
|
17
|
-
}
|
|
18
|
-
const header = /^\s*\[([^\]]+)\]\s*(?:#.*)?$/.exec(line)
|
|
19
|
-
if (header !== null) {
|
|
20
|
-
current = header[1]!.trim()
|
|
21
|
-
continue
|
|
22
|
-
}
|
|
23
|
-
if (current !== section) continue
|
|
24
|
-
const m = /^\s*version\s*=\s*["']([^"']+)["']\s*(?:#.*)?$/.exec(line)
|
|
25
|
-
if (m !== null) return m[1]
|
|
26
|
-
}
|
|
27
|
-
return undefined
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Version files in the order they are tried: the files a release writes for the node, python, rust and simple release types.
|
|
31
|
-
const READERS: Array<[string, (text: string) => string | undefined]> = [
|
|
32
|
-
['package.json', (t) => (JSON.parse(t) as { version?: unknown }).version as string | undefined],
|
|
33
|
-
// the release tooling reads [project] first and falls back to [tool.poetry]
|
|
34
|
-
['pyproject.toml', (t) => tomlVersion(t, 'project') ?? tomlVersion(t, 'tool.poetry')],
|
|
35
|
-
['Cargo.toml', (t) => tomlVersion(t, 'package')],
|
|
36
|
-
['version.txt', (t) => t.trim() || undefined],
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* `describes` for the unit in `dir` (relative to the repository root): `{ [component]: <its version> }`.
|
|
41
|
-
* A unit with no version file, or still at the 0.0.0 placeholder (not released yet), gives `{}`, the same as a
|
|
42
|
-
* package that describes nothing.
|
|
43
|
-
*/
|
|
44
|
-
export function describesOf(component: string, dir: string): Record<string, string> {
|
|
45
|
-
for (const [name, read] of READERS) {
|
|
46
|
-
const file = new URL(`${dir.replace(/\/+$/, '')}/${name}`, root)
|
|
47
|
-
if (!existsSync(file)) continue
|
|
48
|
-
const version = read(readFileSync(file, 'utf8'))
|
|
49
|
-
if (typeof version !== 'string' || version === '') continue
|
|
50
|
-
return version === '0.0.0' ? {} : { [component]: version }
|
|
51
|
-
}
|
|
52
|
-
return {}
|
|
53
|
-
}
|
package/facts-skeleton.mjs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// The skeleton of the facts/ directory of a repository that follows the template structure: the aggregate package that
|
|
2
|
-
// publishes the facts, the fact-kit configuration, one component package per unit (and one for the product-level spec),
|
|
3
|
-
// and the shared _lib/describes.ts the components read their version through. No dependency and no file of the repository
|
|
4
|
-
// that holds the templates is read, so the same file runs from the published package
|
|
5
|
-
// (blueprint-shared-templates/facts-skeleton.mjs); the only file it reads is facts-describes.ts beside it.
|
|
6
|
-
//
|
|
7
|
-
// factsSkeleton({ repoName, repoUrl, access, metaFactName, productSpecFactName?, units, versions })
|
|
8
|
-
// repoName the repository name, written into descriptions
|
|
9
|
-
// repoUrl the git URL of the repository, e.g. git+https://github.com/<owner>/<repo>.git
|
|
10
|
-
// access "restricted" publishes the aggregate package to GitHub Packages, anything else to the public registry
|
|
11
|
-
// metaFactName the package name of the aggregate facts package
|
|
12
|
-
// productSpecFactName the fact name of the product-level spec component, when the repository has one
|
|
13
|
-
// units [{ unitName, factName, dir, publish? }]: a component package per unit. `dir` is the unit's directory,
|
|
14
|
-
// which describesOf reads the version from (check-release-policy.sh compares it with the
|
|
15
|
-
// release-please configuration); `publish` is { target, name } when the unit publishes
|
|
16
|
-
// versions { "fact-kit": "<range>", "oxc-parser": "<range>" } written into devDependencies
|
|
17
|
-
// returns a Map of repository-relative path -> file content.
|
|
18
|
-
// What only some repositories have (the facts of an R2 bucket or a URL pattern of a unit) is added by the caller.
|
|
19
|
-
import { readFileSync } from "node:fs";
|
|
20
|
-
|
|
21
|
-
const json = (value) => JSON.stringify(value, null, 2) + "\n";
|
|
22
|
-
|
|
23
|
-
// describes.ts of a component package: the same file as facts/_lib/describes.ts of the repository that holds the templates
|
|
24
|
-
// (a test compares them), so a repository reads the version of the unit it describes from the unit's directory.
|
|
25
|
-
export const describesText = () => readFileSync(new URL("./facts-describes.ts", import.meta.url), "utf8");
|
|
26
|
-
|
|
27
|
-
export function factsSkeleton({ repoName, repoUrl, access, metaFactName, productSpecFactName, units, versions }) {
|
|
28
|
-
for (const [key, value] of Object.entries({ repoName, repoUrl, metaFactName })) {
|
|
29
|
-
if (!value) throw new Error(`factsSkeleton: ${key} is required`);
|
|
30
|
-
}
|
|
31
|
-
for (const key of ["fact-kit", "oxc-parser"]) if (!versions?.[key]) throw new Error(`factsSkeleton: versions["${key}"] is required`);
|
|
32
|
-
for (const u of units ?? []) {
|
|
33
|
-
for (const key of ["unitName", "factName", "dir"]) if (!u[key]) throw new Error(`factsSkeleton: unit ${u.unitName ?? JSON.stringify(u)} has no ${key}`);
|
|
34
|
-
}
|
|
35
|
-
const out = new Map();
|
|
36
|
-
const publishConfig = access === "restricted" ? { registry: "https://npm.pkg.github.com" } : { access: "public" };
|
|
37
|
-
const components = units.map((unit) => ({ name: unit.unitName, factName: unit.factName, unit }));
|
|
38
|
-
if (productSpecFactName) components.push({ name: `${repoName}-spec`, factName: productSpecFactName });
|
|
39
|
-
components.sort((a, b) => a.name.localeCompare(b.name));
|
|
40
|
-
const dev = { "fact-kit": versions["fact-kit"], "oxc-parser": versions["oxc-parser"] };
|
|
41
|
-
out.set("facts/_lib/describes.ts", describesText());
|
|
42
|
-
out.set("facts/fact-kit.config.json", json({ aggregate: Object.fromEntries(components.map((c) => [c.name, c.factName])) }));
|
|
43
|
-
out.set(
|
|
44
|
-
"facts/package.json",
|
|
45
|
-
json({
|
|
46
|
-
name: metaFactName,
|
|
47
|
-
version: "0.0.0",
|
|
48
|
-
description: `Facts for ${repoName}: one component per unit${productSpecFactName ? " and the product-level spec" : ""}`,
|
|
49
|
-
type: "module",
|
|
50
|
-
repository: { type: "git", url: repoUrl, directory: "facts" },
|
|
51
|
-
publishConfig,
|
|
52
|
-
files: ["dist"],
|
|
53
|
-
scripts: { build: "fact-kit build", check: "fact-kit check" },
|
|
54
|
-
devDependencies: { ...Object.fromEntries(components.map((c) => [c.factName, "workspace:*"])), ...dev },
|
|
55
|
-
exports: Object.fromEntries(components.flatMap((c) => [[`./${c.name}/index.json`, `./dist/${c.name}/index.json`], [`./${c.name}/schemas/*`, `./dist/${c.name}/schemas/*`]])),
|
|
56
|
-
}),
|
|
57
|
-
);
|
|
58
|
-
for (const c of components) {
|
|
59
|
-
out.set(
|
|
60
|
-
`facts/${c.name}/package.json`,
|
|
61
|
-
json({
|
|
62
|
-
name: c.factName,
|
|
63
|
-
version: "0.0.0",
|
|
64
|
-
private: true,
|
|
65
|
-
description: `Facts about ${c.name}. Private workspace package, published through ${metaFactName}.`,
|
|
66
|
-
type: "module",
|
|
67
|
-
scripts: { build: "fact-kit build", check: "fact-kit check" },
|
|
68
|
-
devDependencies: { "fact-kit": dev["fact-kit"] },
|
|
69
|
-
exports: { [`./${c.name}/index.json`]: `./dist/${c.name}/index.json` },
|
|
70
|
-
}),
|
|
71
|
-
);
|
|
72
|
-
if (c.unit) out.set(`facts/${c.name}/fact-kit.config.json`, json({ implDirs: [`../../${c.unit.dir}`] }));
|
|
73
|
-
const publish = c.unit?.publish ? ` publish: { target: '${c.unit.publish.target}', name: '${c.unit.publish.name}' },\n` : "";
|
|
74
|
-
// Every facts entry declares its layer (blueprint-shared.doc-layers.layers): a unit's facts are the implementation
|
|
75
|
-
// layer, the product-level spec is the product layer.
|
|
76
|
-
out.set(
|
|
77
|
-
`facts/${c.name}/facts/${c.name}/index.ts`,
|
|
78
|
-
c.unit
|
|
79
|
-
? `import type { FactsModule } from 'fact-kit'\nimport { describesOf } from '../../../_lib/describes.ts'\n\n// No facts yet: the package exists so every unit has a place to put them.\nconst entry: FactsModule = {\n layer: 'implementation',\n describes: describesOf('${c.name}', '${c.unit.dir}'),\n${publish} facts: [],\n}\n\nexport default entry\n`
|
|
80
|
-
: `import type { FactsModule } from 'fact-kit'\n\n// Product-level facts. describes is empty: the product version comes from the Release Plan, not the manifest.\nconst entry: FactsModule = {\n layer: 'product',\n describes: {},\n facts: [],\n}\n\nexport default entry\n`,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
return out;
|
|
84
|
-
}
|