blueprint-shared-templates 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/base/.github/ISSUE_TEMPLATE/bug.yml +2 -2
  2. package/base/.github/ISSUE_TEMPLATE/hotfix.yml +1 -1
  3. package/base/.github/actions/setup-workspace/action.yml +2 -2
  4. package/base/.github/workflows/auto-merge.yml +4 -0
  5. package/base/.github/workflows/ci.yml +21 -1
  6. package/base/scripts/ci/run-affected.sh +6 -0
  7. package/base/scripts/lib/common.sh +1 -1
  8. package/base/scripts/lib/retry.mjs +36 -6
  9. package/base/scripts/merge/decide.mjs +30 -15
  10. package/deploy/.github/workflows/deploy-prerelease.yml +6 -50
  11. package/deploy/.github/workflows/deploy-prod.yml +103 -0
  12. package/deploy/scripts/deploy/plan-prod.sh +57 -0
  13. package/deploy/scripts/deploy/promote.sh +23 -7
  14. package/deploy/scripts/deploy/publish-bundle.sh +10 -1
  15. package/deploy/scripts/deploy/route-tag.sh +10 -12
  16. package/deploy/scripts/deploy/run-prerelease.sh +4 -7
  17. package/deploy/scripts/deploy/{run-production.sh → run-prod.sh} +15 -17
  18. package/deploy/scripts/deploy/writeback-ops.sh +71 -40
  19. package/hub/scripts/release/dispatch-release-lines.sh +25 -2
  20. package/hub/scripts/release/snapshot-members.sh +1 -1
  21. package/ops/.github/workflows/ops-deploy.yml +92 -11
  22. package/ops/schemas/targets.schema.json +209 -0
  23. package/ops/scripts/ci/check-targets.mjs +291 -0
  24. package/ops/scripts/deploy/apply-iac.sh +89 -0
  25. package/ops/scripts/deploy/apply-ops.sh +101 -48
  26. package/ops/scripts/deploy/ops-run.sh +50 -12
  27. package/ops/scripts/deploy/smoke.sh +35 -16
  28. package/ops/scripts/lib/ops-steps.sh +75 -0
  29. package/org/scripts/ci/check-org-values.mjs +91 -0
  30. package/package.json +2 -2
  31. package/publish/.github/workflows/publish.yml +12 -3
  32. package/publish/scripts/release/mirror-units.sh +45 -5
  33. package/publish/scripts/release/publish-units.sh +28 -4
  34. package/release/.github/workflows/advance-release.yml +107 -0
  35. package/release/.github/workflows/close-release.yml +133 -0
  36. package/release/.github/workflows/merge-back.yml +82 -0
  37. package/release/.github/workflows/merge-release-pr.yml +82 -0
  38. package/release/.github/workflows/open-release-line.yml +14 -5
  39. package/release/.github/workflows/release-line-finalize.yml +5 -3
  40. package/release/.github/workflows/release-please.yml +99 -15
  41. package/release/.github/workflows/sync-release-tools.yml +91 -0
  42. package/release/release-policy.json +1 -1
  43. package/release/schemas/release-policy.schema.json +13 -3
  44. package/release/scripts/ci/branch-exists.sh +27 -0
  45. package/release/scripts/ci/check-release-policy.sh +13 -2
  46. package/release/scripts/ci/pin-train.sh +5 -3
  47. package/release/scripts/ci/release-train.sh +22 -3
  48. package/release/scripts/lib/release-plan.sh +3 -1
  49. package/release/scripts/lib/release-pr.sh +275 -11
  50. package/release/scripts/lib/release-stages.sh +245 -27
  51. package/release/scripts/release/check-trigger-actor.sh +32 -0
  52. package/release/scripts/release/close-ready.mjs +72 -0
  53. package/release/scripts/release/close-ready.sh +70 -0
  54. package/release/scripts/release/cut-release.sh +34 -3
  55. package/release/scripts/release/ensure-stage-deploys.sh +3 -3
  56. package/release/scripts/release/finalize-release.sh +47 -15
  57. package/release/scripts/release/merge-back-ready.sh +27 -0
  58. package/release/scripts/release/merge-release-pr.sh +34 -107
  59. package/release/scripts/release/open-release-line.sh +28 -8
  60. package/release/scripts/release/pin-release-pr.sh +53 -0
  61. package/release/scripts/release/product-release-notes.sh +28 -0
  62. package/release/scripts/release/sync-release-tools.sh +137 -0
  63. package/release/scripts/release/{verify-production.sh → verify-prod.sh} +11 -10
  64. package/transform.mjs +2 -3
  65. package/verify/.github/workflows/{verify-production.yml → verify-prod.yml} +7 -7
  66. package/verify/scripts/release/verify-ops.sh +4 -4
  67. package/deploy/.github/workflows/deploy-production.yml +0 -173
  68. package/deploy/scripts/deploy/plan-production.sh +0 -43
  69. package/infra/.github/workflows/deploy-prerelease.yml +0 -157
  70. package/infra/.github/workflows/deploy-production.yml +0 -173
  71. package/infra/scripts/deploy/apply-infra.sh +0 -46
  72. package/infra/scripts/deploy/apply-prerelease.sh +0 -22
  73. package/infra/scripts/deploy/apply-production.sh +0 -33
  74. package/infra/scripts/deploy/route-tag.sh +0 -65
