blueprint-shared-templates 0.1.0-0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/.github/CODEOWNERS.example +10 -0
- package/base/.github/ISSUE_TEMPLATE/bug.yml +15 -0
- package/base/.github/ISSUE_TEMPLATE/feature.yml +19 -0
- package/base/.github/ISSUE_TEMPLATE/hotfix.yml +17 -0
- package/base/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- package/base/.github/actions/setup-workspace/action.yml +54 -0
- package/base/.github/version-control.md +22 -0
- package/base/.github/workflows/auto-merge.yml +138 -0
- package/base/.github/workflows/ci.yml +274 -0
- package/base/.github/workflows/main-commit-check.yml +42 -0
- package/base/.github/workflows/pr-message.yml +64 -0
- package/base/.gitignore +356 -0
- package/base/.oxlintrc.json +14 -0
- package/base/LICENSE +21 -0
- package/base/releases/release-plan.md +39 -0
- package/base/scripts/ci/affected.sh +15 -0
- package/base/scripts/ci/ai-attribution-list.txt +68 -0
- package/base/scripts/ci/check-commit-body.sh +110 -0
- package/base/scripts/ci/check-main-commits.sh +31 -0
- package/base/scripts/ci/check-pr-title.sh +10 -0
- package/base/scripts/ci/ci-scope.conf +23 -0
- package/base/scripts/ci/ci-scope.sh +106 -0
- package/base/scripts/ci/native-build.sh +40 -0
- package/base/scripts/ci/run-affected.sh +48 -0
- package/base/scripts/ci/run-units.sh +33 -0
- package/base/scripts/hooks/commit-msg +38 -0
- package/base/scripts/hooks/pre-push +63 -0
- package/base/scripts/lib/common.sh +233 -0
- package/base/scripts/lib/retry.mjs +178 -0
- package/base/scripts/merge/decide.mjs +130 -0
- package/base/scripts/setup/git-hooks.sh +16 -0
- package/base/scripts/setup/github-repo-settings.json +8 -0
- package/base/scripts/setup/github-repo-settings.sh +110 -0
- package/deploy/.github/workflows/deploy-prerelease.yml +157 -0
- package/deploy/.github/workflows/deploy-production.yml +173 -0
- package/deploy/scripts/deploy/build-bundle.sh +49 -0
- package/deploy/scripts/deploy/clone-ops.sh +14 -0
- package/deploy/scripts/deploy/plan-production.sh +43 -0
- package/deploy/scripts/deploy/promote.sh +35 -0
- package/deploy/scripts/deploy/publish-bundle.sh +21 -0
- package/deploy/scripts/deploy/route-tag.sh +65 -0
- package/deploy/scripts/deploy/run-prerelease.sh +49 -0
- package/deploy/scripts/deploy/run-production.sh +51 -0
- package/deploy/scripts/deploy/writeback-ops.sh +53 -0
- package/deploy/scripts/lib/bundle.sh +52 -0
- package/facts-describes.ts +53 -0
- package/facts-skeleton.mjs +84 -0
- package/hub/.github/workflows/open-release-lines.yml +63 -0
- package/hub/scripts/deploy/clone-ops.sh +14 -0
- package/hub/scripts/release/dispatch-release-lines.sh +54 -0
- package/hub/scripts/release/snapshot-members.sh +85 -0
- package/infra/.github/workflows/deploy-prerelease.yml +157 -0
- package/infra/.github/workflows/deploy-production.yml +173 -0
- package/infra/scripts/deploy/apply-infra.sh +46 -0
- package/infra/scripts/deploy/apply-prerelease.sh +22 -0
- package/infra/scripts/deploy/apply-production.sh +33 -0
- package/infra/scripts/deploy/route-tag.sh +65 -0
- package/ops/.github/workflows/ops-deploy.yml +88 -0
- package/ops/scripts/deploy/apply-ops.sh +100 -0
- package/ops/scripts/deploy/healthz.sh +16 -0
- package/ops/scripts/deploy/ops-run.sh +41 -0
- package/ops/scripts/deploy/smoke.sh +49 -0
- package/ops/scripts/lib/bundle.sh +52 -0
- package/package.json +21 -4
- package/publish/.github/workflows/publish.yml +299 -0
- package/publish/scripts/release/cleanup-private-packages.mjs +107 -0
- package/publish/scripts/release/mirror-units.sh +167 -0
- package/publish/scripts/release/publish-units.sh +489 -0
- package/release/.github/workflows/nightly.yml +93 -0
- package/release/.github/workflows/open-release-line.yml +70 -0
- package/release/.github/workflows/release-line-finalize.yml +101 -0
- package/release/.github/workflows/release-please.yml +148 -0
- package/release/release-please-config.json +39 -0
- package/release/release-policy.json +38 -0
- package/release/schemas/release-policy.schema.json +151 -0
- package/release/scripts/ci/check-facts-describes.sh +63 -0
- package/release/scripts/ci/check-facts.sh +46 -0
- package/release/scripts/ci/check-release-policy-schema.sh +59 -0
- package/release/scripts/ci/check-release-policy.sh +123 -0
- package/release/scripts/ci/pin-train.sh +29 -0
- package/release/scripts/ci/release-train.sh +39 -0
- package/release/scripts/ci/validate-json-schema.mjs +17 -0
- package/release/scripts/lib/docs.sh +71 -0
- package/release/scripts/lib/facts.sh +146 -0
- package/release/scripts/lib/release-plan.sh +128 -0
- package/release/scripts/lib/release-pr.sh +106 -0
- package/release/scripts/lib/release-stages.sh +903 -0
- package/release/scripts/release/advance-release.sh +86 -0
- package/release/scripts/release/cut-release.sh +313 -0
- package/release/scripts/release/dispatch-publish.sh +34 -0
- package/release/scripts/release/ensure-stage-deploys.sh +56 -0
- package/release/scripts/release/finalize-release.sh +351 -0
- package/release/scripts/release/merge-release-pr.sh +233 -0
- package/release/scripts/release/open-release-line.sh +22 -0
- package/release/scripts/release/plan.sh +45 -0
- package/release/scripts/release/snapshot.sh +57 -0
- package/release/scripts/release/verify-production.sh +63 -0
- package/transform.mjs +64 -0
- package/verify/.github/workflows/verify-production.yml +71 -0
- package/verify/scripts/release/verify-ops.sh +41 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Check that every commit in a range satisfies the rules for entering main (docs/git-flow.md, 進入 main):
|
|
3
|
+
# one change is one commit, so there are no merge commits; every subject follows Conventional Commits; and
|
|
4
|
+
# no message carries AI-platform attribution (check-commit-body.sh --only attribution).
|
|
5
|
+
# The pre-push hook runs it on the range being pushed; nightly runs it on main's whole first-parent
|
|
6
|
+
# history, catching commits that skipped the hooks with --no-verify. It only reports, never rewrites.
|
|
7
|
+
# The attribution rule holds from the commit that added scripts/ci/ai-attribution-list.txt: a commit whose
|
|
8
|
+
# tree has no list predates the rule, and its message is history that is not rewritten.
|
|
9
|
+
# usage: check-main-commits.sh <rev-range> e.g. origin/main, abc123..def456
|
|
10
|
+
set -euo pipefail
|
|
11
|
+
# check-commit-body.sh needs bash 4; under 3.2 it would fail on every commit and read as attribution
|
|
12
|
+
(( BASH_VERSINFO[0] >= 4 )) || { printf '%s\n' >&2 "✗ 需要 bash 4 以上(目前 ${BASH_VERSION})"; exit 1; }
|
|
13
|
+
range="${1:?usage: check-main-commits.sh <rev-range>}"
|
|
14
|
+
here="$(cd "$(dirname "$0")" && pwd)"
|
|
15
|
+
list=scripts/ci/ai-attribution-list.txt
|
|
16
|
+
bad=0
|
|
17
|
+
while IFS= read -r c; do
|
|
18
|
+
[[ -n "$c" ]] || continue
|
|
19
|
+
printf '%s\n' >&2 "✗ ${c:0:7} 是合併 commit:進 main 用 git merge --squash,一個變更一個 commit"; bad=1
|
|
20
|
+
done < <(git rev-list --first-parent --merges "$range")
|
|
21
|
+
while IFS=$'\t' read -r c subject; do
|
|
22
|
+
[[ -n "$c" ]] || continue
|
|
23
|
+
bash "$here/check-pr-title.sh" "$subject" >/dev/null 2>&1 \
|
|
24
|
+
|| { printf '%s\n' >&2 "✗ ${c:0:7} 的訊息不符 Conventional Commits:$subject"; bad=1; }
|
|
25
|
+
if git cat-file -e "$c:$list" 2>/dev/null; then
|
|
26
|
+
bash "$here/check-commit-body.sh" --only attribution --commit "$c" >/dev/null 2>&1 \
|
|
27
|
+
|| { printf '%s\n' >&2 "✗ ${c:0:7} 的訊息帶 AI 平台署名:${subject}(看是哪一行:bash scripts/ci/check-commit-body.sh --only attribution --commit ${c:0:7})"; bad=1; }
|
|
28
|
+
fi
|
|
29
|
+
done < <(git log --first-parent --no-merges --format=$'%H\t%s' "$range")
|
|
30
|
+
(( bad == 0 )) && printf '%s\n' "✓ $range 的 commit 都符合進 main 的條件"
|
|
31
|
+
exit "$bad"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Conventional Commits check for one title: a PR title (squash-merge makes it the releasable unit) or the
|
|
3
|
+
# subject of a commit entering main. The single source of the rule for ci.yml, the commit-msg and pre-push
|
|
4
|
+
# hooks, and the nightly history check.
|
|
5
|
+
# usage: check-pr-title.sh "<title>" (exit 1 on violation)
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
title="${1:?usage: check-pr-title.sh <title>}"
|
|
8
|
+
re='^(feat|fix|perf|refactor|docs|chore|ci|build|test|deps|revert)(\([a-z0-9./_-]+\))?!?: .+'
|
|
9
|
+
if [[ "$title" =~ $re ]]; then printf '%s\n' "✓ title ok: $title"; else
|
|
10
|
+
printf '%s\n' >&2 "✗ title must follow Conventional Commits (<type>(<scope>): <subject>): $title"; exit 1; fi
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Settings for scripts/ci/ci-scope.sh. The script is the same file in every repository that adopts the
|
|
2
|
+
# flow; what differs between repositories lives here. Patterns are git glob pathspecs: "*" stays within
|
|
3
|
+
# one directory level, "**" crosses levels.
|
|
4
|
+
|
|
5
|
+
# Paths that never change what ci builds or tests. A commit that touches only these skips ci.
|
|
6
|
+
CI_SCOPE_NON_SOURCE=(
|
|
7
|
+
'*.md'
|
|
8
|
+
'**/CHANGELOG.md'
|
|
9
|
+
'**/.release-marker'
|
|
10
|
+
'release-please-config.json'
|
|
11
|
+
'.release-please-manifest.json'
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
# Paths that need the macOS job, and the paths under them that do not. CI_SCOPE_NATIVE_UNITS lists the SwiftPM
|
|
15
|
+
# package directories scripts/ci/native-build.sh builds. A repository without a Swift unit leaves all three empty, and
|
|
16
|
+
# the macOS job never has work. Composing a repository with a Swift unit writes its path here.
|
|
17
|
+
CI_SCOPE_NATIVE=()
|
|
18
|
+
CI_SCOPE_NATIVE_EXCLUDE=()
|
|
19
|
+
CI_SCOPE_NATIVE_UNITS=()
|
|
20
|
+
|
|
21
|
+
# 0: a pull request here checks only the affected units, so its green run does not stand in for the
|
|
22
|
+
# full-tree run of the push that merges it.
|
|
23
|
+
CI_SCOPE_PR_TREE=0
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Decide what this ci run has to check. Writes run=true|false and native=true|false to $GITHUB_OUTPUT
|
|
3
|
+
# and the reason to $GITHUB_STEP_SUMMARY; every other ci job runs only when run=true.
|
|
4
|
+
#
|
|
5
|
+
# A push is compared with the last *successful* ci run on the same branch, never with the previous
|
|
6
|
+
# push: a docs-only commit on top of a red commit still carries the red commit's source change in its
|
|
7
|
+
# diff, so it runs. A run skipped here still concludes success, which is sound because its tree
|
|
8
|
+
# differs from a green one only in non-source paths; the release gates read that success as "the tip
|
|
9
|
+
# is checked". The base never falls back to another branch, because the ci of a branch can be wider
|
|
10
|
+
# than another's (a train adds e2e): a new train with no green run yet runs everything.
|
|
11
|
+
#
|
|
12
|
+
# With CI_SCOPE_PR_TREE=1 a push is also skipped when it is the merge of a pull request whose head has
|
|
13
|
+
# the same tree and a green ci run. Only enable it where the pull request runs the same checks as the
|
|
14
|
+
# push; a pull request that checks only the affected units says nothing about the full tree.
|
|
15
|
+
#
|
|
16
|
+
# Scope looks at source changes only. What a repository has (facts/, release-policy.json, tests/e2e/) is not an
|
|
17
|
+
# output: a job with no work of its own says so and concludes success, and which jobs a repository has follows from
|
|
18
|
+
# its roles when ci.yml is composed.
|
|
19
|
+
#
|
|
20
|
+
# This file is the same in every repository that adopts the flow; what differs lives in
|
|
21
|
+
# scripts/ci/ci-scope.conf.
|
|
22
|
+
#
|
|
23
|
+
# usage: ci-scope.sh
|
|
24
|
+
# env from Actions: EVENT, BRANCH, BASE_REF (pull_request), DEFAULT_BRANCH, REPO, GH_TOKEN
|
|
25
|
+
# needs a checkout with fetch-depth: 0 and a token with actions: read and pull-requests: read
|
|
26
|
+
set -euo pipefail
|
|
27
|
+
cd "$(git rev-parse --show-toplevel)"
|
|
28
|
+
CI_SCOPE_NON_SOURCE=() CI_SCOPE_NATIVE=() CI_SCOPE_NATIVE_EXCLUDE=() CI_SCOPE_NATIVE_UNITS=() CI_SCOPE_PR_TREE=0 CI_SCOPE_WORKFLOW=ci.yml
|
|
29
|
+
# shellcheck source=scripts/ci/ci-scope.conf
|
|
30
|
+
source scripts/ci/ci-scope.conf
|
|
31
|
+
|
|
32
|
+
decide() { # decide <run> <native> <reason>
|
|
33
|
+
printf 'run=%s\nnative=%s\n' "$1" "$2" >> "${GITHUB_OUTPUT:-/dev/null}"
|
|
34
|
+
printf '%s\n' "$3"
|
|
35
|
+
printf '### ci scope\n- run: `%s`, native: `%s`\n- %s\n' "$1" "$2" "$3" >> "${GITHUB_STEP_SUMMARY:-/dev/null}"
|
|
36
|
+
exit 0
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# git pathspecs: the whole tree minus the paths that never change what ci builds or tests
|
|
40
|
+
source_spec=(.)
|
|
41
|
+
for p in "${CI_SCOPE_NON_SOURCE[@]}"; do source_spec+=(":(glob,exclude)$p"); done
|
|
42
|
+
native_spec=()
|
|
43
|
+
for p in "${CI_SCOPE_NATIVE[@]}"; do native_spec+=(":(glob)$p"); done
|
|
44
|
+
for p in "${CI_SCOPE_NATIVE_EXCLUDE[@]}"; do native_spec+=(":(glob,exclude)$p"); done
|
|
45
|
+
|
|
46
|
+
changed() { # changed <base> <pathspec>...: does <base>..HEAD touch these paths
|
|
47
|
+
local base="$1"; shift
|
|
48
|
+
! git diff --quiet "$base" HEAD -- "$@"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
native_since() { # native_since <base>: true|false, true when there is no base to compare with
|
|
52
|
+
(( ${#native_spec[@]} )) || { echo false; return; }
|
|
53
|
+
[[ -n "$1" ]] || { echo true; return; }
|
|
54
|
+
if changed "$1" "${native_spec[@]}"; then echo true; else echo false; fi
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
last_green() { # last_green <branch>: head of the branch's latest successful ci run, when HEAD contains it
|
|
58
|
+
local sha
|
|
59
|
+
sha="$(gh run list --workflow "$CI_SCOPE_WORKFLOW" --branch "$1" --status success --limit 1 \
|
|
60
|
+
--json headSha --jq '.[0].headSha // empty' 2>/dev/null || true)"
|
|
61
|
+
[[ -n "$sha" ]] && git merge-base --is-ancestor "$sha" HEAD 2>/dev/null && printf '%s\n' "$sha"
|
|
62
|
+
return 0
|
|
63
|
+
}
|
|
64
|
+
|
|
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" \
|
|
67
|
+
--jq '[.[] | select(.merged_at != null)][0].head.sha // empty' 2>/dev/null || true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case "${EVENT:?}" in
|
|
71
|
+
pull_request)
|
|
72
|
+
base="$(git merge-base "origin/${BASE_REF:?}" HEAD)"
|
|
73
|
+
why="和 ${BASE_REF} 的共同祖先 ${base:0:7} 比較"
|
|
74
|
+
native_base="$base"
|
|
75
|
+
;;
|
|
76
|
+
push)
|
|
77
|
+
if (( CI_SCOPE_PR_TREE )); then
|
|
78
|
+
head="$(merged_pr_head)"
|
|
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 \
|
|
82
|
+
--json databaseId --jq '.[0].databaseId // empty' 2>/dev/null || true)"
|
|
83
|
+
if [[ "$tree" == "$(git rev-parse 'HEAD^{tree}')" && -n "$green" ]]; then
|
|
84
|
+
decide false false "來源 PR 的 head ${head:0:7} 與 HEAD 同 tree,且 ci run ${green} 已通過"
|
|
85
|
+
fi
|
|
86
|
+
fi
|
|
87
|
+
fi
|
|
88
|
+
base="$(last_green "${BRANCH:?}")"
|
|
89
|
+
[[ -n "$base" ]] || {
|
|
90
|
+
# native keeps its old base so a new branch does not take a macOS slot for nothing
|
|
91
|
+
native_base="$(git merge-base "origin/${DEFAULT_BRANCH:?}" HEAD 2>/dev/null || true)"
|
|
92
|
+
decide true "$(native_since "$native_base")" "${BRANCH} 沒有可比較的成功 ci,全部執行"
|
|
93
|
+
}
|
|
94
|
+
why="和 ${BRANCH} 最近一次成功的 ci ${base:0:7} 比較"
|
|
95
|
+
native_base="$base"
|
|
96
|
+
;;
|
|
97
|
+
*)
|
|
98
|
+
decide true "$( (( ${#native_spec[@]} )) && echo true || echo false )" "${EVENT} 事件一律全部執行"
|
|
99
|
+
;;
|
|
100
|
+
esac
|
|
101
|
+
|
|
102
|
+
if changed "$base" "${source_spec[@]}"; then
|
|
103
|
+
decide true "$(native_since "$native_base")" "${why}:有原始碼變更"
|
|
104
|
+
else
|
|
105
|
+
decide false false "${why}:只改了非原始碼路徑"
|
|
106
|
+
fi
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Native build for a mobile unit. ios / macos are SwiftPM packages: build and test with the Swift
|
|
3
|
+
# toolchain (the ci `native` job runs this on the macOS runner). android stays a stub: a real gradle
|
|
4
|
+
# build needs a JDK and the Android SDK on the runner, which the template does not provision.
|
|
5
|
+
#
|
|
6
|
+
# usage: native-build.sh <product-ios|product-macos|product-android> an app under apps/, as in git-flow-template
|
|
7
|
+
# native-build.sh <dir> a SwiftPM package at <dir> (has a Package.swift)
|
|
8
|
+
# native-build.sh every directory of CI_SCOPE_NATIVE_UNITS in scripts/ci/ci-scope.conf
|
|
9
|
+
set -euo pipefail
|
|
10
|
+
cd "$(git rev-parse --show-toplevel)"
|
|
11
|
+
if (( $# == 0 )); then
|
|
12
|
+
CI_SCOPE_NATIVE_UNITS=()
|
|
13
|
+
# shellcheck source=scripts/ci/ci-scope.conf
|
|
14
|
+
source scripts/ci/ci-scope.conf
|
|
15
|
+
(( ${#CI_SCOPE_NATIVE_UNITS[@]} )) || { printf '%s\n' "native-build:ci-scope.conf 的 CI_SCOPE_NATIVE_UNITS 是空的,沒有原生單元要建置"; exit 0; }
|
|
16
|
+
for unit in "${CI_SCOPE_NATIVE_UNITS[@]}"; do bash "$0" "$unit"; done
|
|
17
|
+
exit 0
|
|
18
|
+
fi
|
|
19
|
+
app="${1:?usage: native-build.sh <product-ios|product-macos|product-android|dir>}"
|
|
20
|
+
# A SwiftPM package of a unit directory (not an app of the template): the same build and test commands,
|
|
21
|
+
# pointed at the package. It has no version.txt, because release-please keeps the version in the manifest.
|
|
22
|
+
if [[ -f "$app/Package.swift" ]]; then
|
|
23
|
+
command -v swift >/dev/null || { printf '%s\n' >&2 "[$app] 找不到 swift 工具鏈:原生建置在 macOS runner 的 ci native job 執行"; exit 1; }
|
|
24
|
+
printf '%s\n' "[$app] swift build + swift test"
|
|
25
|
+
swift build --package-path "$app" && swift test --package-path "$app"
|
|
26
|
+
exit 0
|
|
27
|
+
fi
|
|
28
|
+
dir="$(cd "apps/$app" && pwd)"
|
|
29
|
+
version="$(cat "$dir/version.txt")"
|
|
30
|
+
case "$app" in
|
|
31
|
+
product-ios|product-macos)
|
|
32
|
+
command -v swift >/dev/null || { printf '%s\n' >&2 "[$app] 找不到 swift 工具鏈:原生建置在 macOS runner 的 ci native job 執行"; exit 1; }
|
|
33
|
+
printf '%s\n' "[$app] version ${version}:swift build + swift test"
|
|
34
|
+
( cd "$dir" && swift build -c release && swift test )
|
|
35
|
+
;;
|
|
36
|
+
product-android)
|
|
37
|
+
printf '%s\n' "[product-android] version ${version}:gradle 未接上(runner 需 JDK 與 Android SDK),native/build.gradle 的 versionName 由 release-please 維護"
|
|
38
|
+
;;
|
|
39
|
+
*) printf '%s\n' >&2 "unknown app: $app"; exit 2 ;;
|
|
40
|
+
esac
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Run a workspace script over the affected set (AFFECTED_SINCE set) or the whole tree (unset).
|
|
3
|
+
#
|
|
4
|
+
# Affected = packages changed since AFFECTED_SINCE plus everything depending on them (pnpm's
|
|
5
|
+
# "...[<ref>]"). That set is right for tests but not for builds: a changed package still needs its
|
|
6
|
+
# UPSTREAM packages' dist/*.d.ts to compile (observed 2026-09-09: shared-utils failed with TS2307 on
|
|
7
|
+
# product-shared-types, which was unchanged and therefore unbuilt). WITH_DEPS=1 widens the build to
|
|
8
|
+
# the dependency closure by adding "<name>..." for every affected package.
|
|
9
|
+
#
|
|
10
|
+
# Filters are passed as argv, never through eval: an eval re-parse strips the quotes and lets the
|
|
11
|
+
# shell expand "**/*.md" into file names, which pnpm then took for the script name and ran nothing
|
|
12
|
+
# while exiting 0 (observed 2026-09-09 on the first probe PRs).
|
|
13
|
+
#
|
|
14
|
+
# usage: AFFECTED_SINCE=origin/main [WITH_DEPS=1] scripts/ci/run-affected.sh build
|
|
15
|
+
# scripts/ci/run-affected.sh test # full tree
|
|
16
|
+
set -euo pipefail
|
|
17
|
+
(( $# )) || { printf '%s\n' "usage: run-affected.sh <script> [pnpm flags]" >&2; exit 2; }
|
|
18
|
+
ignore="${CHANGED_IGNORE:-**/*.md}"
|
|
19
|
+
declare -a args=(-r)
|
|
20
|
+
if [[ -z "${AFFECTED_SINCE:-}" ]]; then
|
|
21
|
+
printf '%s\n' "[affected] 全量"
|
|
22
|
+
else
|
|
23
|
+
# The workspace root is dropped in both modes: its build and test scripts are `pnpm -r <script>`,
|
|
24
|
+
# so selecting it re-runs the script over the whole tree. A change confined to root files (scripts/,
|
|
25
|
+
# docs/) selected only the root, and `test` then ran every package against dist/ that the build
|
|
26
|
+
# step had rightly skipped (observed 2026-09-25 on PR #511: libs/product-shared-types "Could not find 'dist/'").
|
|
27
|
+
root_name="$(jq -r '.name' package.json)"
|
|
28
|
+
# A failed listing must stop the job, not read as "nothing affected" and skip it.
|
|
29
|
+
listing="$(pnpm ls -r --depth -1 --json --filter "...[${AFFECTED_SINCE}]" --changed-files-ignore-pattern "$ignore")" \
|
|
30
|
+
|| { printf '%s\n' "[affected] 無法列出 ${AFFECTED_SINCE} 以來的受影響套件" >&2; exit 1; }
|
|
31
|
+
declare -a names=()
|
|
32
|
+
while IFS= read -r n; do
|
|
33
|
+
[[ -n "$n" && "$n" != "$root_name" ]] && names+=("$n")
|
|
34
|
+
done < <(jq -r '.[].name' <<<"$listing")
|
|
35
|
+
if (( ${#names[@]} == 0 )); then printf '%s\n' "[affected] since ${AFFECTED_SINCE}:無受影響套件,略過 $1"; exit 0; fi
|
|
36
|
+
joined="$(IFS=,; printf '%s' "${names[*]}")"; joined="${joined//,/, }"
|
|
37
|
+
# Only in this mode: a PR that touches only a package without this script (templates/) would otherwise fail
|
|
38
|
+
# with ERR_PNPM_RECURSIVE_RUN_NO_SCRIPT. The full tree stays strict, where no package having it means a broken setup.
|
|
39
|
+
args+=(--if-present)
|
|
40
|
+
if [[ "${WITH_DEPS:-0}" == 1 ]]; then
|
|
41
|
+
for n in "${names[@]}"; do args+=(--filter "${n}..."); done
|
|
42
|
+
printf '%s\n' "[affected] since ${AFFECTED_SINCE}:${#names[@]} 個受影響套件及其上游閉包(${joined})"
|
|
43
|
+
else
|
|
44
|
+
for n in "${names[@]}"; do args+=(--filter "$n"); done
|
|
45
|
+
printf '%s\n' "[affected] since ${AFFECTED_SINCE}:${#names[@]} 個變更套件及其下游(${joined})"
|
|
46
|
+
fi
|
|
47
|
+
fi
|
|
48
|
+
exec pnpm "${args[@]}" "$@"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Build or test the units that are not pnpm packages (Python, Rust, Go), from the rows of scripts/ci/units.json that
|
|
3
|
+
# composing the repository wrote. The commands are the ones of the unit's stack, the same ones blueprint's demos.yml
|
|
4
|
+
# runs. Swift units go through the native job, pnpm units through run-affected.sh.
|
|
5
|
+
#
|
|
6
|
+
# Like run-affected.sh, a pull request runs only the units whose directory changed since AFFECTED_SINCE (the base
|
|
7
|
+
# branch), and without AFFECTED_SINCE (a push to main or a train) every unit runs.
|
|
8
|
+
#
|
|
9
|
+
# usage: AFFECTED_SINCE=origin/main scripts/ci/run-units.sh build|test
|
|
10
|
+
# scripts/ci/run-units.sh langs # the languages of the units, comma-separated, for the toolchain steps
|
|
11
|
+
set -euo pipefail
|
|
12
|
+
cd "$(git rev-parse --show-toplevel)"
|
|
13
|
+
units="scripts/ci/units.json"
|
|
14
|
+
mode="${1:?usage: run-units.sh build|test|langs}"
|
|
15
|
+
[[ -f "$units" ]] || { [[ "$mode" == langs ]] || printf '%s\n' "[units] 沒有 ${units},沒有其他語言的單元"; exit 0; }
|
|
16
|
+
case "$mode" in
|
|
17
|
+
langs) jq -r '[.[].lang] | unique | join(",")' "$units"; exit 0 ;;
|
|
18
|
+
build|test) ;;
|
|
19
|
+
*) printf '%s\n' >&2 "usage: run-units.sh build|test|langs"; exit 2 ;;
|
|
20
|
+
esac
|
|
21
|
+
since=""
|
|
22
|
+
[[ -z "${AFFECTED_SINCE:-}" ]] || since="$(git merge-base "$AFFECTED_SINCE" HEAD)"
|
|
23
|
+
ran=0
|
|
24
|
+
while IFS=$'\t' read -r name dir cmd; do
|
|
25
|
+
if [[ -n "$since" ]] && git diff --quiet "$since" HEAD -- "$dir"; then
|
|
26
|
+
printf '%s\n' "[units] ${name}:${dir} 自 ${AFFECTED_SINCE} 沒有變更,略過 ${mode}"
|
|
27
|
+
continue
|
|
28
|
+
fi
|
|
29
|
+
printf '%s\n' "[units] ${name}:${mode}"
|
|
30
|
+
bash -c "$cmd"
|
|
31
|
+
ran=$((ran + 1))
|
|
32
|
+
done < <(jq -r --arg mode "$mode" '.[] | [.unit, .dir, .[$mode]] | @tsv' "$units")
|
|
33
|
+
printf '%s\n' "[units] ${ran} 個單元執行了 ${mode}"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Message rules for a commit (docs/git-flow.md, commit 與 PR 訊息格式).
|
|
3
|
+
# Every branch: no AI-platform attribution. The rule covers every commit and PR, not only main.
|
|
4
|
+
# On main, where a local squash merge (git merge --squash, then git commit) writes the commit
|
|
5
|
+
# release-please will read: the subject follows Conventional Commits (condition 2 for entering main),
|
|
6
|
+
# and a commit whose staged files span two or more release units declares Coupled-Change: in its last
|
|
7
|
+
# paragraph.
|
|
8
|
+
# Other branches are otherwise free: their commits never reach main, the PR title and body or the squash
|
|
9
|
+
# commit does. git commit --amend on main compares the index with the commit being amended, so units that
|
|
10
|
+
# commit already touched are not counted here; the pre-push hook checks every pushed commit whole.
|
|
11
|
+
# The checks need bash 4 (scripts/lib/common.sh); macOS ships 3.2 as /bin/bash. A branch commit never
|
|
12
|
+
# reaches main, so there an old bash only warns; on main the commit is held back, since an unchecked
|
|
13
|
+
# message there is what release-please reads. This file itself stays bash 3.2 compatible.
|
|
14
|
+
set -euo pipefail
|
|
15
|
+
root="$(git rev-parse --show-toplevel)"
|
|
16
|
+
branch="$(git branch --show-current)"
|
|
17
|
+
if (( BASH_VERSINFO[0] < 4 )); then
|
|
18
|
+
if [[ "$branch" != main ]]; then
|
|
19
|
+
printf '%s\n' >&2 "commit-msg:目前的 bash 是 ${BASH_VERSION},訊息檢查要 bash 4 以上,這次略過。用 brew install bash 安裝新版,並讓 PATH 裡的 bash 指向它。"
|
|
20
|
+
exit 0
|
|
21
|
+
fi
|
|
22
|
+
printf '%s\n' >&2 "commit-msg:沒有提交。main 上的 commit 要用 bash 4 以上檢查訊息,目前是 ${BASH_VERSION}。macOS 內建的 /bin/bash 是 3.2,用 brew install bash 安裝新版,並讓 PATH 裡的 bash 指向它。"
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
25
|
+
if [[ "$branch" != main ]]; then
|
|
26
|
+
bash "$root/scripts/ci/check-commit-body.sh" --only attribution --message "$1" >/dev/null || {
|
|
27
|
+
printf '%s\n' >&2 "commit-msg:commit 訊息不加 AI 平台署名"; exit 1; }
|
|
28
|
+
exit 0
|
|
29
|
+
fi
|
|
30
|
+
subject="$(grep -v '^#' "$1" | head -n1)"
|
|
31
|
+
bash "$root/scripts/ci/check-pr-title.sh" "$subject" >/dev/null || {
|
|
32
|
+
printf '%s\n' >&2 "commit-msg:main 上的 commit 訊息要符合 Conventional Commits,release-please 依它計算版號"
|
|
33
|
+
exit 1
|
|
34
|
+
}
|
|
35
|
+
bash "$root/scripts/ci/check-commit-body.sh" --message "$1" --cached >/dev/null || {
|
|
36
|
+
printf '%s\n' >&2 "commit-msg:沒有提交。照上面的原因改訊息或拆開變更,不用 --no-verify 跳過"
|
|
37
|
+
exit 1
|
|
38
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Local lane into main (docs/git-flow.md, 進入 main). A push to main is allowed when the pushed commits
|
|
3
|
+
# 1. are one change each (no merge commits), follow Conventional Commits and carry no AI-platform
|
|
4
|
+
# attribution (check-main-commits.sh),
|
|
5
|
+
# 2. each touch one release unit, or declare Coupled-Change: in the last paragraph
|
|
6
|
+
# (check-commit-body.sh --only units),
|
|
7
|
+
# 3. contain no change that must go through a PR: release governance paths (.github/CODEOWNERS) or a
|
|
8
|
+
# breaking change ("!" or a BREAKING CHANGE footer), and
|
|
9
|
+
# 4. pass lint, build and tests over the affected packages (scripts/ci/run-affected.sh).
|
|
10
|
+
# Pushes to other branches are not checked here; release/* is written by the release scripts, and a human
|
|
11
|
+
# change to it goes through a PR. Skipping with --no-verify is caught by the nightly history check.
|
|
12
|
+
set -euo pipefail
|
|
13
|
+
root="$(git rev-parse --show-toplevel)"
|
|
14
|
+
cd "$root"
|
|
15
|
+
zero=0000000000000000000000000000000000000000
|
|
16
|
+
|
|
17
|
+
# CODEOWNERS patterns as shell globs: a leading "/" anchors at the root, a trailing "/" means everything below.
|
|
18
|
+
governed() { # governed <file>
|
|
19
|
+
local f="$1" p
|
|
20
|
+
while read -r p _; do
|
|
21
|
+
[[ -z "$p" || "$p" == \#* ]] && continue
|
|
22
|
+
p="${p#/}"; [[ "$p" == */ ]] && p="$p*"
|
|
23
|
+
# shellcheck disable=SC2053
|
|
24
|
+
[[ "$f" == $p ]] && return 0
|
|
25
|
+
done < .github/CODEOWNERS
|
|
26
|
+
return 1
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
status=0
|
|
30
|
+
while read -r _ local_sha remote_ref remote_sha; do
|
|
31
|
+
[[ "$remote_ref" == refs/heads/main && "$local_sha" != "$zero" ]] || continue
|
|
32
|
+
[[ "$remote_sha" != "$zero" ]] || { printf '%s\n' >&2 "pre-push:遠端還沒有 main,略過檢查"; continue; }
|
|
33
|
+
range="$remote_sha..$local_sha"
|
|
34
|
+
# the checks below need bash 4 (scripts/lib/common.sh); macOS ships 3.2 as /bin/bash
|
|
35
|
+
if (( BASH_VERSINFO[0] < 4 )); then
|
|
36
|
+
printf '%s\n' >&2 "pre-push:推上 main 要用 bash 4 以上檢查,目前是 ${BASH_VERSION}。用 brew install bash 安裝新版,並讓 PATH 裡的 bash 指向它。"
|
|
37
|
+
status=1; break
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
bash scripts/ci/check-main-commits.sh "$range" || status=1
|
|
41
|
+
while IFS= read -r c; do
|
|
42
|
+
[[ -n "$c" ]] || continue
|
|
43
|
+
bash scripts/ci/check-commit-body.sh --only units --commit "$c" >/dev/null \
|
|
44
|
+
|| { printf '%s\n' >&2 " ↑ ${c:0:7} $(git log -1 --format=%s "$c")"; status=1; }
|
|
45
|
+
done < <(git rev-list --no-merges "$range")
|
|
46
|
+
|
|
47
|
+
while IFS= read -r f; do
|
|
48
|
+
[[ -n "$f" ]] && governed "$f" && { printf '%s\n' >&2 "✗ $f 是發布治理路徑(.github/CODEOWNERS),這個變更要走 PR"; status=1; }
|
|
49
|
+
done < <(git diff --name-only "$range")
|
|
50
|
+
while IFS=$'\t' read -r c subject; do
|
|
51
|
+
[[ -n "$c" ]] || continue
|
|
52
|
+
if [[ "$subject" =~ ^[a-z]+(\([^\)]*\))?!: ]] || git log -1 --format=%b "$c" | grep -qE '^BREAKING[ -]CHANGE:'; then
|
|
53
|
+
printf '%s\n' >&2 "✗ ${c:0:7} 是破壞性變更,會跳主版,要走 PR 留下討論紀錄"; status=1
|
|
54
|
+
fi
|
|
55
|
+
done < <(git log --no-merges --format=$'%H\t%s' "$range")
|
|
56
|
+
(( status == 0 )) || break
|
|
57
|
+
|
|
58
|
+
printf '%s\n' "pre-push:lint、建置與測試受影響範圍(since ${remote_sha:0:7})"
|
|
59
|
+
pnpm lint && AFFECTED_SINCE="$remote_sha" WITH_DEPS=1 bash scripts/ci/run-affected.sh build \
|
|
60
|
+
&& AFFECTED_SINCE="$remote_sha" bash scripts/ci/run-affected.sh test || status=1
|
|
61
|
+
done
|
|
62
|
+
(( status == 0 )) || printf '%s\n' >&2 "pre-push:沒有推送。一定走 PR 的變更改開 PR,其餘修正後再推。"
|
|
63
|
+
exit "$status"
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Shared helpers for release / scenario scripts. Source it; do not execute.
|
|
3
|
+
# DRY_RUN=1 print every mutating command instead of running it
|
|
4
|
+
# ASSUME_YES=1 skip the interactive confirmation for external writes (CI / scenario --yes)
|
|
5
|
+
# TASK_DIR where external-ops.log lives (default tmp/<today>-git-flow-sim)
|
|
6
|
+
# A script that skipped any external write (declined, or no terminal to answer the prompt) lists the
|
|
7
|
+
# skipped writes and exits 3 even when everything else succeeded, outside DRY_RUN.
|
|
8
|
+
set -euo pipefail
|
|
9
|
+
|
|
10
|
+
# mapfile and associative arrays are bash 4; macOS still ships 3.2 as /bin/bash, so say so plainly
|
|
11
|
+
# rather than failing later with a confusing parse error.
|
|
12
|
+
if (( BASH_VERSINFO[0] < 4 )); then
|
|
13
|
+
printf '%s\n' "✗ 需要 bash 4 以上(目前 ${BASH_VERSION});macOS 內建的 /bin/bash 是 3.2,請以 brew install bash 安裝後再跑" >&2
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"
|
|
18
|
+
DRY_RUN="${DRY_RUN:-0}"
|
|
19
|
+
ASSUME_YES="${ASSUME_YES:-0}"
|
|
20
|
+
TASK_DIR="${TASK_DIR:-$REPO_ROOT/tmp/$(date +%Y-%m-%d)-git-flow-sim}"
|
|
21
|
+
AUDIT_LOG="$TASK_DIR/external-ops.log"
|
|
22
|
+
CONFIG="release-please-config.json"
|
|
23
|
+
MANIFEST=".release-please-manifest.json"
|
|
24
|
+
|
|
25
|
+
log() { printf '%s\n' "→ $*"; }
|
|
26
|
+
info() { printf '%s\n' " $*"; }
|
|
27
|
+
warn() { printf '%s\n' "! $*" >&2; }
|
|
28
|
+
die() { printf '%s\n' "✗ $*" >&2; exit 1; }
|
|
29
|
+
|
|
30
|
+
# bash has no array-membership operator, and open-coding the loop at each call site is where
|
|
31
|
+
# unquoted-expansion bugs creep in, so every membership test goes through this one helper.
|
|
32
|
+
in_array() { # in_array <needle> <haystack>...
|
|
33
|
+
local needle="$1"; shift
|
|
34
|
+
local item
|
|
35
|
+
for item in "$@"; do [[ "$item" == "$needle" ]] && return 0; done
|
|
36
|
+
return 1
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# run a local (reversible) command; printed only under DRY_RUN
|
|
40
|
+
run() {
|
|
41
|
+
if (( DRY_RUN )); then printf '%s\n' " [dry-run] $*"; else printf '%s\n' " \$ $*"; "$@"; fi
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# external write gate (execute-external per external-operation-guard): returns 0 to proceed
|
|
45
|
+
confirm_external() {
|
|
46
|
+
local target="$1" op="$2"
|
|
47
|
+
printf '%s\n' "外部寫入(execute-external):$op → $target"
|
|
48
|
+
if (( DRY_RUN )); then printf '%s\n' " [dry-run] 不執行"; return 1; fi
|
|
49
|
+
if (( ASSUME_YES )); then printf '%s\n' " ASSUME_YES=1,視為已確認"; return 0; fi
|
|
50
|
+
local reply
|
|
51
|
+
read -r -n1 -p " 確認執行?[y/N] " reply || true
|
|
52
|
+
printf '\n'
|
|
53
|
+
[[ "$reply" == "y" ]]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# audit <target> <op> <result> — one line, four pipe-delimited fields.
|
|
57
|
+
# The operation text is flattened and truncated: PR bodies carry newlines and "|" (markdown tables),
|
|
58
|
+
# which would otherwise break the one-record-per-line format and make the log unparsable.
|
|
59
|
+
audit() {
|
|
60
|
+
local op="${2//$'\n'/ ⏎ }"
|
|
61
|
+
op="${op//|//}"
|
|
62
|
+
(( ${#op} > 300 )) && op="${op:0:300}…"
|
|
63
|
+
mkdir -p "$TASK_DIR"
|
|
64
|
+
printf '%s\n' "$(date '+%Y-%m-%d %H:%M') | $1 | $op | $3" >> "$AUDIT_LOG"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# A declined write returns 0 so the script runs to the end, but a run that skipped a push and exited 0
|
|
68
|
+
# reads as "pushed": a caller without a terminal (an agent, CI without --yes) declines every prompt
|
|
69
|
+
# silently. So skipped writes are collected and the exit trap reports them and turns the status into 3.
|
|
70
|
+
SKIPPED_EXTERNAL=()
|
|
71
|
+
skip_external() { # skip_external <target> <op>
|
|
72
|
+
SKIPPED_EXTERNAL+=("$1:$2")
|
|
73
|
+
log "跳過:$2"
|
|
74
|
+
}
|
|
75
|
+
report_skipped_external() {
|
|
76
|
+
local rc=$? op
|
|
77
|
+
(( DRY_RUN == 0 && ${#SKIPPED_EXTERNAL[@]} )) || return "$rc"
|
|
78
|
+
printf '\n%s\n' "✗ 有 ${#SKIPPED_EXTERNAL[@]} 個外部寫入沒有執行,遠端還沒有這些變更:" >&2
|
|
79
|
+
for op in "${SKIPPED_EXTERNAL[@]}"; do printf '%s\n' " - $op" >&2; done
|
|
80
|
+
printf '%s\n' " 確認後帶 --yes 重跑,或手動執行上面的指令" >&2
|
|
81
|
+
(( rc == 0 )) && exit 3
|
|
82
|
+
return "$rc"
|
|
83
|
+
}
|
|
84
|
+
trap report_skipped_external EXIT
|
|
85
|
+
|
|
86
|
+
# external command wrapped with confirmation + audit: external <target> <cmd...>
|
|
87
|
+
external() {
|
|
88
|
+
local target="$1"; shift
|
|
89
|
+
if confirm_external "$target" "$*"; then
|
|
90
|
+
if "$@"; then audit "$target" "$*" success; else audit "$target" "$*" failure; return 1; fi
|
|
91
|
+
else
|
|
92
|
+
skip_external "$target" "$*"
|
|
93
|
+
return 0
|
|
94
|
+
fi
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Same gate as external(), but asks again after a transient error through retry.mjs (decision transient-error-shared-retry), which
|
|
98
|
+
# decides by the kind. push: HTTP 500, 502, 503, 504 and a connect timeout, never a force or a delete. merge: those, and GitHub's
|
|
99
|
+
# "Base branch was modified", which happens routinely here when a staging deploy writes the ops declaration back to main while a feature
|
|
100
|
+
# PR is in flight. The merge and a plain push are safe to repeat, so retry rather than abort the run. 5 rounds, RETRY_SLEEP seconds apart (5).
|
|
101
|
+
RETRY_MJS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/retry.mjs"
|
|
102
|
+
external_retry() { # external_retry <push|merge> <target> <cmd>...
|
|
103
|
+
local kind="$1" target="$2"; shift 2
|
|
104
|
+
if ! confirm_external "$target" "$*"; then skip_external "$target" "$*"; return 0; fi
|
|
105
|
+
if node "$RETRY_MJS" "$kind" -- "$@"; then audit "$target" "$*" success; return 0; fi
|
|
106
|
+
audit "$target" "$*" failure
|
|
107
|
+
return 1
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
remote_target() { git remote get-url origin 2>/dev/null | sed -E 's#(git@|https://)([^/:]+)[:/]#\2/#; s#\.git$##; s#^[^@]+@##'; }
|
|
111
|
+
|
|
112
|
+
require_clean_tree() {
|
|
113
|
+
[[ -z "$(git status --porcelain)" ]] && return 0
|
|
114
|
+
if (( DRY_RUN )); then warn "工作區不乾淨(dry-run 下僅警告)"; return 0; fi
|
|
115
|
+
die "工作區不乾淨,先 commit 或 stash"
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
current_branch() { git branch --show-current; }
|
|
119
|
+
|
|
120
|
+
release_branches() { git branch -r --list 'origin/release/*' | sed 's#.*origin/##'; }
|
|
121
|
+
|
|
122
|
+
unit_path() { # unit_path product-web -> apps/product-web; a config entry whose component differs from its folder wins
|
|
123
|
+
local u="$1" p
|
|
124
|
+
p="$(jq -r --arg u "$u" '.packages | to_entries[] | select(.value.component == $u) | .key' "$CONFIG" 2>/dev/null | head -1)"
|
|
125
|
+
if [[ -n "$p" && -d "$p" ]]; then printf '%s\n' "$p"
|
|
126
|
+
elif [[ -d "apps/$u" ]]; then printf '%s\n' "apps/$u"
|
|
127
|
+
elif [[ -d "packages/$u" ]]; then printf '%s\n' "packages/$u"
|
|
128
|
+
elif [[ -d "libs/$u" ]]; then printf '%s\n' "libs/$u"
|
|
129
|
+
else return 1; fi
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
unit_component() { # unit_component packages/cli -> mainflow; the folder name when the config sets no component
|
|
133
|
+
local p="${1%/}" c
|
|
134
|
+
c="$(jq -r --arg p "$p" '.packages[$p].component // empty' "$CONFIG" 2>/dev/null)"
|
|
135
|
+
printf '%s\n' "${c:-${p##*/}}"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# whether the unit has shipped before: release-please only applies its versioning strategy on top of a
|
|
139
|
+
# previous release; without one it takes initial-version verbatim (1.0.0 when unset).
|
|
140
|
+
# The answer comes from the tags on origin, not the local ones: fetching tags never deletes a tag that was
|
|
141
|
+
# removed on the remote, so a local tag can outlive the release it stood for. When ls-remote fails (network,
|
|
142
|
+
# permission, credentials) the script stops and prints git's error; "no tag" must never be a guess.
|
|
143
|
+
# Call it in the shell itself, not in $(...), so the stop ends the script.
|
|
144
|
+
unit_released() {
|
|
145
|
+
local out
|
|
146
|
+
out="$(git ls-remote --tags origin "refs/tags/$1/v*" 2>&1)" \
|
|
147
|
+
|| die "查遠端 tag 失敗,無法判斷 $1 發過版沒有(git ls-remote --tags origin):$out"
|
|
148
|
+
[[ -n "$out" ]]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
manifest_version() { jq -r --arg p "$1" '.[$p] // empty' "$MANIFEST"; }
|
|
152
|
+
|
|
153
|
+
# strip a prerelease suffix: 1.2.0-rc.3 → 1.2.0
|
|
154
|
+
stable_version() { printf '%s\n' "${1%%-*}"; }
|
|
155
|
+
|
|
156
|
+
# units listed in the config on <ref> (default: working tree), by component name when one is set
|
|
157
|
+
# shellcheck disable=SC2120 # <ref> is optional; most callers read the working tree
|
|
158
|
+
config_units() {
|
|
159
|
+
local q='.packages | to_entries[] | (.value.component // (.key | split("/")[1]))'
|
|
160
|
+
if [[ -n "${1:-}" ]]; then git show "$1:$CONFIG" | jq -r "$q"
|
|
161
|
+
else jq -r "$q" "$CONFIG"; fi
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
# linked-versions binds a group of components to a single version, so a train shipping any member
|
|
165
|
+
# must carry the whole group: the plugin cannot bump components that are absent from the scoped
|
|
166
|
+
# config. Returns every component of every group containing one of the given units.
|
|
167
|
+
linked_group_members() { # linked_group_members <unit>... → component names (may be empty)
|
|
168
|
+
local u
|
|
169
|
+
for u in "$@"; do
|
|
170
|
+
jq -r --arg u "$u" '
|
|
171
|
+
(.plugins // [])[]
|
|
172
|
+
| select(.type == "linked-versions")
|
|
173
|
+
| select((.components // []) | index($u))
|
|
174
|
+
| .components[]
|
|
175
|
+
' "$CONFIG" 2>/dev/null
|
|
176
|
+
done | sort -u
|
|
177
|
+
return 0
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
# Workspace dependents of the given units, transitively. release-please's node-workspace plugin can
|
|
181
|
+
# only bump packages that are in the config, so a train that ships a package must also carry whatever
|
|
182
|
+
# depends on it — otherwise the dependents keep pointing at a version that no longer matches. For the
|
|
183
|
+
# same reason only directories the config lists count: an unregistered package is not a unit, and
|
|
184
|
+
# release-please would neither bump nor tag it.
|
|
185
|
+
workspace_dependents() { # workspace_dependents <unit>... → dependent unit names (may be empty)
|
|
186
|
+
local d u p pkgname dn
|
|
187
|
+
local -a frontier=("$@") found=()
|
|
188
|
+
while (( ${#frontier[@]} )); do
|
|
189
|
+
u="${frontier[0]}"; frontier=("${frontier[@]:1}")
|
|
190
|
+
p="$(unit_path "$u" 2>/dev/null)" || continue
|
|
191
|
+
# a unit with no package.json (python, rust) is not a node package, so no node unit depends on it.
|
|
192
|
+
# Reading its package.json anyway makes jq fail, and under set -e that ends the whole function.
|
|
193
|
+
[[ -f "$p/package.json" ]] || continue
|
|
194
|
+
pkgname="$(jq -r '.name // empty' "$p/package.json")"
|
|
195
|
+
[[ -n "$pkgname" ]] || continue
|
|
196
|
+
# the directories come from the config, not from a fixed list of parents, so a package under services/
|
|
197
|
+
# is found as well as one under apps/ or packages/
|
|
198
|
+
while IFS= read -r d; do
|
|
199
|
+
[[ -n "$d" && -f "$d/package.json" ]] || continue
|
|
200
|
+
dn="$(unit_component "$d")"
|
|
201
|
+
[[ "$dn" == "$u" ]] && continue
|
|
202
|
+
if jq -e --arg n "$pkgname" '((.dependencies // {}) + (.peerDependencies // {})) | has($n)' "$d/package.json" >/dev/null 2>&1; then
|
|
203
|
+
in_array "$dn" "${found[@]:-}" || { found+=("$dn"); frontier+=("$dn"); }
|
|
204
|
+
fi
|
|
205
|
+
done < <(jq -r '.packages // {} | keys[]' "$CONFIG" 2>/dev/null)
|
|
206
|
+
done
|
|
207
|
+
# one per line: callers split on newlines, and a space-separated list would arrive as a single
|
|
208
|
+
# bogus unit name
|
|
209
|
+
(( ${#found[@]} )) && printf '%s\n' "${found[@]}"
|
|
210
|
+
return 0
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
# Units this train actually shipped: the manifest entries that differ from main's. Derived rather
|
|
214
|
+
# than read from the config, because merge-back restores the config from main and would otherwise
|
|
215
|
+
# lose the train scope, making the phase impossible to re-run.
|
|
216
|
+
train_units_by_manifest() {
|
|
217
|
+
local p
|
|
218
|
+
while IFS= read -r p; do [[ -n "$p" ]] && unit_component "$p"; done < <(
|
|
219
|
+
jq -s -r '.[0] as $main | .[1] | to_entries[] | select(.value != $main[.key]) | .key' \
|
|
220
|
+
<(git show origin/main:"$MANIFEST") "$MANIFEST")
|
|
221
|
+
return 0
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
# The libraries below belong to the release template. A repository composed from the base role alone does not
|
|
225
|
+
# have them, so each is sourced only when present (the message checks need nothing from them).
|
|
226
|
+
for _lib in release-stages release-plan release-pr facts docs; do
|
|
227
|
+
# release-stages: stages and the policy file; release-plan: Release Plans, the only source of product
|
|
228
|
+
# versions; release-pr: waiting for and merging the Release PR; facts: fact-kit steps; docs: pinning the
|
|
229
|
+
# "next" of docs/**/*.doc.ts
|
|
230
|
+
# shellcheck source=/dev/null
|
|
231
|
+
if [[ -f "$(dirname "${BASH_SOURCE[0]}")/${_lib}.sh" ]]; then source "$(dirname "${BASH_SOURCE[0]}")/${_lib}.sh"; fi
|
|
232
|
+
done
|
|
233
|
+
unset _lib
|