blueprint-shared-templates 0.0.0-stage → 0.1.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.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/base/.github/CODEOWNERS.example +10 -0
  3. package/base/.github/ISSUE_TEMPLATE/bug.yml +15 -0
  4. package/base/.github/ISSUE_TEMPLATE/feature.yml +19 -0
  5. package/base/.github/ISSUE_TEMPLATE/hotfix.yml +17 -0
  6. package/base/.github/PULL_REQUEST_TEMPLATE.md +13 -0
  7. package/base/.github/actions/setup-workspace/action.yml +54 -0
  8. package/base/.github/version-control.md +22 -0
  9. package/base/.github/workflows/auto-merge.yml +138 -0
  10. package/base/.github/workflows/ci.yml +274 -0
  11. package/base/.github/workflows/main-commit-check.yml +42 -0
  12. package/base/.github/workflows/pr-message.yml +64 -0
  13. package/base/.gitignore +356 -0
  14. package/base/.oxlintrc.json +14 -0
  15. package/base/LICENSE +21 -0
  16. package/base/releases/release-plan.md +39 -0
  17. package/base/scripts/ci/affected.sh +15 -0
  18. package/base/scripts/ci/ai-attribution-list.txt +68 -0
  19. package/base/scripts/ci/check-commit-body.sh +110 -0
  20. package/base/scripts/ci/check-main-commits.sh +31 -0
  21. package/base/scripts/ci/check-pr-title.sh +10 -0
  22. package/base/scripts/ci/ci-scope.conf +23 -0
  23. package/base/scripts/ci/ci-scope.sh +106 -0
  24. package/base/scripts/ci/native-build.sh +40 -0
  25. package/base/scripts/ci/run-affected.sh +48 -0
  26. package/base/scripts/ci/run-units.sh +33 -0
  27. package/base/scripts/hooks/commit-msg +38 -0
  28. package/base/scripts/hooks/pre-push +63 -0
  29. package/base/scripts/lib/common.sh +233 -0
  30. package/base/scripts/lib/retry.mjs +178 -0
  31. package/base/scripts/merge/decide.mjs +130 -0
  32. package/base/scripts/setup/git-hooks.sh +16 -0
  33. package/base/scripts/setup/github-repo-settings.json +8 -0
  34. package/base/scripts/setup/github-repo-settings.sh +110 -0
  35. package/deploy/.github/workflows/deploy-prerelease.yml +157 -0
  36. package/deploy/.github/workflows/deploy-production.yml +173 -0
  37. package/deploy/scripts/deploy/build-bundle.sh +49 -0
  38. package/deploy/scripts/deploy/clone-ops.sh +14 -0
  39. package/deploy/scripts/deploy/plan-production.sh +43 -0
  40. package/deploy/scripts/deploy/promote.sh +35 -0
  41. package/deploy/scripts/deploy/publish-bundle.sh +21 -0
  42. package/deploy/scripts/deploy/route-tag.sh +65 -0
  43. package/deploy/scripts/deploy/run-prerelease.sh +49 -0
  44. package/deploy/scripts/deploy/run-production.sh +51 -0
  45. package/deploy/scripts/deploy/writeback-ops.sh +53 -0
  46. package/deploy/scripts/lib/bundle.sh +52 -0
  47. package/facts-describes.ts +53 -0
  48. package/facts-skeleton.mjs +84 -0
  49. package/hub/.github/workflows/open-release-lines.yml +63 -0
  50. package/hub/scripts/deploy/clone-ops.sh +14 -0
  51. package/hub/scripts/release/dispatch-release-lines.sh +54 -0
  52. package/hub/scripts/release/snapshot-members.sh +85 -0
  53. package/infra/.github/workflows/deploy-prerelease.yml +157 -0
  54. package/infra/.github/workflows/deploy-production.yml +173 -0
  55. package/infra/scripts/deploy/apply-infra.sh +46 -0
  56. package/infra/scripts/deploy/apply-prerelease.sh +22 -0
  57. package/infra/scripts/deploy/apply-production.sh +33 -0
  58. package/infra/scripts/deploy/route-tag.sh +65 -0
  59. package/ops/.github/workflows/ops-deploy.yml +88 -0
  60. package/ops/scripts/deploy/apply-ops.sh +100 -0
  61. package/ops/scripts/deploy/healthz.sh +16 -0
  62. package/ops/scripts/deploy/ops-run.sh +41 -0
  63. package/ops/scripts/deploy/smoke.sh +49 -0
  64. package/ops/scripts/lib/bundle.sh +52 -0
  65. package/package.json +33 -3
  66. package/publish/.github/workflows/publish.yml +299 -0
  67. package/publish/scripts/release/cleanup-private-packages.mjs +107 -0
  68. package/publish/scripts/release/mirror-units.sh +167 -0
  69. package/publish/scripts/release/publish-units.sh +489 -0
  70. package/release/.github/workflows/nightly.yml +93 -0
  71. package/release/.github/workflows/open-release-line.yml +70 -0
  72. package/release/.github/workflows/release-line-finalize.yml +101 -0
  73. package/release/.github/workflows/release-please.yml +148 -0
  74. package/release/release-please-config.json +39 -0
  75. package/release/release-policy.json +38 -0
  76. package/release/schemas/release-policy.schema.json +151 -0
  77. package/release/scripts/ci/check-facts-describes.sh +63 -0
  78. package/release/scripts/ci/check-facts.sh +46 -0
  79. package/release/scripts/ci/check-release-policy-schema.sh +59 -0
  80. package/release/scripts/ci/check-release-policy.sh +123 -0
  81. package/release/scripts/ci/pin-train.sh +29 -0
  82. package/release/scripts/ci/release-train.sh +39 -0
  83. package/release/scripts/ci/validate-json-schema.mjs +17 -0
  84. package/release/scripts/lib/docs.sh +71 -0
  85. package/release/scripts/lib/facts.sh +146 -0
  86. package/release/scripts/lib/release-plan.sh +128 -0
  87. package/release/scripts/lib/release-pr.sh +106 -0
  88. package/release/scripts/lib/release-stages.sh +892 -0
  89. package/release/scripts/release/advance-release.sh +86 -0
  90. package/release/scripts/release/cut-release.sh +313 -0
  91. package/release/scripts/release/dispatch-publish.sh +34 -0
  92. package/release/scripts/release/ensure-stage-deploys.sh +56 -0
  93. package/release/scripts/release/finalize-release.sh +351 -0
  94. package/release/scripts/release/merge-release-pr.sh +233 -0
  95. package/release/scripts/release/open-release-line.sh +22 -0
  96. package/release/scripts/release/plan.sh +45 -0
  97. package/release/scripts/release/snapshot.sh +57 -0
  98. package/release/scripts/release/verify-production.sh +63 -0
  99. package/transform.mjs +64 -0
  100. package/verify/.github/workflows/verify-production.yml +71 -0
  101. package/verify/scripts/release/verify-ops.sh +41 -0
  102. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Carlos Space
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ # Changes to versioning and release files need the owner's review. Adjust the paths to the repository's
2
+ # actual version config, CI config and release scripts. The platform only enforces this when "Require
3
+ # review from Code Owners" is on (branch protection or a ruleset); otherwise it just requests a review.
4
+ # Copy to .github/CODEOWNERS and replace {owner}. The pre-push hook (scripts/hooks/pre-push) reads
5
+ # .github/CODEOWNERS too: a push to main that touches one of these paths is refused and goes through a PR.
6
+ # fact: codeowners-enforcement
7
+ /release-please-config*.json @{owner}
8
+ /.release-please-manifest.json @{owner}
9
+ /.github/workflows/ @{owner}
10
+ /scripts/release/ @{owner}
@@ -0,0 +1,15 @@
1
+ name: Bug(主線)
2
+ description: 尚未發布或 staging 發現的 bug(bugfix/<issue-N>-<kebab> → main)
3
+ labels: ["type:bug"]
4
+ body:
5
+ - type: textarea
6
+ id: repro
7
+ attributes:
8
+ label: 重現步驟與預期
9
+ validations:
10
+ required: true
11
+ - type: dropdown
12
+ id: env
13
+ attributes:
14
+ label: 發現環境
15
+ options: [local, dev, beta, staging, production]
@@ -0,0 +1,19 @@
1
+ name: Feature
2
+ description: 新功能(feature/<issue-N>-<kebab> → main)
3
+ labels: ["type:feature"]
4
+ body:
5
+ - type: textarea
6
+ id: goal
7
+ attributes:
8
+ label: 目標與驗收條件
9
+ validations:
10
+ required: true
11
+ - type: dropdown
12
+ id: units
13
+ attributes:
14
+ label: 影響單元
15
+ multiple: true
16
+ options: [product-web, product-api, product-macos, product-ios, product-android, product-sdk-core, product-sdk-binding, product-sdk-js, product-sdk-client, product-sdk-cli, product-sdk, product-sdk-py, product-sdk-rs, product-shared-types, product-shared-utils]
17
+ - type: markdown
18
+ attributes:
19
+ value: 版號於 Release Plan 撰寫時才指派(label release:v*),此處不填版號。
@@ -0,0 +1,17 @@
1
+ name: Hotfix(已發布正式版)
2
+ description: 生產環境正式版的問題(hotfix/<issue-N>-<kebab> → release/v*;發布分支已刪除時,從同一產品線最大的產品 tag 重建)
3
+ labels: ["type:bug", "production-bug", "hotfix-needed"]
4
+ body:
5
+ - type: input
6
+ id: version
7
+ attributes:
8
+ label: 受影響的正式版(vX.Y.Z 與單元 tag)
9
+ placeholder: v{X.Y.Z}({單元}/v{X.Y.Z})
10
+ validations:
11
+ required: true
12
+ - type: textarea
13
+ id: impact
14
+ attributes:
15
+ label: 影響與重現
16
+ validations:
17
+ required: true
@@ -0,0 +1,13 @@
1
+ ## 動機
2
+ 為什麼改,觸發的現象或需求。
3
+
4
+ ## 變更
5
+ - 依單元列出做了什麼
6
+
7
+ ## 影響
8
+ - 行為、相容性、遷移步驟。沒有影響寫「行為不變」
9
+
10
+ ## 驗證
11
+ - 跑了什麼、結果,一兩行
12
+
13
+ Closes #N
@@ -0,0 +1,54 @@
1
+ name: setup-workspace
2
+ description: >
3
+ Toolchain for this repo on either runner environment: Node + pnpm via setup actions (never
4
+ preinstalled tools) and an optional frozen install. The scripts are bash, which both runner
5
+ environments already ship, so no shell install is needed. The pnpm cache input is disabled on
6
+ self-hosted, where a persistent store is mounted, and when install is not "true", because no pnpm store
7
+ exists to save.
8
+ inputs:
9
+ node:
10
+ description: install Node and pnpm (deploy / finalize jobs only need jq and gh)
11
+ default: "true"
12
+ install:
13
+ description: run pnpm install --frozen-lockfile
14
+ default: "true"
15
+ registry-url:
16
+ description: passed to setup-node for publish jobs
17
+ default: ""
18
+ restore-from-default:
19
+ description: >
20
+ space-separated paths to take from the default branch instead of the checked-out ref. Deploy and
21
+ finalize jobs check out a tag, whose scripts/ and ops/ are frozen at release time; the tooling
22
+ must come from the default branch or a fix landed after the tag is silently not used.
23
+ default: ""
24
+ runs:
25
+ using: composite
26
+ steps:
27
+ - name: tooling from the default branch
28
+ if: inputs.restore-from-default != ''
29
+ shell: bash
30
+ run: |
31
+ git fetch --no-tags origin "${{ github.event.repository.default_branch }}"
32
+ git checkout FETCH_HEAD -- ${{ inputs.restore-from-default }}
33
+ # GitHub-hosted: pnpm first, because setup-node's pnpm cache needs the pnpm binary already on PATH.
34
+ # Self-hosted: Node first, because pnpm/action-setup runs its installer with whatever node is on
35
+ # PATH and the macOS base image ships one too old for it (self-hosted-runner README).
36
+ - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
37
+ if: inputs.node == 'true' && runner.environment == 'github-hosted'
38
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
39
+ if: inputs.node == 'true'
40
+ with:
41
+ node-version: 24
42
+ cache: ${{ runner.environment == 'github-hosted' && inputs.install == 'true' && 'pnpm' || '' }}
43
+ registry-url: ${{ inputs.registry-url }}
44
+ - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
45
+ if: inputs.node == 'true' && runner.environment != 'github-hosted'
46
+ - name: pnpm install
47
+ if: inputs.node == 'true' && inputs.install == 'true'
48
+ shell: bash
49
+ # pnpm 11 and later read only PNPM_CONFIG_STORE_DIR, and runnerd sets only npm_config_store_dir. Export it
50
+ # in this step, not in the job env, because pnpm self-update reads it too (runnerd README).
51
+ # GitHub-hosted has no npm_config_store_dir, so nothing is exported there.
52
+ run: |
53
+ [ -n "${npm_config_store_dir:-}" ] && export PNPM_CONFIG_STORE_DIR="$npm_config_store_dir"
54
+ pnpm install --frozen-lockfile
@@ -0,0 +1,22 @@
1
+ # 版控流程範本
2
+
3
+ 導入版控流程時,下表的檔案隨 base 範本組進倉庫。每個檔案都是起點,依倉庫的設定調整佔位符 `{...}`。
4
+
5
+ | 檔案 | 用途 |
6
+ | :--- | :--- |
7
+ | `.github/PULL_REQUEST_TEMPLATE.md` | PR 內文的動機、變更、影響、驗證四段,最後一段放關聯 trailer。squash 後 PR 內文就是 commit 內文,所以和 commit 訊息同一份格式 |
8
+ | `.github/ISSUE_TEMPLATE/*.yml` | bug、feature、hotfix 三種 Issue |
9
+ | `releases/release-plan.md` | 一版一份的發布規劃範本,複製成主檔的 `releases/release-plan-v{X.Y.Z}.md`。維護型發布規劃由 `scripts/release/plan.sh maintenance` 寫出,不從這份範本複製 |
10
+ | `.github/CODEOWNERS.example` | 複製成 `.github/CODEOWNERS`,列出版號與發布相關檔案的審查者。`scripts/hooks/pre-push` 也讀它,推上 main 的變更碰到這些路徑時擋下,改走 PR |
11
+ | `scripts/hooks/commit-msg`、`scripts/hooks/pre-push` | 訊息格式與 AI 平台署名的檢查,推送預設分支前再查一次推送範圍的訊息並跑建置測試。由 `scripts/setup/git-hooks.sh` 設定 `core.hooksPath`,使用者在自己的終端機執行(代理執行會被權限規則擋下) |
12
+ | `.github/workflows/main-commit-check.yml` | 每天核對預設分支前一天的 commit 訊息格式與 AI 平台署名,呼叫 `scripts/ci/check-main-commits.sh` |
13
+ | `.github/workflows/pr-message.yml` | PR 標題與內文的同一組檢查,squash 後標題與內文就是 commit 訊息 |
14
+ | `scripts/setup/github-repo-settings.sh`、`scripts/setup/github-repo-settings.json` | 把倉庫鎖定成只允許 squash 合併、合併後刪分支,並設定 Actions 產物與 log 的保留天數。值寫在旁邊的 JSON。可以一次指定多個倉。`--dry-run` 只印要送的請求,套用前先讀現值,已相同的設定不送 |
15
+
16
+ 訊息檢查的腳本在 `scripts/ci/`:`check-pr-title.sh`、`check-commit-body.sh`、`check-main-commits.sh` 與 `ai-attribution-list.txt`。
17
+
18
+ `pre-push` 檢查推上 main 的 commit:訊息格式與 AI 平台署名、每個 commit 只動一個發布單元、不碰 `.github/CODEOWNERS` 列的治理路徑、沒有破壞性變更,通過後跑 `scripts/ci/run-affected.sh` 的 lint、build、test。`core.hooksPath` 寫相對路徑時,在 linked worktree 裡會指到那個 worktree 底下的 `scripts/hooks/`。
19
+
20
+ 每日核對 workflow 的 runner 讀倉庫變數 `LINUX_RUNNER`,沒設時用 self-hosted 的 `self-hosted-linux`。改用其他 runner 時,只要有 git 與 bash 4 就能跑。倉庫沒有 self-hosted runner 時,把 `LINUX_RUNNER` 設成 `ubuntu-latest`。
21
+
22
+ Issue 與 PR 範本取自 git-flow-template,label 與分支前綴是它的預設值,倉庫的設定不同時照設定替換。PR 範本的 `Closes #N` 依目標分支換關鍵字,目標是發布分支(hotfix)時寫 `Refs #N`。
@@ -0,0 +1,138 @@
1
+ name: auto-merge
2
+
3
+ # Merges the pull requests that carry the auto-merge label once the required checks have passed. Every repository
4
+ # has this same workflow, because the free plan gives a private repository no platform auto-merge and no ruleset.
5
+ # It runs when the auto-merge label is added and when ci or pr-message finishes, and each run reads the checks of the latest
6
+ # head commit again (scripts/merge/decide.mjs). The required checks and the label are in scripts/merge/merge-config.json.
7
+ # The decide job's if keeps every event that cannot lead to a merge off the runner: another label than the auto-merge label
8
+ # (release-please adds autorelease labels), a Release PR (its branch starts with release-please--, and a script merges it, never this workflow),
9
+ # and a finished ci or pr-message that belongs to no pull request (a push to main or a release branch, or a fork).
10
+ # A ci that failed still runs the decision, because a job of ci that is not a required check (native) can fail while the
11
+ # required checks pass. pr-message stays a trigger: pr-title is a required check in it, and when it finishes after ci there is no
12
+ # later event to merge on.
13
+ #
14
+ # pull_request_target runs this file and the scripts from the base branch, never from the pull request, so the
15
+ # App token is not handed to code of the pull request. A pull request from a fork is never merged.
16
+ # The names of the GitHub App variable and secret are written in when the repository is composed.
17
+ on:
18
+ pull_request_target:
19
+ types: [labeled]
20
+ workflow_run:
21
+ workflows: [ci, pr-message]
22
+ types: [completed]
23
+
24
+ permissions:
25
+ contents: read
26
+
27
+ defaults:
28
+ run:
29
+ shell: bash
30
+
31
+ env:
32
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
33
+ POLL_TRIES: "2"
34
+ CI_GATE_TRIES: "2"
35
+ CI_GATE_QUEUE_TRIES: "0"
36
+
37
+ jobs:
38
+ decide:
39
+ # The label value is written in when the repository is composed (scripts/merge/merge-config.json has the same one).
40
+ if: >-
41
+ (github.event_name == 'pull_request_target'
42
+ && github.event.label.name == '@@mergeLabel@@'
43
+ && !startsWith(github.event.pull_request.head.ref, 'release-please--'))
44
+ || (github.event_name == 'workflow_run'
45
+ && github.event.workflow_run.pull_requests[0].number
46
+ && !startsWith(github.event.workflow_run.head_branch, 'release-please--'))
47
+ # A newer event of the same pull request reads the checks again, so a decide still running for an older one is cancelled.
48
+ concurrency:
49
+ group: auto-merge-decide-${{ github.event.pull_request.number || github.event.workflow_run.pull_requests[0].number }}
50
+ cancel-in-progress: true
51
+ runs-on: self-hosted-linux
52
+ timeout-minutes: 5
53
+ permissions:
54
+ actions: read
55
+ contents: read
56
+ pull-requests: read
57
+ checks: read
58
+ statuses: read
59
+ outputs:
60
+ action: ${{ steps.d.outputs.action }}
61
+ pr: ${{ steps.d.outputs.pr }}
62
+ sha: ${{ steps.d.outputs.sha }}
63
+ steps:
64
+ - uses: actions/checkout@v7
65
+ with:
66
+ persist-credentials: false
67
+ - uses: ./.github/actions/setup-workspace
68
+ with:
69
+ install: "false"
70
+ - id: d
71
+ env:
72
+ GH_TOKEN: ${{ github.token }}
73
+ GH_REPO: ${{ github.repository }}
74
+ PR_NUMBER: ${{ github.event.pull_request.number || github.event.workflow_run.pull_requests[0].number }}
75
+ run: |
76
+ if [[ -z "$PR_NUMBER" ]]; then
77
+ echo "action=skip" >> "$GITHUB_OUTPUT"; echo "no pull request belongs to this event"; exit 0
78
+ fi
79
+ fields=number,state,isDraft,headRefOid,headRefName,baseRefName,isCrossRepository,labels,author,latestReviews
80
+ mkdir -p "$RUNNER_TEMP/merge"
81
+ checked_sha="$(gh pr view "$PR_NUMBER" --json headRefOid --jq .headRefOid)"
82
+ # gh pr checks exits 1 for a failed check and 8 for a pending one; the decision reads both from the output
83
+ rc=0; gh pr checks "$PR_NUMBER" --json name,bucket > "$RUNNER_TEMP/merge/checks.json" 2> "$RUNNER_TEMP/merge/checks.err" || rc=$?
84
+ cat "$RUNNER_TEMP/merge/checks.err" >&2
85
+ # a pull request without any check yet: exit 1, nothing on stdout, "no checks reported" on stderr; the decision reads that as "has not run"
86
+ if (( rc == 1 )) && [[ ! -s "$RUNNER_TEMP/merge/checks.json" ]] && grep -q 'no checks reported on the' "$RUNNER_TEMP/merge/checks.err"; then
87
+ printf '[]\n' > "$RUNNER_TEMP/merge/checks.json"
88
+ fi
89
+ (( rc == 0 || rc == 1 || rc == 8 )) || { echo "::error::gh pr checks exited $rc"; exit 1; }
90
+ # an empty or non-array output means the checks could not be read; it must not reach the decision as "no check ran"
91
+ jq -e 'type == "array"' "$RUNNER_TEMP/merge/checks.json" > /dev/null || { echo "::error::gh pr checks exited $rc and printed no JSON array of checks"; exit 1; }
92
+ gh pr diff "$PR_NUMBER" --name-only | jq -R . | jq -s . > "$RUNNER_TEMP/merge/files.json"
93
+ gh pr view "$PR_NUMBER" --json "$fields" \
94
+ | jq --arg sha "$checked_sha" --slurpfile checks "$RUNNER_TEMP/merge/checks.json" --slurpfile files "$RUNNER_TEMP/merge/files.json" \
95
+ '{pr: ., checkedSha: $sha, checks: $checks[0], changedFiles: $files[0]}' > "$RUNNER_TEMP/merge/input.json"
96
+ node scripts/merge/decide.mjs --input "$RUNNER_TEMP/merge/input.json" | tee "$RUNNER_TEMP/merge/decision.json"
97
+ {
98
+ echo "action=$(jq -r .action "$RUNNER_TEMP/merge/decision.json")"
99
+ echo "pr=$(jq -r '.pr // empty' "$RUNNER_TEMP/merge/decision.json")"
100
+ echo "sha=$(jq -r '.sha // empty' "$RUNNER_TEMP/merge/decision.json")"
101
+ } >> "$GITHUB_OUTPUT"
102
+ jq -r '"### auto-merge\n- action: `\(.action)`\n- \(.reason)"' "$RUNNER_TEMP/merge/decision.json" >> "$GITHUB_STEP_SUMMARY"
103
+
104
+ merge:
105
+ needs: decide
106
+ if: needs.decide.outputs.action == 'merge'
107
+ # A merge is never cancelled halfway: the runs of one pull request queue.
108
+ concurrency:
109
+ group: auto-merge-merge-${{ needs.decide.outputs.pr }}
110
+ cancel-in-progress: false
111
+ runs-on: self-hosted-linux
112
+ timeout-minutes: 5
113
+ steps:
114
+ # the base branch's scripts/lib/retry.mjs, as in decide: never the code of the pull request
115
+ - uses: actions/checkout@v7
116
+ with:
117
+ persist-credentials: false
118
+ - uses: ./.github/actions/setup-workspace
119
+ with:
120
+ install: "false"
121
+ - id: app-token
122
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
123
+ with:
124
+ client-id: ${{ vars.@@clientIdVariable@@ }}
125
+ private-key: ${{ secrets.@@privateKeySecret@@ }}
126
+ # --match-head-commit makes gh refuse the merge when a commit was pushed after the checks were read.
127
+ # Pull requests merged at the same moment into one base can get HTTP 405 "Base branch was modified" for the one that lost the
128
+ # race (reported by users; the GitHub documentation does not mention it). scripts/lib/retry.mjs merge asks again after that
129
+ # error and after a transient error of GitHub (HTTP 500, 502, 503, 504, a connect timeout), up to 5 attempts RETRY_SLEEP
130
+ # seconds apart; any other error fails at once, as does the last attempt (decision transient-error-shared-retry).
131
+ - name: Squash-merge the pull request
132
+ env:
133
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
134
+ GH_REPO: ${{ github.repository }}
135
+ PR_NUMBER: ${{ needs.decide.outputs.pr }}
136
+ HEAD_SHA: ${{ needs.decide.outputs.sha }}
137
+ RETRY_SLEEP: "3"
138
+ run: node scripts/lib/retry.mjs merge -- gh pr merge "$PR_NUMBER" --squash --match-head-commit "$HEAD_SHA" --delete-branch
@@ -0,0 +1,274 @@
1
+ name: ci
2
+
3
+ # Tiered by trigger (docs/ci.md): a pull request gets the fast, affected-only set and blocks the
4
+ # merge; a push to main or to a train runs the full tree, because those are the points where
5
+ # release-please reads history; a train additionally runs the assembled-system e2e, which GA gates on.
6
+ #
7
+ # Whether a run checks anything is decided by content, in the scope job (scripts/ci/ci-scope.sh),
8
+ # not by path filters here: every push gets a run, so "the latest ci run" is always the run of the
9
+ # tip, which is what the release gates read. A run whose source is unchanged since the branch's last
10
+ # green run skips its jobs and still concludes success.
11
+ on:
12
+ pull_request:
13
+ # 手動派送一律全部執行,用來在不推 commit 的情況下重跑一次
14
+ workflow_dispatch:
15
+ push:
16
+ branches:
17
+ - main
18
+ - "release/**"
19
+ # 合回分支只用來開回 main 的 PR,PR 那次執行就是它的檢查;push 再跑一次是同一個 SHA
20
+ - "!release/**--to-main"
21
+
22
+ permissions:
23
+ contents: read
24
+
25
+ defaults:
26
+ run:
27
+ shell: bash
28
+
29
+ concurrency:
30
+ group: ci-${{ github.ref }}
31
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
32
+
33
+ jobs:
34
+ # release-please opens its PRs with GITHUB_TOKEN. GitHub deliberately does not run workflows for
35
+ # those PRs (recursion guard), so they sit as "Action required" forever. Their content is generated
36
+ # (version bumps + changelog) and CI already ran on the base branch, so skip them explicitly.
37
+ #
38
+ # The PR title and body check lives in pr-message.yml, which also runs when the PR is edited. It is
39
+ # not here because an edited run of this workflow would either rebuild for a text change or record
40
+ # skipped static/build-test checks; gh pr checks keeps only the newest check per name, workflow and
41
+ # event, so a skipped one would hide an earlier failure from the merge gate.
42
+ #
43
+ # Scope decides whether anything runs (run) and whether the macOS job has work (native). Both come
44
+ # from one diff against the same base, so the path rules live in one place: scripts/ci/ci-scope.conf.
45
+ # It runs only git and gh, so it does not use setup-workspace.
46
+ scope:
47
+ if: github.event_name != 'pull_request' || !startsWith(github.head_ref, 'release-please--')
48
+ runs-on: self-hosted-linux
49
+ env:
50
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
51
+ POLL_TRIES: "2"
52
+ CI_GATE_TRIES: "2"
53
+ CI_GATE_QUEUE_TRIES: "0"
54
+ timeout-minutes: 5
55
+ permissions:
56
+ contents: read
57
+ actions: read # gh run list: the branch's last successful ci run
58
+ pull-requests: read # commits/<sha>/pulls: the pull request a push came from
59
+ outputs:
60
+ run: ${{ steps.s.outputs.run }}
61
+ native: ${{ steps.s.outputs.native }}
62
+ steps:
63
+ - uses: actions/checkout@v7
64
+ with:
65
+ fetch-depth: 0
66
+ persist-credentials: false
67
+ - id: s
68
+ run: bash scripts/ci/ci-scope.sh
69
+ env:
70
+ GH_TOKEN: ${{ github.token }}
71
+ EVENT: ${{ github.event_name }}
72
+ BRANCH: ${{ github.ref_name }}
73
+ BASE_REF: ${{ github.base_ref }}
74
+ DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
75
+ REPO: ${{ github.repository }}
76
+
77
+ static:
78
+ needs: scope
79
+ if: needs.scope.outputs.run == 'true'
80
+ runs-on: self-hosted-linux
81
+ env:
82
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
83
+ POLL_TRIES: "2"
84
+ CI_GATE_TRIES: "2"
85
+ CI_GATE_QUEUE_TRIES: "0"
86
+ timeout-minutes: 15
87
+ steps:
88
+ - uses: actions/checkout@v7
89
+ with:
90
+ persist-credentials: false
91
+ - uses: ./.github/actions/setup-workspace
92
+ - name: Lint (oxlint, whole tree — it is fast enough not to need scoping)
93
+ run: pnpm lint
94
+ - name: Shell syntax
95
+ run: find scripts -name '*.sh' -print0 | xargs -0 -n1 bash -n
96
+ # 政策檔不符 schema 時,發布腳本要到開線才報錯;放在 static 讓每個 PR 與 main 都先擋下
97
+ # 有 release 角色的倉一律跑,和範本相同;沒有 release 角色的倉沒有政策檔也沒有這支腳本,組裝時不放這一步
98
+ # @if release
99
+ - name: 政策檔符合 schema
100
+ run: bash scripts/ci/check-release-policy-schema.sh
101
+ # @end
102
+ # bash -n 抓不到:$var 後面直接接中文時,bash 把非 ASCII 位元組讀進變數名,set -u 下執行到才報未綁定。改寫成 ${var}
103
+ - name: Shell 變數名後不接非 ASCII
104
+ run: |
105
+ if grep -rnP --include='*.sh' '\$[A-Za-z_][A-Za-z0-9_]*[^\x00-\x7F]' scripts; then
106
+ echo "::error::上面幾行的變數後面直接接非 ASCII 字元,改寫成 \${var}"; exit 1
107
+ fi
108
+
109
+ build-test:
110
+ needs: scope
111
+ if: needs.scope.outputs.run == 'true'
112
+ runs-on: self-hosted-linux
113
+ env:
114
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
115
+ POLL_TRIES: "2"
116
+ CI_GATE_TRIES: "2"
117
+ CI_GATE_QUEUE_TRIES: "0"
118
+ timeout-minutes: 20
119
+ steps:
120
+ - uses: actions/checkout@v7
121
+ with:
122
+ fetch-depth: 0
123
+ persist-credentials: false
124
+ - uses: ./.github/actions/setup-workspace
125
+ - id: aff
126
+ name: Affected set (PR only; push runs everything)
127
+ run: echo "since=$(bash scripts/ci/affected.sh)" >> "$GITHUB_OUTPUT"
128
+ # tsc is the type check: build fails on a type error, so no separate typecheck step
129
+ # (one would need every upstream package's dist/*.d.ts, i.e. a build anyway).
130
+ - name: Build (type-checks via tsc; affected set plus its upstream closure)
131
+ run: bash scripts/ci/run-affected.sh build
132
+ env:
133
+ AFFECTED_SINCE: ${{ steps.aff.outputs.since }}
134
+ WITH_DEPS: "1"
135
+ - name: Unit tests
136
+ run: bash scripts/ci/run-affected.sh test
137
+ env:
138
+ AFFECTED_SINCE: ${{ steps.aff.outputs.since }}
139
+ # Units that are not pnpm packages (Python, Rust, Go), from scripts/ci/units.json: only the affected ones on
140
+ # a pull request, all of them on a push, like the pnpm units above. Swift units are built by the native job.
141
+ - id: langs
142
+ name: Languages of the other units
143
+ run: echo "langs=$(bash scripts/ci/run-units.sh langs)" >> "$GITHUB_OUTPUT"
144
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
145
+ if: contains(steps.langs.outputs.langs, 'python')
146
+ with:
147
+ python-version: "3.12"
148
+ - uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
149
+ if: contains(steps.langs.outputs.langs, 'rust')
150
+ with:
151
+ toolchain: stable
152
+ - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
153
+ if: contains(steps.langs.outputs.langs, 'go')
154
+ with:
155
+ go-version: "1.24"
156
+ - name: Build (Python, Rust and Go units)
157
+ run: bash scripts/ci/run-units.sh build
158
+ env:
159
+ AFFECTED_SINCE: ${{ steps.aff.outputs.since }}
160
+ - name: Test (Python, Rust and Go units)
161
+ run: bash scripts/ci/run-units.sh test
162
+ env:
163
+ AFFECTED_SINCE: ${{ steps.aff.outputs.since }}
164
+
165
+ # The facts packages (facts/) against the code they describe. Three things fail here: a fact-kit rule
166
+ # (fact-kit check on every facts package; a component package's implDirs makes an implementation that
167
+ # imports the aggregate fail with impl-imports-facts), a fact whose since is ahead of describes (on a
168
+ # release branch the version of the open Release PR is passed as --train, and the rows of those components are
169
+ # pinned in the checkout first), and a component whose describes is not
170
+ # written with describesOf (a literal version in index.ts) or {}, or whose built describes has a key that is not the component.
171
+ # Scope decides when it runs, like the other jobs: facts/ and every unit directory count as source. A repository with
172
+ # the release role always has this job; with no facts/ in it, the scripts say so and succeed. A repository without the
173
+ # release role has no facts scripts, so its job keeps the id and the check name and only says there is nothing to check.
174
+ # The job id and the step names are referenced from other repositories' docs; rename them only together.
175
+ facts:
176
+ needs: scope
177
+ if: needs.scope.outputs.run == 'true'
178
+ runs-on: self-hosted-linux
179
+ env:
180
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
181
+ POLL_TRIES: "2"
182
+ CI_GATE_TRIES: "2"
183
+ CI_GATE_QUEUE_TRIES: "0"
184
+ timeout-minutes: 15
185
+ permissions:
186
+ contents: read # release-train.sh reads the Release PR branch with git fetch, which needs no pull-requests scope
187
+ steps:
188
+ - uses: actions/checkout@v7
189
+ with:
190
+ persist-credentials: false
191
+ # @if !release
192
+ - name: No facts in this repository
193
+ run: echo "⊘ 這個倉沒有 release 角色,沒有 facts 套件,不需要檢查"
194
+ # @end
195
+ # @if release
196
+ - uses: ./.github/actions/setup-workspace
197
+ # The facts of a release branch are pinned to the next version before the Release PR merges, while describes
198
+ # still reads the version file of the unit directory, which the Release PR has not changed yet. A push to a release branch and a pull request into one both read the Release PR of
199
+ # that release branch. Other branches have no Release PR and set nothing.
200
+ # The checkout keeps no token, because the later steps build and run code from the pull request. Only this
201
+ # step hands the read-only token to git, through GIT_CONFIG_* in its own environment, for the git fetch of the
202
+ # Release PR branch.
203
+ - name: Train of the open Release PR
204
+ if: startsWith(github.ref, 'refs/heads/release/') || startsWith(github.base_ref, 'release/')
205
+ run: |
206
+ export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.${GITHUB_SERVER_URL}/.extraheader"
207
+ GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n')"
208
+ export GIT_CONFIG_VALUE_0
209
+ bash scripts/ci/release-train.sh >> "$GITHUB_ENV"
210
+ env:
211
+ GH_TOKEN: ${{ github.token }}
212
+ BRANCH: ${{ github.base_ref || github.ref_name }}
213
+ # Pins the next rows of the components in the train, in this checkout only (nothing is committed), the way
214
+ # merge-release-pr.sh pins them before the Release PR merges. Without it check reports train-next.
215
+ - name: Pin the train in the checkout
216
+ if: startsWith(github.ref, 'refs/heads/release/') || startsWith(github.base_ref, 'release/')
217
+ run: bash scripts/ci/pin-train.sh
218
+ - name: fact-kit check (every facts package)
219
+ run: bash scripts/ci/check-facts.sh
220
+ - name: describes is written with describesOf
221
+ run: bash scripts/ci/check-facts-describes.sh
222
+ # @end
223
+
224
+ # Native lane. Deciding whether there is native work must not itself need a macOS runner: only two
225
+ # macOS VMs can exist on the host, they are shared with other repositories, and the GA gate waits on
226
+ # this run. So the scope job decides on linux and the macOS job is only requested when it has
227
+ # something to build. 只做編譯;這個 job 不跑時沒有任何檢查被略過。
228
+ native:
229
+ needs: scope
230
+ if: needs.scope.outputs.native == 'true'
231
+ runs-on: self-hosted-macos-lite
232
+ env:
233
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
234
+ POLL_TRIES: "2"
235
+ CI_GATE_TRIES: "2"
236
+ CI_GATE_QUEUE_TRIES: "0"
237
+ timeout-minutes: 20
238
+ steps:
239
+ - uses: actions/checkout@v7
240
+ with:
241
+ persist-credentials: false
242
+ - name: Toolchain
243
+ run: xcodebuild -version && swift --version | head -1
244
+ - name: Build and test (the SwiftPM packages of CI_SCOPE_NATIVE_UNITS)
245
+ run: bash scripts/ci/native-build.sh
246
+
247
+ # Assembled-system tests against built artifacts. Only on a train: this is the stabilisation
248
+ # window, and finalize-release.sh --phase ga refuses to proceed until this run is green.
249
+ e2e:
250
+ if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && startsWith(github.ref, 'refs/heads/release/')
251
+ needs: [scope, build-test]
252
+ runs-on: self-hosted-linux
253
+ env:
254
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
255
+ POLL_TRIES: "2"
256
+ CI_GATE_TRIES: "2"
257
+ CI_GATE_QUEUE_TRIES: "0"
258
+ timeout-minutes: 20
259
+ steps:
260
+ - uses: actions/checkout@v7
261
+ with:
262
+ persist-credentials: false
263
+ # A repository with no tests/e2e/ (no pnpm unit) has nothing to run here: the job says so and succeeds, as
264
+ # nightly.yml does for its e2e step.
265
+ - name: No e2e tests in this repository
266
+ if: hashFiles('tests/e2e/*.test.mjs') == ''
267
+ run: echo "⊘ 沒有 tests/e2e/*.test.mjs,沒有端對端測試可跑"
268
+ - if: hashFiles('tests/e2e/*.test.mjs') != ''
269
+ uses: ./.github/actions/setup-workspace
270
+ - if: hashFiles('tests/e2e/*.test.mjs') != ''
271
+ run: pnpm -r build
272
+ - name: E2E on dist/
273
+ if: hashFiles('tests/e2e/*.test.mjs') != ''
274
+ run: pnpm test:e2e
@@ -0,0 +1,42 @@
1
+ # Checks every commit message that landed on the default branch since the previous day: Conventional Commits,
2
+ # no merge commits, and no AI-platform attribution, with the same script the pre-push hook runs
3
+ # (scripts/ci/check-main-commits.sh). Hooks can be skipped with --no-verify, so this is the after-the-fact detection.
4
+ # The job runs on the repository variable LINUX_RUNNER, defaulting to the self-hosted scale set
5
+ # self-hosted-linux; any runner with git and bash 4 works. A repository without self-hosted runners sets
6
+ # LINUX_RUNNER to ubuntu-latest.
7
+ # Third-party actions are pinned to a commit SHA; the comment after it names the release it came from.
8
+ # Platform behavior this file relies on, by id in the service-facts package (github-actions entry):
9
+ # fact: action-sha-pinning
10
+ # fact: token-permissions-key
11
+ # fact: job-timeout-default
12
+ # fact: checkout-persist-credentials
13
+ name: main-commit-check
14
+ on:
15
+ schedule:
16
+ - cron: "0 18 * * *"
17
+ workflow_dispatch:
18
+ permissions:
19
+ contents: read
20
+ env:
21
+ # a loop of a template script asks twice at most and the CI gate asks twice (decision self-hosted-job-no-wait)
22
+ POLL_TRIES: "2"
23
+ CI_GATE_TRIES: "2"
24
+ CI_GATE_QUEUE_TRIES: "0"
25
+
26
+ jobs:
27
+ check:
28
+ runs-on: ${{ vars.LINUX_RUNNER || 'self-hosted-linux' }}
29
+ timeout-minutes: 10
30
+ defaults:
31
+ run:
32
+ shell: bash
33
+ steps:
34
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
35
+ with:
36
+ fetch-depth: 0
37
+ persist-credentials: false
38
+ - name: check commits from the previous day
39
+ run: |
40
+ # the newest commit older than a day is the lower bound; a history younger than a day is checked whole
41
+ since="$(git rev-list -n1 --before='1 day ago' HEAD || true)"
42
+ bash scripts/ci/check-main-commits.sh "${since:+$since..}HEAD"