@@ -1,173 +0,0 @@
1
- name: deploy-production
2
-
3
- # 這份檔在 deploy 與 infra 兩個角色的目錄各有一份,內容相同。倉有哪個角色,就留下那個角色的 job(compose 的角色區塊 # @if)。
4
- # 產品 tag 是唯一的上線閘門,逐單元的正式 tag 不觸發,因此本版所有單元有單一的上線時刻。
5
- # @if deploy
6
- # release job 一次把本版全部入版單元用 GA 版號重建 bundle,掛在產品 tag 的 GitHub Release,再一起寫進 production 的 ops 宣告。
7
- # 入版單元由 manifest 與前一個產品 tag 的差異推導,不需另行維護清單。
8
- # 不沿用 rc 的 bundle:版號寫在 bundle 裡,rc 的 bundle 寫 rc 的版號,GA 要重建(decision ga-rebuild-bundle)。
9
- # 這個 job 不呼叫 wrangler,也不讀 Cloudflare 的憑證。
10
- # @end
11
- # @if infra
12
- # infra job 一次把本版全部 infra 單元套用到 production:用 wrangler 建立單元宣告的 R2 bucket(scripts/deploy/apply-production.sh)。
13
- # 套用可以重複執行,已存在的 bucket 視為已套用。
14
- # @end
15
- # 兩個角色都有的倉(monorepo)先跑 infra job,release job 用 needs 等它成功才跑,因為 bucket 要在綁定它的 Worker 上線前存在
16
- # (decision monorepo-release-align)。
17
-
18
- on:
19
- push:
20
- tags: ["v[0-9]*"]
21
- workflow_dispatch:
22
- inputs:
23
- tag:
24
- description: "product tag, e.g. v1.3.0"
25
- required: true
26
- type: string
27
-
28
- permissions:
29
- contents: read
30
-
31
- defaults:
32
- run:
33
- shell: bash
34
-
35
- concurrency:
36
- group: deploy-production
37
- cancel-in-progress: false
38
-
39
- env:
40
- # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
41
- POLL_TRIES: "2"
42
- CI_GATE_TRIES: "2"
43
- CI_GATE_QUEUE_TRIES: "0"
44
-
45
- jobs:
46
- # @if infra
47
- infra:
48
- # production 只能由產品 tag 套用。免費方案的 private repo 用不了 environment 的 deployment branches
49
- # and tags,所以由這裡核對:觸發的 ref 必須是 tag,且要套用的 tag 是 v<數字>開頭的產品 tag。
50
- # 這個檢查寫在 workflow 裡,改 workflow 就能繞過;GitHub 強制的白名單需要 public repo 或 Pro/Team。
51
- # scripts/deploy/apply-production.sh 會再核對一次 tag 的格式。
52
- if: >-
53
- vars.DEPLOY_ENABLED == 'true'
54
- && startsWith(github.ref, 'refs/tags/v')
55
- && (
56
- startsWith(inputs.tag || github.ref_name, 'v0') ||
57
- startsWith(inputs.tag || github.ref_name, 'v1') ||
58
- startsWith(inputs.tag || github.ref_name, 'v2') ||
59
- startsWith(inputs.tag || github.ref_name, 'v3') ||
60
- startsWith(inputs.tag || github.ref_name, 'v4') ||
61
- startsWith(inputs.tag || github.ref_name, 'v5') ||
62
- startsWith(inputs.tag || github.ref_name, 'v6') ||
63
- startsWith(inputs.tag || github.ref_name, 'v7') ||
64
- startsWith(inputs.tag || github.ref_name, 'v8') ||
65
- startsWith(inputs.tag || github.ref_name, 'v9')
66
- )
67
- runs-on: self-hosted-linux
68
- timeout-minutes: 20
69
- steps:
70
- - uses: actions/checkout@v7
71
- with:
72
- ref: ${{ inputs.tag || github.ref_name }}
73
- fetch-depth: 0
74
- - uses: ./.github/actions/setup-workspace
75
- with:
76
- restore-from-default: "scripts"
77
- - name: 套用本版 infra 單元宣告的 R2 bucket 到 production
78
- run: bash scripts/deploy/apply-production.sh "$TAG"
79
- env:
80
- TAG: ${{ inputs.tag || github.ref_name }}
81
- CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
82
- CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
83
- DEPLOY_LOG_DIR: ${{ runner.temp }}/deploy-log
84
- - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
85
- if: always()
86
- with:
87
- name: apply-production-${{ inputs.tag || github.ref_name }}
88
- path: ${{ runner.temp }}/deploy-log
89
- if-no-files-found: ignore
90
- retention-days: 7
91
- # @end
92
-
93
- # @if deploy
94
- release:
95
- # @end
96
- # @if deploy+infra
97
- needs: infra
98
- # @end
99
- # @if deploy
100
- # production 只能由產品 tag 部署。免費方案的 private repo 用不了 environment 的 deployment branches
101
- # and tags,所以由這裡核對:觸發的 ref 必須是 tag,且要部署的 tag 是 v<數字>開頭的產品 tag。
102
- # 這個檢查寫在 workflow 裡,改 workflow 就能繞過;GitHub 強制的白名單需要 public repo 或 Pro/Team。
103
- # scripts/deploy/run-production.sh 會再核對一次 tag 的格式。
104
- # 兩個角色都有的倉:infra 被 skipped(DEPLOY_ENABLED 不是 true)時,沒有狀態函式的下游 job 也跟著 skipped,
105
- # 所以那個倉的 if 用 !cancelled() 讓 release 照條件判斷,infra 失敗時仍不跑。只有 deploy 角色的倉沒有 infra job,那版的 if 不依賴 infra。
106
- if: >-
107
- # @end
108
- # @if deploy+infra
109
- needs.infra.result != 'failure' && !cancelled() &&
110
- # @end
111
- # @if deploy
112
- startsWith(github.ref, 'refs/tags/v')
113
- && (
114
- startsWith(inputs.tag || github.ref_name, 'v0') ||
115
- startsWith(inputs.tag || github.ref_name, 'v1') ||
116
- startsWith(inputs.tag || github.ref_name, 'v2') ||
117
- startsWith(inputs.tag || github.ref_name, 'v3') ||
118
- startsWith(inputs.tag || github.ref_name, 'v4') ||
119
- startsWith(inputs.tag || github.ref_name, 'v5') ||
120
- startsWith(inputs.tag || github.ref_name, 'v6') ||
121
- startsWith(inputs.tag || github.ref_name, 'v7') ||
122
- startsWith(inputs.tag || github.ref_name, 'v8') ||
123
- startsWith(inputs.tag || github.ref_name, 'v9')
124
- )
125
- runs-on: self-hosted-linux
126
- timeout-minutes: 20
127
- # 掛 Release 與回寫同倉的 ops 宣告都要寫入權限;read 會讓 push 失敗
128
- permissions:
129
- contents: write
130
- actions: write
131
- steps:
132
- - uses: actions/checkout@v7
133
- with:
134
- ref: ${{ inputs.tag || github.ref_name }}
135
- fetch-depth: 0
136
- - uses: ./.github/actions/setup-workspace
137
- with:
138
- restore-from-default: "scripts"
139
- - id: ops-name
140
- if: vars.OPS_REPO != ''
141
- env:
142
- OPS_REPO: ${{ vars.OPS_REPO }}
143
- run: echo "name=${OPS_REPO#*/}" >> "$GITHUB_OUTPUT"
144
- - id: app-token
145
- if: vars.OPS_REPO != ''
146
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
147
- with:
148
- client-id: ${{ vars.@@clientIdVariable@@ }}
149
- private-key: ${{ secrets.@@privateKeySecret@@ }}
150
- owner: ${{ github.repository_owner }}
151
- repositories: ${{ steps.ops-name.outputs.name }}
152
- - name: 用 GA 版號重建入版單元,掛 Release,寫入 production 宣告
153
- run: |
154
- if [[ -n "$OPS_TOKEN" ]]; then
155
- export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.${GITHUB_SERVER_URL}/.extraheader"
156
- GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$OPS_TOKEN" | base64 | tr -d '\n')"
157
- export GIT_CONFIG_VALUE_0
158
- fi
159
- bash scripts/deploy/run-production.sh "$TAG"
160
- env:
161
- TAG: ${{ inputs.tag || github.ref_name }}
162
- GH_TOKEN: ${{ github.token }}
163
- OPS_TOKEN: ${{ steps.app-token.outputs.token }}
164
- OPS_REPO: ${{ vars.OPS_REPO }}
165
- DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
166
- DEPLOY_LOG_DIR: ${{ runner.temp }}/deploy-log
167
- BUNDLE_DIR: ${{ runner.temp }}/bundles
168
- - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
169
- with:
170
- name: deploy-production-${{ inputs.tag || github.ref_name }}
171
- path: ${{ runner.temp }}/deploy-log
172
- retention-days: 7
173
- # @end
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Create the R2 buckets that the wrangler.toml of an infra unit declares for one environment. A bucket that exists
3
- # already counts as applied, so a rerun changes nothing. "Exists" is told by the message "already exists" or the code 10004 (owned by you)
4
- # or 10073 (BucketConflict, the code the R2 error table lists). This is the only script of the infra role that runs wrangler, and
5
- # the only one that reads the Cloudflare credentials (decision infra-apply-on-tag).
6
- #
7
- # The declaration is the array of tables [[env.<env>.r2_buckets]] of <unit dir>/wrangler.toml, one `bucket_name` each.
8
- # Nothing is deleted: a bucket that the declaration no longer names stays where it is.
9
- #
10
- # usage: apply-infra.sh <env> <unit dir>
11
- # env: WRANGLER the command that runs wrangler (default `pnpm exec wrangler`; offline: the stand-in)
12
- # DEPLOY_LOG_DIR where <env>.log is appended (default tmp/deploy-log)
13
- # CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID read by wrangler; set only by the workflow step that applies
14
- set -euo pipefail
15
- env_name="${1:?usage: apply-infra.sh <env> <unit dir>}"
16
- dir="${2:?usage: apply-infra.sh <env> <unit dir>}"
17
- [[ "$env_name" =~ ^[a-z][a-z0-9-]*$ ]] || { printf '%s\n' >&2 "env 需為小寫英數與連字號(環境名由 release-policy.json 的 targets 決定)"; exit 2; }
18
- root="$(git rev-parse --show-toplevel)"
19
- toml="$root/$dir/wrangler.toml"
20
- [[ -f "$toml" ]] || { printf '%s\n' >&2 "找不到 $toml"; exit 1; }
21
- read -r -a wrangler <<<"${WRANGLER:-pnpm exec wrangler}"
22
- log_dir="${DEPLOY_LOG_DIR:-$root/tmp/deploy-log}"
23
- mkdir -p "$log_dir"
24
-
25
- names=()
26
- while IFS= read -r n; do names+=("$n"); done < <(awk -v table="[[env.${env_name}.r2_buckets]]" '
27
- /^[[:space:]]*\[/ { inside = ($0 == table); next }
28
- inside && /^[[:space:]]*bucket_name[[:space:]]*=/ { sub(/^[^"]*"/, ""); sub(/".*$/, ""); print }
29
- ' "$toml")
30
- if (( ${#names[@]} == 0 )); then
31
- printf '%s\n' "⊘ $dir/wrangler.toml 沒有 $env_name 環境的 R2 bucket 宣告,沒有要套用的資源" | tee -a "$log_dir/$env_name.log"
32
- exit 0
33
- fi
34
-
35
- for name in "${names[@]}"; do
36
- if out="$("${wrangler[@]}" r2 bucket create "$name" 2>&1)"; then
37
- result=created
38
- elif grep -qiE 'already exists|\[code: (10004|10073)\]' <<<"$out"; then
39
- result=exists
40
- else
41
- printf '%s\n' "$out" >&2
42
- printf '%s\n' "✗ 建立 R2 bucket $name 失敗" >&2
43
- exit 1
44
- fi
45
- printf '%s\n' "r2 bucket $name ($env_name): $result" | tee -a "$log_dir/$env_name.log"
46
- done
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env bash
2
- # What the apply job of deploy-prerelease.yml does for a unit tag {unit}/vX.Y.Z-<stage>.N in a repository with the infra role: apply the
3
- # resources of the unit to the environment that the stage goes to. The tag is routed by route-tag.sh, the same file as the deploy
4
- # role has (the target of the stage in release-policy.json, an [env.<env>] table in the unit's wrangler.toml, and the directory
5
- # infra/ for kind=infra). The script is named apply-* so that a repository with both roles has no file of the same name from the
6
- # deploy role (decision monorepo-release-align). Where the deploy role builds a bundle and writes it into the ops declaration, this one applies resources
7
- # directly (apply-infra.sh), because a bucket is not a bundle that something else puts online (decision infra-apply-on-tag).
8
- #
9
- # usage: apply-prerelease.sh <unit tag>
10
- # env: see apply-infra.sh
11
- set -euo pipefail
12
- source "$(dirname "$0")/../lib/common.sh"
13
- cd "$REPO_ROOT"
14
- here="$(dirname "$0")"
15
- tag="${1:?usage: apply-prerelease.sh <unit tag>}"
16
- route="$(bash "$here/route-tag.sh" "$tag")"
17
- get() { sed -n "s/^$1=//p" <<<"$route"; }
18
- if [[ "$(get skip)" == true ]]; then info "⊘ $tag 無需套用:$(get reason)"; exit 0; fi
19
- # a unit under apps/ or services/ is built by the deploy role (run-prerelease.sh), never applied here
20
- if [[ "$(get kind)" != infra ]]; then info "⊘ $tag 不是這裡套用的單元(kind $(get kind))"; exit 0; fi
21
- unit="$(get unit)" env_name="$(get env)"
22
- bash "$here/apply-infra.sh" "$env_name" "$(unit_path "$unit")"
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env bash
2
- # What the infra job of deploy-production.yml does for a product tag vX.Y.Z in a repository with the infra role. Only a product tag applies
3
- # to production: the stable tag of a single unit never does (git-flow-template release.ts:130-134). Every infra unit of the
4
- # release (a unit under infra/ whose wrangler.toml has an [env.<the GA environment>] table) is applied. The units under apps/ and
5
- # services/ are the deploy role's (plan-production.sh), so a unit of kind backend or service is told apart by its directory. Applying is
6
- # idempotent, so the units that did not change in this release are applied again without effect.
7
- #
8
- # usage: apply-production.sh <product tag> the tag must be checked out
9
- # env: see apply-infra.sh
10
- set -euo pipefail
11
- source "$(dirname "$0")/../lib/common.sh"
12
- cd "$REPO_ROOT"
13
- here="$(dirname "$0")"
14
- tag="${1:?usage: apply-production.sh <product tag>}"
15
- # a private repository on GitHub Free has no deployment branch and tag rules for environments, so the tag is
16
- # checked here; this is in the workflow file, and whoever can change the file can bypass it
17
- [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "production 只由產品 tag(vX.Y.Z)套用,收到 $tag"
18
- applied=0
19
- for path in $(jq -r 'keys[]' "$MANIFEST"); do
20
- unit="$(unit_component "$path")"
21
- [[ "$path" == infra/* ]] || { info "略過不在 infra/ 之下的單元:$path"; continue; }
22
- case "$(policy_unit_kind "$unit")" in
23
- service|backend|web) ;;
24
- *) info "略過非套用單元:$path"; continue ;;
25
- esac
26
- env_name="$(stage_target "$unit" ga || true)"
27
- if [[ -z "$env_name" ]] || ! grep -q "^\[env\.${env_name}\]" "$path/wrangler.toml" 2>/dev/null; then
28
- info "略過沒有 GA 環境設定的單元:$path"; continue
29
- fi
30
- bash "$here/apply-infra.sh" "$env_name" "$path"
31
- applied=$((applied + 1))
32
- done
33
- if (( applied == 0 )); then info "⊘ $tag 沒有要套用的單元,略過"; fi
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Decide where a unit tag deploys. Prints key=value lines (usable as $GITHUB_OUTPUT):
3
- # unit, version, stage, env, kind (service|infra|none), skip (true|false), reason
4
- #
5
- # A prerelease tag {unit}/vX.Y.Z-<stage>.N goes where the policy file (release-policy.json) sends that stage
6
- # for that unit: the unit's own targets, else the repository targets (stage_target in
7
- # scripts/lib/release-stages.sh). The unit's kind in the policy file says how it deploys:
8
- # - service, backend, web: the target is an environment, and the unit needs an [env.<env>] table in its
9
- # wrangler.toml to deploy there (the Worker <name>-<env>)
10
- # - anything else (package, sdk, mobile, desktop): nothing to deploy here. Packages are published by
11
- # publish.yml, and native apps are not part of the first version (decision native-apps-not-in-first-version)
12
- # The directory of the unit tells which job of the workflow takes it, because the policy kind alone does not: an InfraName unit is
13
- # kind backend too. A unit under apps/ or services/ is kind=service (the deploy role builds it), a unit under infra/ is kind=infra
14
- # (the infra role applies it). A repository with both roles has this one file and both jobs; each job runs for its own kind
15
- # (decision monorepo-release-align).
16
- # The deploy is skipped, with the reason printed, when the unit has nothing to deploy to at that stage.
17
- # A stable tag never deploys here: the product tag triggers it (deploy-production.yml).
18
- #
19
- # usage: route-tag.sh <tag>
20
- # env: RELEASE_POLICY the policy file to read (default release-policy.json at the repository root)
21
- set -euo pipefail
22
- source "$(dirname "$0")/../lib/common.sh"
23
- cd "$REPO_ROOT"
24
- tag="${1:?usage: route-tag.sh <tag>}"
25
- # Every value below lands in $GITHUB_OUTPUT as key=value; a newline in the tag would add a line of its
26
- # own and could override skip. Tags only ever carry these characters, so anything else is refused.
27
- [[ "$tag" =~ ^[A-Za-z0-9._/-]+$ ]] || die "tag 含不允許的字元,只接受英數與 . _ / -"
28
-
29
- unit="" version="" stage="" env="" kind=none skip=true reason=""
30
- emit() {
31
- printf '%s=%s\n' unit "$unit" version "$version" stage "$stage" env "$env" kind "$kind" \
32
- skip "$skip" reason "$reason"
33
- exit 0
34
- }
35
- skip_with() { reason="$1"; emit; }
36
-
37
- [[ "$tag" == */v* ]] || skip_with "tag $tag 不是 {unit}/vX.Y.Z 格式"
38
- unit="${tag%%/*}"; version="${tag#*/v}"
39
- [[ "$version" == *-* ]] || skip_with "正式版不在這裡部署:正式環境由產品 tag 統一觸發"
40
- pre="${version#*-}"; stage="${pre%%.*}"
41
- if ! is_stage "$stage" || [[ "$stage" == ga ]]; then
42
- skip_with "版號 $version 的預發布階段「${stage}」不是 ${RELEASE_STAGES[*]:0:3} 之一"
43
- fi
44
- policy_unit_exists "$unit" || skip_with "$unit 不在政策檔($(basename "$(policy_file)"))的 units 裡,不是發布單元"
45
-
46
- case "$(policy_unit_kind "$unit")" in
47
- service|backend|web)
48
- path="$(unit_path "$unit" 2>/dev/null || true)"
49
- case "${path%%/*}" in
50
- apps|services) kind=service ;;
51
- infra) kind=infra ;;
52
- *) skip_with "$unit 的目錄(${path:-找不到})不在 apps/、services/ 或 infra/ 之下,不是部署或套用單元" ;;
53
- esac
54
- env="$(stage_target "$unit" "$stage" || true)"
55
- [[ -n "$env" ]] || skip_with "$unit 沒有 $stage 階段的去處(政策檔 units.$unit.targets 與 targets),略過部署"
56
- grep -q "^\[env\.${env}\]" "$REPO_ROOT/$path/wrangler.toml" 2>/dev/null \
57
- || skip_with "$unit 沒有 $env 環境的設定($path/wrangler.toml 的 [env.$env]),略過 $env 部署"
58
- ;;
59
- *)
60
- kind=none
61
- skip_with "$unit 不是部署單元(政策檔的 kind 是 $(policy_unit_kind "$unit"),由 publish.yml 發布,或不在第一版)"
62
- ;;
63
- esac
64
- skip=false
65
- emit