@tama-create/sf-tools 1.4.0-dev.3 → 1.4.0-dev.4

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.
@@ -64,7 +64,7 @@ export const projectCommand = {
64
64
  const box = sub !== "create" && sub !== "status" && raw.files.exists("sf-tools/config")
65
65
  ? fileLoggedBox(raw, `sf-tools/logs/project-${sub}.log`, `sft project ${sub}`)
66
66
  : raw;
67
- const templateDir = box.env("SF_TOOLS_WORKFLOW_TEMPLATE_DIR") || fileURLToPath(new URL("../../templates/.github/workflows", import.meta.url));
67
+ const templateDir = box.env("SF_TOOLS_WORKFLOW_TEMPLATE_DIR") || fileURLToPath(new URL("../../templates-ts/.github/workflows", import.meta.url));
68
68
  // status は読み取りのみ(確認の質問をしない)
69
69
  if (sub === "status")
70
70
  return runProjectStatus(rest, box, { folderName: basename(process.cwd()), templateDir });
@@ -202,6 +202,16 @@ export async function phaseRepoCreate(ctx) {
202
202
  repo.files.makeDir(to.slice(0, slash));
203
203
  repo.files.writeText(to, box.files.readText(`${tmpl}/${rel}`));
204
204
  }
205
+ // ワークフローは、sft 版(templates-ts)で上書きする(シェル版の templates/.github/workflows は、段階 6 まで残る)
206
+ const wf = ctx.deps.workflowsDir;
207
+ if (wf !== undefined) {
208
+ const names = box.files.walkFiles(wf);
209
+ if (names.length === 0)
210
+ throw new Error("empty-workflows");
211
+ repo.files.makeDir(".github/workflows");
212
+ for (const rel of names)
213
+ repo.files.writeText(`.github/workflows/${rel}`, box.files.readText(`${wf}/${rel}`));
214
+ }
205
215
  }
206
216
  catch {
207
217
  throw new CreateStop(1, "テンプレートファイルのコピーに失敗しました。");
@@ -45,6 +45,7 @@ export function realCreateDeps(box, workflowTemplateDir) {
45
45
  },
46
46
  cwd: process.cwd(),
47
47
  templatesDir: fileURLToPath(new URL("../../templates", import.meta.url)),
48
+ workflowsDir: workflowTemplateDir,
48
49
  gitmessageFile: fileURLToPath(new URL("../../config/install/gitmessage", import.meta.url)),
49
50
  workflowTemplateDir,
50
51
  doctor: realDoctorDeps(box),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tama-create/sf-tools",
3
- "version": "1.4.0-dev.3",
3
+ "version": "1.4.0-dev.4",
4
4
  "description": "Salesforce 開発の環境構築と毎日の作業を自動化する(TypeScript 版・開発中)",
5
5
  "license": "Unlicense",
6
6
  "repository": {
@@ -19,7 +19,8 @@
19
19
  "lib/typecheck.js",
20
20
  "lib/package.json",
21
21
  "config/",
22
- "templates/"
22
+ "templates/",
23
+ "templates-ts/"
23
24
  ],
24
25
  "engines": {
25
26
  "node": ">=24"
@@ -0,0 +1,109 @@
1
+ # ==============================================================================
2
+ # wf-metasync.yml - Salesforce メタデータ自動同期(sft 版。doc/rebuild-design.md 4.6)
3
+ # ==============================================================================
4
+ # main の Salesforce 組織(エイリアス prod)の最新のメタデータを取得し、変更があれば、Git の main ブランチにコミットして push する
5
+ # (Salesforce 組織の内容を正とする)。main の変更は、staging・develop のブランチへは伝播しない(一方通行の原則。
6
+ # doc/one-way-promotion-design.md 3.7)。Actions の画面での名前は「[metasync] メタ同期」(最上位の name:)。
7
+ # シェル版(templates/.github/workflows/wf-metasync.yml)との違い: sf-tools を git clone ではなく npm で入れ、
8
+ # ログインを `sft ci select-org`・`sft ci login`、同期を `sft metasync` に替えた。
9
+ #
10
+ # 【起動の条件】
11
+ # - schedule: cron "0 0 * * 1-5"(UTC の月〜金 0:00 = 日本時間の月〜金 9:00。毎日 1 回。--full 付き)と、
12
+ # cron "0 3-10/3 * * 1-5"(日本時間の月〜金 12:00・15:00・18:00)。既定のブランチ(main)にあるこのファイルで動く
13
+ # - workflow_dispatch(手動の実行。入力なし。--full 付き)。どのブランチで実行しても、main を取得して同期する
14
+ # - 起動しない場合: PR・push などのイベント
15
+ #
16
+ # 【ジョブ】
17
+ # 1. メタデータ同期(sync): 条件なしで、常に実行する。concurrency(グループ metasync・実行中のものは取り消さない)で、1 つずつ動く。
18
+ # 必須チェックではない(PR では動かない)
19
+ #
20
+ # 【処理の流れ】
21
+ # 1. main を、全履歴で、Secret PAT_TOKEN を使って取得する(以降の git push も、この PAT で行う)
22
+ # 2. Node.js 24 3. Salesforce CLI(npm install --global @salesforce/cli) 4. sft(npm ci --prefix sf-tools --ignore-scripts)
23
+ # 5. sft ci select-org(BASE_REF=main → *_PROD)→ sft ci login(エイリアス prod)
24
+ # 6. Git ユーザー情報を設定(github-actions[bot])
25
+ # 7. sft metasync(--full: 毎日 1 回の cron と、手動の実行。終了コード 3・4・5 は、sft metasync の説明を参照)
26
+ #
27
+ # 【必要な Secrets / Variables】
28
+ # Secrets: PAT_TOKEN・SF_PRIVATE_KEY・SF_CONSUMER_KEY_PROD・SLACK_BOT_TOKEN(任意)
29
+ # Variables: SF_USERNAME_PROD・SF_INSTANCE_URL_PROD・SF_METASYNC_DETECT / _FINGERPRINT / _SECRET_SCAN / _EXTRA(任意)・SLACK_CHANNEL_ID(任意)
30
+ #
31
+ # 【補足】
32
+ # - sft の呼び出しは、環境変数 SFT に 1 か所で書く(凍結した入口 bin/sft.js の場所: 設計 4.7)
33
+ # - 同期の実行中の待機の置き換え: 待機中のものは、より新しい実行に置き換えられるが、新しい実行が、その時点の最新を同期するため、漏れはない
34
+ # ==============================================================================
35
+ name: "[metasync] メタ同期"
36
+ on:
37
+ schedule:
38
+ - cron: "0 0 * * 1-5"
39
+ - cron: "0 3-10/3 * * 1-5"
40
+ workflow_dispatch:
41
+
42
+ env:
43
+ # sft の入口(絶対パス)
44
+ SFT: node ${{ github.workspace }}/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
45
+
46
+ jobs:
47
+ sync:
48
+ name: メタデータ同期
49
+ runs-on: ubuntu-latest
50
+ concurrency:
51
+ group: metasync
52
+ cancel-in-progress: false
53
+ permissions:
54
+ contents: write
55
+ steps:
56
+ # main を、完全な履歴付きで取得する(PAT_TOKEN を使う。以降の git push も、この PAT で行われる)
57
+ - name: ソースコードを取得
58
+ uses: actions/checkout@v7
59
+ with:
60
+ ref: main
61
+ fetch-depth: 0
62
+ token: ${{ secrets.PAT_TOKEN }}
63
+
64
+ - name: Node.js をインストール
65
+ uses: actions/setup-node@v7
66
+ with:
67
+ node-version: '24'
68
+ cache: npm
69
+ cache-dependency-path: sf-tools/package-lock.json
70
+
71
+ - name: Salesforce CLI をインストール
72
+ run: npm install --global @salesforce/cli
73
+
74
+ - name: 自動化ツール(sft)を入れる
75
+ run: npm ci --prefix sf-tools --ignore-scripts
76
+
77
+ - name: 接続先組織を選択(main の組織)
78
+ env:
79
+ BASE_REF: main
80
+ SF_CONSUMER_KEY_PROD: ${{ secrets.SF_CONSUMER_KEY_PROD }}
81
+ SF_USERNAME_PROD: ${{ vars.SF_USERNAME_PROD }}
82
+ SF_INSTANCE_URL_PROD: ${{ vars.SF_INSTANCE_URL_PROD }}
83
+ run: $SFT ci select-org
84
+
85
+ # sft metasync が使うエイリアス prod で登録する
86
+ - name: Salesforce 組織にログイン
87
+ env:
88
+ SF_PRIVATE_KEY: ${{ secrets.SF_PRIVATE_KEY }}
89
+ ORG_ALIAS: prod
90
+ run: $SFT ci login
91
+
92
+ - name: Git ユーザー情報を設定
93
+ run: |
94
+ git config user.name "github-actions[bot]"
95
+ git config user.email "github-actions[bot]@users.noreply.github.com"
96
+
97
+ - name: メタデータ取得・Git 同期を実行
98
+ env:
99
+ SF_METASYNC_DETECT: ${{ vars.SF_METASYNC_DETECT || 'off' }}
100
+ SF_METASYNC_FINGERPRINT: ${{ vars.SF_METASYNC_FINGERPRINT || 'off' }}
101
+ SF_METASYNC_SECRET_SCAN: ${{ vars.SF_METASYNC_SECRET_SCAN || 'shadow' }}
102
+ SF_METASYNC_EXTRA: ${{ vars.SF_METASYNC_EXTRA || 'off' }}
103
+ # リポジトリの公開・非公開の確認(gh api repos/…)に使う。公開、または確認できないときは、取得せずに止める(終了コード 5)
104
+ GH_TOKEN: ${{ github.token }}
105
+ # 止めたときの Slack 通知(任意)
106
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
107
+ SLACK_CHANNEL_ID: ${{ vars.SLACK_CHANNEL_ID }}
108
+ # --full: 毎日 1 回の cron(0 0 * * 1-5)と、手動の実行では、変更の検知が「変更なし」でも、全件取得する
109
+ run: $SFT metasync ${{ (github.event_name != 'schedule' || github.event.schedule == '0 0 * * 1-5') && '--full' || '' }}
@@ -0,0 +1,263 @@
1
+ # ==============================================================================
2
+ # wf-release.yml - Salesforce リリース(sft 版。doc/rebuild-design.md 4.6)
3
+ # ==============================================================================
4
+ # PR が main / staging / develop にマージされたら、マージ先のブランチに対応する Salesforce 組織へ、sft release --release で
5
+ # リリースし(組織に反映する)、リリースの印(commit status)を付け、結果を Slack に通知する。
6
+ # Actions の画面での名前は「[release] デプロイ」(最上位の name:)。
7
+ # シェル版(templates/.github/workflows/wf-release.yml)との違い: yml の中のシェルを `sft ci <手順>` に移した。
8
+ # あわせて、デプロイ対象が空で、sft の版(sf-tools/package.json・package-lock.json)か .github/workflows/ だけを変える PR は、
9
+ # 組織へは何も出さずに、リリースの印だけを付ける(ジョブ「印だけ付ける」。設計 4.3。付けないと、次の段階の PR が R1 で止まる)。
10
+ #
11
+ # 【起動の条件】
12
+ # - pull_request の closed で、マージ先が main / staging / develop のとき(マージせずに閉じた PR でも起動するが、
13
+ # リリースのジョブは、マージされたときだけ動く)
14
+ # - 手動の実行(workflow_dispatch)は、ない(PR を通らずに組織へ出せるため。doc/one-way-promotion-design.md 3.5)。
15
+ # 失敗したリリースのやり直しは、その実行の「Re-run jobs」で行う(同じイベント・同じコミットのため、確認も同じく通る)
16
+ #
17
+ # 【ジョブ】
18
+ # 1. リリース対象確認(check-branch): sft ci check-branch。出力 skip(true / false)・mark_only(印だけ付けるとき true)
19
+ # ジョブ名は、必須チェック「対象ファイル確認」と、わざと別(同じ名前だと、先の PR で付いた成功が、次の段階の PR の
20
+ # 必須チェックを満たしてしまうため)
21
+ # 2. リリース実行(release): PR がマージされ、skip が true でないときだけ。権限: contents: read・pull-requests: read・
22
+ # statuses: write・actions: read。同時実行は、マージ先のブランチごとに 1 つずつ(queue: max で、待機中も残す)
23
+ # 3. 印だけ付ける(mark-only): PR がマージされ、skip が true で、mark_only が true のときだけ。同じ concurrency。
24
+ # 印を付ける前に、リリースのジョブと同じく、一方通行の確認(R0〜R3)を行う(破っていれば、印を付けない)
25
+ #
26
+ # 【処理の流れ】
27
+ # リリース実行:
28
+ # 1. この PR のマージのコミット(merge_commit_sha)を、全履歴で取得(あとの PR の変更を混ぜない)
29
+ # 2. Node.js 24・Salesforce CLI・sft(npm ci --prefix sf-tools --ignore-scripts)
30
+ # 3. sft ci release-info(リリース先を、ログと Actions の要約に出す)
31
+ # 4. sft ci select-org → login(マージ先 main → prod、staging → staging、develop → develop のエイリアス)
32
+ # 5. PR の先端のコミットを force-promote-check に取得し、その sf-tools にも sft を入れて、sft ci promote-check --pr(R0〜R3。破っていれば、組織へは出さない)
33
+ # 6. sft ci release-run(branch_name.txt を書いて、release --release --no-open --target <別名>)
34
+ # 7. sft ci release-mark(成功したときだけ。3 回まで試し、だめなら失敗)
35
+ # 8. (常に)sft ci slack-release(失敗しても、ステップは失敗にしない)
36
+ #
37
+ # 【必要な Secrets / Variables】
38
+ # Secrets: SF_PRIVATE_KEY・SF_CONSUMER_KEY_PROD / _STG / _DEV・SLACK_BOT_TOKEN(任意)
39
+ # Variables: SF_USERNAME_*・SF_INSTANCE_URL_*・SLACK_CHANNEL_ID(任意)
40
+ #
41
+ # 【補足】
42
+ # - sft の呼び出しは、環境変数 SFT に 1 か所で書く(凍結した入口 bin/sft.js の場所: 設計 4.7)
43
+ # - リリースの印の context(sf-tools/released-<段階>)は、版をまたいで凍結(設計 4.7)
44
+ # - check-branch の判定は、validate と同じ手順を使う(マージ先は main・staging・develop のどれかなので、段階の判定も同じ)
45
+ # ==============================================================================
46
+ name: "[release] デプロイ"
47
+ on:
48
+ pull_request:
49
+ types: [closed]
50
+ branches:
51
+ - main
52
+ - staging
53
+ - develop
54
+
55
+ env:
56
+ # sft の入口(絶対パス。working-directory を変えるステップからも呼ぶため)
57
+ SFT: node ${{ github.workspace }}/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
58
+
59
+ jobs:
60
+ check-branch:
61
+ name: リリース対象確認
62
+ runs-on: ubuntu-latest
63
+ outputs:
64
+ skip: ${{ steps.check.outputs.skip }}
65
+ mark_only: ${{ steps.check.outputs.mark_only }}
66
+ permissions:
67
+ contents: read
68
+ pull-requests: read # 変更するファイルの一覧(版・ワークフローの変更の確認)を読むため
69
+ steps:
70
+ - uses: actions/checkout@v7
71
+ - uses: actions/setup-node@v7
72
+ with:
73
+ node-version: '24'
74
+ cache: npm
75
+ cache-dependency-path: sf-tools/package-lock.json
76
+ - name: 自動化ツール(sft)を入れる
77
+ run: npm ci --prefix sf-tools --ignore-scripts
78
+ - id: check
79
+ name: デプロイ対象ファイルを確認
80
+ env:
81
+ # 利用者が決められる値は、シェルに直接埋め込まず、環境変数で受け取る
82
+ HEAD_REF: ${{ github.event.pull_request.head.ref }}
83
+ # リリース先(PR のマージ先)
84
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
85
+ REPOSITORY: ${{ github.repository }}
86
+ PR_NUMBER: ${{ github.event.pull_request.number }}
87
+ GH_TOKEN: ${{ github.token }}
88
+ run: $SFT ci check-branch
89
+
90
+ release:
91
+ name: リリース実行
92
+ needs: check-branch
93
+ # PR がマージされたときだけ、リリースする
94
+ if: github.event.pull_request.merged == true && needs.check-branch.outputs.skip != 'true'
95
+ runs-on: ubuntu-latest
96
+ # 一方通行の確認(PR・コミットの状態・Actions の実行を読む)と、リリースの印(commit status)を付けるための権限
97
+ permissions:
98
+ contents: read
99
+ pull-requests: read
100
+ statuses: write
101
+ actions: read
102
+ # 同じ組織(マージ先のブランチ)へのリリースは、1 つずつ動かす。queue: max で、待機中の実行を置き換えずに、すべて残す
103
+ # (各実行は、自分のソースブランチのリストだけをリリースする)。実行中のものは取り消さない
104
+ concurrency:
105
+ group: release-${{ github.event.pull_request.base.ref }}
106
+ cancel-in-progress: false
107
+ queue: max
108
+ steps:
109
+ # この PR のマージのコミットに固定する。続けてマージされたとき、あとの PR の変更を、この PR のリリースに混ぜないため
110
+ - name: ソースコードを取得
111
+ uses: actions/checkout@v7
112
+ with:
113
+ ref: ${{ github.event.pull_request.merge_commit_sha }}
114
+ fetch-depth: 0
115
+
116
+ - name: Node.js をインストール
117
+ uses: actions/setup-node@v7
118
+ with:
119
+ node-version: '24'
120
+ cache: npm
121
+ cache-dependency-path: sf-tools/package-lock.json
122
+
123
+ - name: Salesforce CLI をインストール
124
+ run: npm install --global @salesforce/cli
125
+
126
+ - name: 自動化ツール(sft)を入れる
127
+ run: npm ci --prefix sf-tools --ignore-scripts
128
+
129
+ - name: リリース先を確認
130
+ env:
131
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
132
+ PR_TITLE_RAW: ${{ github.event.pull_request.title || '' }}
133
+ PR_NUMBER_RAW: ${{ github.event.pull_request.number || '' }}
134
+ run: $SFT ci release-info
135
+
136
+ - name: 接続先組織を選択(マージ先ブランチに応じて切り替え)
137
+ env:
138
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
139
+ SF_CONSUMER_KEY_PROD: ${{ secrets.SF_CONSUMER_KEY_PROD }}
140
+ SF_USERNAME_PROD: ${{ vars.SF_USERNAME_PROD }}
141
+ SF_INSTANCE_URL_PROD: ${{ vars.SF_INSTANCE_URL_PROD }}
142
+ SF_CONSUMER_KEY_STG: ${{ secrets.SF_CONSUMER_KEY_STG }}
143
+ SF_USERNAME_STG: ${{ vars.SF_USERNAME_STG }}
144
+ SF_INSTANCE_URL_STG: ${{ vars.SF_INSTANCE_URL_STG }}
145
+ SF_CONSUMER_KEY_DEV: ${{ secrets.SF_CONSUMER_KEY_DEV }}
146
+ SF_USERNAME_DEV: ${{ vars.SF_USERNAME_DEV }}
147
+ SF_INSTANCE_URL_DEV: ${{ vars.SF_INSTANCE_URL_DEV }}
148
+ run: $SFT ci select-org
149
+
150
+ - name: Salesforce 組織にログイン
151
+ env:
152
+ SF_PRIVATE_KEY: ${{ secrets.SF_PRIVATE_KEY }}
153
+ # main → prod・staging → staging・develop → develop(sft release --target のエイリアス)
154
+ ORG_ALIAS: ${{ github.event.pull_request.base.ref == 'main' && 'prod' || github.event.pull_request.base.ref == 'staging' && 'staging' || 'develop' }}
155
+ run: $SFT ci login
156
+
157
+ # 一方通行の確認(最後の守り): PR の先端のコミットを別のフォルダ(force-promote-check。作業ツリーを分けるための名前)に取得し、R0〜R3 をすべて確かめる。
158
+ # 破っていれば、ここでジョブを失敗にし、組織へは出さない
159
+ - name: 一方通行の確認用に、PR の先端のコミットを取得
160
+ uses: actions/checkout@v7
161
+ with:
162
+ ref: ${{ github.event.pull_request.head.sha }}
163
+ path: force-promote-check
164
+ fetch-depth: 0
165
+
166
+ # force-promote-check(PR の先端のコミット)の中の sft は、そのコミットの sf-tools/package.json の版に固定されているため、
167
+ # その版を、そこにも入れる(入れないと、固定した版が入っていないとして止まる)
168
+ - name: 自動化ツール(sft)を、PR の先端のコミットにも入れる
169
+ run: npm ci --prefix force-promote-check/sf-tools --ignore-scripts
170
+
171
+ - name: 一方通行の確認(順序・積み重ね・環境ブランチ)
172
+ id: promote
173
+ working-directory: force-promote-check
174
+ env:
175
+ SFT: node ${{ github.workspace }}/force-promote-check/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
176
+ GH_TOKEN: ${{ github.token }}
177
+ PR_NUMBER: ${{ github.event.pull_request.number }}
178
+ run: $SFT ci promote-check --pr "$PR_NUMBER"
179
+
180
+ - name: Salesforce にリリースを実行
181
+ env:
182
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
183
+ SOURCE_BRANCH: ${{ github.event.pull_request.head.ref }}
184
+ run: $SFT ci release-run
185
+
186
+ - name: リリースの印を付ける
187
+ env:
188
+ GH_TOKEN: ${{ github.token }}
189
+ REPOSITORY: ${{ github.repository }}
190
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
191
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
192
+ PR_NUMBER: ${{ github.event.pull_request.number }}
193
+ RUN_ID: ${{ github.run_id }}
194
+ run: $SFT ci release-mark
195
+
196
+ - name: Slack に結果を通知
197
+ if: always()
198
+ env:
199
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
200
+ SLACK_CHANNEL_ID: ${{ vars.SLACK_CHANNEL_ID }}
201
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
202
+ PR_TITLE_RAW: ${{ github.event.pull_request.title || '' }}
203
+ PR_NUMBER_RAW: ${{ github.event.pull_request.number || '' }}
204
+ REPOSITORY: ${{ github.repository }}
205
+ RUN_ID: ${{ github.run_id }}
206
+ JOB_STATUS: ${{ job.status }}
207
+ PROMOTE_OUTCOME: ${{ steps.promote.outcome }}
208
+ run: $SFT ci slack-release
209
+
210
+ mark-only:
211
+ name: 印だけ付ける
212
+ needs: check-branch
213
+ # デプロイ対象がなく、版・ワークフローだけを変える PR(組織へは何も出さない)。印がないと、次の段階の PR が R1 で止まる
214
+ if: github.event.pull_request.merged == true && needs.check-branch.outputs.skip == 'true' && needs.check-branch.outputs.mark_only == 'true'
215
+ runs-on: ubuntu-latest
216
+ # 一方通行の確認(PR・コミットの状態・Actions の実行を読む)と、リリースの印(commit status)を付けるための権限
217
+ permissions:
218
+ contents: read
219
+ pull-requests: read
220
+ statuses: write
221
+ actions: read
222
+ concurrency:
223
+ group: release-${{ github.event.pull_request.base.ref }}
224
+ cancel-in-progress: false
225
+ queue: max
226
+ steps:
227
+ - uses: actions/checkout@v7
228
+ with:
229
+ ref: ${{ github.event.pull_request.merge_commit_sha }}
230
+ - uses: actions/setup-node@v7
231
+ with:
232
+ node-version: '24'
233
+ cache: npm
234
+ cache-dependency-path: sf-tools/package-lock.json
235
+ - name: 自動化ツール(sft)を入れる
236
+ run: npm ci --prefix sf-tools --ignore-scripts
237
+ # 印を付ける前に、リリースのジョブと同じく、一方通行の確認(R0〜R3)を行う。破っていれば、印を付けない
238
+ - name: 一方通行の確認用に、PR の先端のコミットを取得
239
+ uses: actions/checkout@v7
240
+ with:
241
+ ref: ${{ github.event.pull_request.head.sha }}
242
+ path: force-promote-check
243
+ fetch-depth: 0
244
+ - name: 自動化ツール(sft)を、PR の先端のコミットにも入れる
245
+ run: npm ci --prefix force-promote-check/sf-tools --ignore-scripts
246
+ - name: 一方通行の確認(順序・積み重ね・環境ブランチ)
247
+ working-directory: force-promote-check
248
+ env:
249
+ SFT: node ${{ github.workspace }}/force-promote-check/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
250
+ GH_TOKEN: ${{ github.token }}
251
+ PR_NUMBER: ${{ github.event.pull_request.number }}
252
+ run: $SFT ci promote-check --pr "$PR_NUMBER" --tooling
253
+
254
+ - name: リリースの印だけを付ける(組織へは出さない)
255
+ env:
256
+ GH_TOKEN: ${{ github.token }}
257
+ REPOSITORY: ${{ github.repository }}
258
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
259
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
260
+ PR_NUMBER: ${{ github.event.pull_request.number }}
261
+ RUN_ID: ${{ github.run_id }}
262
+ MARK_ONLY: 'true'
263
+ run: $SFT ci release-mark
@@ -0,0 +1,150 @@
1
+ # ==============================================================================
2
+ # wf-sequence.yml - Salesforce マージ順序チェック(sft 版。doc/rebuild-design.md 4.6)
3
+ # ==============================================================================
4
+ # main / staging への PR で、一方通行のリリース(develop → staging → main に、同じコミットのまま上げる。
5
+ # doc/one-way-promotion-design.md)の順序を確かめる。判定の本体は sft ci sequence-check(中で sft ci promote-check --only sequence = R0・R1・R3 を呼ぶ)。
6
+ # 段階の並びは、常に origin/main の sf-tools/config/branches.txt から読む。
7
+ # - 順序外(R1: PR の先端のコミットに、前の段階のリリースの印がない)・環境ブランチからの PR(R3)・判断できない(R0): ジョブ
8
+ # 「順序チェック」を失敗にする(警告だけにはしない。Hotfix の例外もない)
9
+ # 順序外・環境ブランチのときは、PR の会話欄にコメントを投稿し(同じ PR では、既存のコメントを更新する)、Slack に通知する。
10
+ # シェル版(templates/.github/workflows/wf-sequence.yml)との違い: yml の中のシェルを `sft ci <手順>` に移した。
11
+ # 対象が空でも、sft の版(sf-tools/package.json・package-lock.json)と .github/workflows/ を変える PR は、順序チェックを
12
+ # 実行する(設計 4.3 の R1。変更の一覧は gh api で読み、読めなければ素通りさせない)。
13
+ # Actions の画面での名前は「[sequence] マージ順序チェック」(最上位の name:)。
14
+ #
15
+ # 【起動の条件】
16
+ # - pull_request(opened / synchronize / reopened)で、マージ先が main または staging のとき
17
+ # - 起動しない場合: develop など、main / staging 以外への PR。edited・closed・直接の push・コンフリクトのある PR
18
+ #
19
+ # 【ジョブ】
20
+ # 1. 対象ファイル確認(check-branch): sft ci sequence-branch。順序チェックが必要かを判定し、出力 skip を返す。常に実行する
21
+ # 2. 順序チェック(check-promotion-order): check-branch のあと。skip が true のときは、スキップされる
22
+ # ジョブ名「対象ファイル確認」「順序チェック」は、ブランチ保護の必須チェック(名前の正本は lib/project.sh の
23
+ # required_status_check_names)。ジョブ名(name:)を変えると、PR をマージできなくなる。スキップされたジョブは、必須チェック
24
+ # としては成功として扱われる
25
+ #
26
+ # 【処理の流れ】
27
+ # 対象ファイル確認: 1. PR のマージ結果を取得 2. sft を入れる 3. sft ci sequence-branch
28
+ # (環境ブランチからの PR は skip=false。対象が空なら skip=true。ただし、版・ワークフローを変える PR は skip=false)
29
+ # 順序チェック:
30
+ # 1. PR の先端のコミットを、全履歴で force-promote-check に取得 2. sft を入れる(force-promote-check の中の sf-tools に。PR の先端の版)
31
+ # 3. sft ci sequence-check(出力 feature・detail・env_branch・out_of_order。0 でなければ失敗)
32
+ # 4. (順序外・環境ブランチのとき。常に)sft ci slack-sequence(失敗しても、ステップは失敗にしない)
33
+ # 5. (常に)sft ci sequence-comment(目印 <!-- sf-tools:sequence --> のコメントを更新)
34
+ #
35
+ # 【必要な Secrets / Variables】
36
+ # Secrets: SLACK_BOT_TOKEN(任意) Variables: SLACK_CHANNEL_ID(任意)
37
+ # 自動の GITHUB_TOKEN(permissions: contents: read・pull-requests: write・statuses: read・actions: read)
38
+ #
39
+ # 【補足】
40
+ # - sft の呼び出しは、環境変数 SFT に 1 か所で書く(凍結した入口 bin/sft.js の場所: 設計 4.7)
41
+ # - 一方通行の印(commit status の context・path)の形は、版をまたいで凍結(設計 4.7)。前の段階の別の版の wf-release が付けた印を読む
42
+ # ==============================================================================
43
+ name: "[sequence] マージ順序チェック"
44
+ on:
45
+ pull_request:
46
+ branches:
47
+ - main
48
+ - staging
49
+
50
+ env:
51
+ # sft の入口(絶対パス。working-directory を変えるステップからも呼ぶため)
52
+ SFT: node ${{ github.workspace }}/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
53
+
54
+ jobs:
55
+ check-branch:
56
+ name: 対象ファイル確認
57
+ runs-on: ubuntu-latest
58
+ outputs:
59
+ skip: ${{ steps.check.outputs.skip }}
60
+ permissions:
61
+ contents: read
62
+ pull-requests: read # 変更するファイルの一覧(版・ワークフローの変更の確認)を読むため
63
+ steps:
64
+ - uses: actions/checkout@v7
65
+ - uses: actions/setup-node@v7
66
+ with:
67
+ node-version: '24'
68
+ cache: npm
69
+ cache-dependency-path: sf-tools/package-lock.json
70
+ - name: 自動化ツール(sft)を入れる
71
+ run: npm ci --prefix sf-tools --ignore-scripts
72
+ - id: check
73
+ name: デプロイ対象ファイルを確認
74
+ env:
75
+ # 利用者が決められる値は、シェルに直接埋め込まず、環境変数で受け取る
76
+ HEAD_REF: ${{ github.event.pull_request.head.ref }}
77
+ REPOSITORY: ${{ github.repository }}
78
+ PR_NUMBER: ${{ github.event.pull_request.number }}
79
+ GH_TOKEN: ${{ github.token }}
80
+ run: $SFT ci sequence-branch
81
+
82
+ check-promotion-order:
83
+ name: 順序チェック
84
+ needs: check-branch
85
+ if: needs.check-branch.outputs.skip != 'true'
86
+ runs-on: ubuntu-latest
87
+ permissions:
88
+ contents: read
89
+ pull-requests: write # 順序外・環境ブランチの ⛔ のコメントを、PR の会話欄に投稿するため(PR を読むのにも使う)
90
+ statuses: read # リリースの印(commit status)を読むため
91
+ actions: read # 印を付けた wf-release の実行を確かめるため
92
+ steps:
93
+ # 一方通行の確認は、PR の先端のコミットを全履歴で取得した作業ツリーで行う
94
+ #(作業ツリーを分けるためのフォルダ force-promote-check に取得する)
95
+ - name: ソースコードを取得
96
+ uses: actions/checkout@v7
97
+ with:
98
+ ref: ${{ github.event.pull_request.head.sha }}
99
+ path: force-promote-check
100
+ fetch-depth: 0
101
+
102
+ # sft は、PR のマージ結果ではなく、先端のコミットの sf-tools/package.json の版を入れる
103
+ #(sf-tools は、force-promote-check の中。このジョブの SFT も、その中の sf-tools を指す)
104
+ - uses: actions/setup-node@v7
105
+ with:
106
+ node-version: '24'
107
+ cache: npm
108
+ cache-dependency-path: force-promote-check/sf-tools/package-lock.json
109
+ - name: 自動化ツール(sft)を入れる
110
+ run: npm ci --prefix force-promote-check/sf-tools --ignore-scripts
111
+
112
+ - name: マージ順序を検証
113
+ id: sequence_check
114
+ working-directory: force-promote-check
115
+ env:
116
+ SFT: node ${{ github.workspace }}/force-promote-check/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
117
+ GH_TOKEN: ${{ github.token }}
118
+ PR_NUMBER: ${{ github.event.pull_request.number }}
119
+ # ブランチ名は、シェルに直接埋め込まず、環境変数で受け取る
120
+ FEATURE_REF: ${{ github.event.pull_request.head.ref }}
121
+ run: $SFT ci sequence-check
122
+
123
+ - name: Slack に順序未確認を通知
124
+ if: always() && (steps.sequence_check.outputs.out_of_order == 'true' || steps.sequence_check.outputs.env_branch == 'true')
125
+ env:
126
+ SFT: node ${{ github.workspace }}/force-promote-check/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
127
+ ENV_BRANCH: ${{ steps.sequence_check.outputs.env_branch }}
128
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
129
+ SLACK_CHANNEL_ID: ${{ vars.SLACK_CHANNEL_ID }}
130
+ FEATURE_RAW: ${{ steps.sequence_check.outputs.feature }}
131
+ DETAIL_RAW: ${{ steps.sequence_check.outputs.detail }}
132
+ PR_TITLE_RAW: ${{ github.event.pull_request.title || '' }}
133
+ PR_NUMBER_RAW: ${{ github.event.pull_request.number || '' }}
134
+ PR_URL_RAW: ${{ github.event.pull_request.html_url || '' }}
135
+ BASE_RAW: ${{ github.event.pull_request.base.ref }}
136
+ run: $SFT ci slack-sequence
137
+
138
+ - name: 順序の結果を PR に投稿
139
+ if: always() && github.event_name == 'pull_request' && (steps.sequence_check.outputs.out_of_order != '' || steps.sequence_check.outputs.env_branch == 'true')
140
+ env:
141
+ SFT: node ${{ github.workspace }}/force-promote-check/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
142
+ GH_TOKEN: ${{ github.token }}
143
+ REPOSITORY: ${{ github.repository }}
144
+ PR_NUMBER: ${{ github.event.pull_request.number }}
145
+ ENV_BRANCH: ${{ steps.sequence_check.outputs.env_branch }}
146
+ OUT_OF_ORDER: ${{ steps.sequence_check.outputs.out_of_order }}
147
+ FEATURE: ${{ steps.sequence_check.outputs.feature }}
148
+ DETAIL: ${{ steps.sequence_check.outputs.detail }}
149
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
150
+ run: $SFT ci sequence-comment
@@ -0,0 +1,184 @@
1
+ # ==============================================================================
2
+ # wf-validate.yml - Salesforce デプロイ前検証(sft 版。doc/rebuild-design.md 4.6)
3
+ # ==============================================================================
4
+ # PR の作成・更新のたびに、sft release を検証モード(sf project deploy start --dry-run。組織には反映しない)で実行し、
5
+ # 結果を PR にコメントする。検証が失敗すると、ジョブ「デプロイ検証」が失敗する(main / staging への PR では、ブランチ保護の
6
+ # 必須チェックのため、マージできなくなる)。Actions の画面での名前は「[validate] デプロイ前検証」(最上位の name:)。
7
+ # シェル版(templates/.github/workflows/wf-validate.yml)との違いは、yml の中のシェルを、すべて `sft ci <手順>` に移したこと
8
+ # (手順の中身は src/core/ci-*.ts)。sf-tools は、git clone ではなく、force-* の sf-tools/package.json の版を npm で入れる。
9
+ #
10
+ # 【起動の条件】
11
+ # - pull_request の opened / synchronize / reopened。マージ先のブランチは問わない
12
+ # - 起動しない場合: PR のタイトル・本文・マージ先の変更(edited)、マージ・クローズ、ブランチへの直接の push、
13
+ # コンフリクトのある PR。workflow_dispatch・schedule はない
14
+ #
15
+ # 【ジョブ】
16
+ # 1. 対象ファイル確認(check-branch): sft ci check-branch。デプロイ対象があるかを判定し、出力 skip を返す。常に実行する
17
+ # 2. デプロイ検証(validate): check-branch のあと(needs)。skip が true のときは、スキップされる
18
+ # ジョブ名「対象ファイル確認」「デプロイ検証」は、ブランチ保護(Ruleset protect-main / protect-staging)の必須チェック
19
+ # (名前の正本は lib/project.sh の required_status_check_names)。ジョブ名(name:)を変えると、PR をマージできなくなる。
20
+ # スキップされたジョブは、必須チェックとしては成功として扱われる
21
+ #
22
+ # 【処理の流れ】
23
+ # 対象ファイル確認: 1. PR のマージ結果を取得 2. sft を入れる 3. sft ci check-branch(段階の判定・対象ファイルの確認)
24
+ # デプロイ検証:
25
+ # 1. PR のマージ結果を取得 2. Node.js 24 3. Salesforce CLI(npm install -g @salesforce/cli)
26
+ # 4. sft を入れる(npm ci --prefix sf-tools。npm のキャッシュは sf-tools/package-lock.json を鍵にする)
27
+ # 5. sft ci select-org(マージ先 main → *_PROD、staging → *_STG、それ以外 → *_DEV。GITHUB_ENV に書く)
28
+ # 6. sft ci login(JWT。秘密鍵は、必ず消す)
29
+ # 7. sf-tools/release/branch_name.txt に、ソースブランチ名を書く
30
+ # 7.5 PR の先端のコミットを、全履歴で force-promote-check に取得する
31
+ # 7.6 その force-promote-check/sf-tools にも sft を入れる(npm ci --prefix force-promote-check/sf-tools --ignore-scripts。PR が版を変えても、確認は PR 側の sft で動く)
32
+ # 8. sft ci validate-stack(一方通行の確認 R0・R2。出力 stack_exit)→ sft ci validate-release(出力 exit_code)
33
+ # 9. (常に)sft ci validate-comment(PR にコメント)
34
+ # 10. (常に)sft ci validate-gate(exit_code で終了。空は 1)
35
+ #
36
+ # 【必要な Secrets / Variables】
37
+ # Secrets: SF_PRIVATE_KEY・SF_CONSUMER_KEY_PROD・SF_CONSUMER_KEY_STG・SF_CONSUMER_KEY_DEV
38
+ # Variables: SF_USERNAME_PROD / _STG / _DEV・SF_INSTANCE_URL_PROD / _STG / _DEV
39
+ # このほか、自動の GITHUB_TOKEN を使う(permissions: pull-requests: write・contents: read・statuses: read・actions: read)
40
+ #
41
+ # 【補足】
42
+ # - sft の呼び出しは、環境変数 SFT に 1 か所で書く(凍結した入口 bin/sft.js の場所: 設計 4.7)
43
+ # - 一方通行の確認のうち、順序(R1)と環境ブランチ(R3)は wf-sequence.yml、すべて(R0〜R3)は wf-release.yml が確かめる
44
+ # - Slack への通知はしない
45
+ # - フォークからの PR では、Secrets が渡されないため、ログインで失敗する
46
+ # ==============================================================================
47
+ name: "[validate] デプロイ前検証"
48
+ on:
49
+ pull_request:
50
+ types: [opened, synchronize, reopened]
51
+
52
+ env:
53
+ # sft の入口(絶対パス。working-directory を変えるステップからも呼ぶため)
54
+ SFT: node ${{ github.workspace }}/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
55
+
56
+ jobs:
57
+ check-branch:
58
+ name: 対象ファイル確認
59
+ runs-on: ubuntu-latest
60
+ outputs:
61
+ skip: ${{ steps.check.outputs.skip }}
62
+ permissions:
63
+ contents: read
64
+ steps:
65
+ - uses: actions/checkout@v7
66
+ - uses: actions/setup-node@v7
67
+ with:
68
+ node-version: '24'
69
+ cache: npm
70
+ cache-dependency-path: sf-tools/package-lock.json
71
+ - name: 自動化ツール(sft)を入れる
72
+ run: npm ci --prefix sf-tools --ignore-scripts
73
+ - id: check
74
+ name: デプロイ対象ファイルを確認
75
+ env:
76
+ # 利用者が決められる値は、シェルに直接埋め込まず、環境変数で受け取る
77
+ HEAD_REF: ${{ github.event.pull_request.head.ref }}
78
+ BASE_REF: ${{ github.event.pull_request.base.ref || github.ref_name }}
79
+ run: $SFT ci check-branch
80
+
81
+ validate:
82
+ name: デプロイ検証
83
+ needs: check-branch
84
+ if: needs.check-branch.outputs.skip != 'true'
85
+ runs-on: ubuntu-latest
86
+ # PR へのコメント投稿・一方通行の確認(リリースの印と、印を付けた実行を読む)に必要
87
+ permissions:
88
+ pull-requests: write
89
+ contents: read
90
+ statuses: read
91
+ actions: read
92
+ steps:
93
+ - name: ソースコードを取得
94
+ uses: actions/checkout@v7
95
+
96
+ - name: Node.js をインストール
97
+ uses: actions/setup-node@v7
98
+ with:
99
+ node-version: '24'
100
+ cache: npm
101
+ cache-dependency-path: sf-tools/package-lock.json
102
+
103
+ - name: Salesforce CLI をインストール
104
+ run: npm install -g @salesforce/cli
105
+
106
+ - name: 自動化ツール(sft)を入れる
107
+ run: npm ci --prefix sf-tools --ignore-scripts
108
+
109
+ - name: 接続先組織を選択(マージ先ブランチに応じて切り替え)
110
+ env:
111
+ BASE_REF: ${{ github.event.pull_request.base.ref || github.ref_name }}
112
+ SF_CONSUMER_KEY_PROD: ${{ secrets.SF_CONSUMER_KEY_PROD }}
113
+ SF_USERNAME_PROD: ${{ vars.SF_USERNAME_PROD }}
114
+ SF_INSTANCE_URL_PROD: ${{ vars.SF_INSTANCE_URL_PROD }}
115
+ SF_CONSUMER_KEY_STG: ${{ secrets.SF_CONSUMER_KEY_STG }}
116
+ SF_USERNAME_STG: ${{ vars.SF_USERNAME_STG }}
117
+ SF_INSTANCE_URL_STG: ${{ vars.SF_INSTANCE_URL_STG }}
118
+ SF_CONSUMER_KEY_DEV: ${{ secrets.SF_CONSUMER_KEY_DEV }}
119
+ SF_USERNAME_DEV: ${{ vars.SF_USERNAME_DEV }}
120
+ SF_INSTANCE_URL_DEV: ${{ vars.SF_INSTANCE_URL_DEV }}
121
+ run: $SFT ci select-org
122
+
123
+ - name: Salesforce 組織にログイン
124
+ env:
125
+ SF_PRIVATE_KEY: ${{ secrets.SF_PRIVATE_KEY }}
126
+ ORG_ALIAS: ci-org
127
+ run: $SFT ci login
128
+
129
+ - name: デプロイ対象ブランチを設定
130
+ env:
131
+ SOURCE_BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }}
132
+ run: |
133
+ mkdir -p sf-tools/release
134
+ printf '%s\n' "$SOURCE_BRANCH" > sf-tools/release/branch_name.txt
135
+ echo "対象ブランチ: ${SOURCE_BRANCH}"
136
+
137
+ # 一方通行の確認用に、PR の先端のコミット(head.sha)を、全履歴で取得する
138
+ #(作業ツリーを分けるためのフォルダ force-promote-check に取得する)
139
+ - name: 一方通行の確認用に、PR の先端のコミットを取得
140
+ uses: actions/checkout@v7
141
+ with:
142
+ ref: ${{ github.event.pull_request.head.sha }}
143
+ path: force-promote-check
144
+ fetch-depth: 0
145
+
146
+ # force-promote-check(PR の先端のコミット)の中の sft は、そのコミットの sf-tools/package.json の版に固定されているため、
147
+ # その版を、そこにも入れる(入れないと、固定した版が入っていないとして止まる)
148
+ - name: 自動化ツール(sft)を、PR の先端のコミットにも入れる
149
+ run: npm ci --prefix force-promote-check/sf-tools --ignore-scripts
150
+
151
+ - name: 一方通行の確認(積み重ね)
152
+ id: stack
153
+ working-directory: force-promote-check
154
+ env:
155
+ SFT: node ${{ github.workspace }}/force-promote-check/sf-tools/node_modules/@tama-create/sf-tools/bin/sft.js
156
+ GH_TOKEN: ${{ github.token }}
157
+ PR_NUMBER: ${{ github.event.pull_request.number }}
158
+ run: $SFT ci validate-stack
159
+
160
+ - name: Salesforce にデプロイ検証を実行(反映なし)
161
+ id: sf_validate
162
+ env:
163
+ SF_TARGET_ORG: ci-org
164
+ STACK_EXIT: ${{ steps.stack.outputs.stack_exit }}
165
+ run: $SFT ci validate-release
166
+
167
+ - name: 検証結果を PR に投稿
168
+ if: always()
169
+ env:
170
+ GH_TOKEN: ${{ github.token }}
171
+ HEAD_REF: ${{ github.event.pull_request.head.ref || github.ref_name }}
172
+ BASE_REF: ${{ github.event.pull_request.base.ref || github.ref_name }}
173
+ HEAD_SHA: ${{ github.event.pull_request.head.sha || '' }}
174
+ # デプロイ検証の終了コード(そこまで届かなかった・取り消し・タイムアウトのときは、空)
175
+ EXIT_CODE: ${{ steps.sf_validate.outputs.exit_code }}
176
+ REPOSITORY: ${{ github.repository }}
177
+ PR_NUMBER: ${{ github.event.pull_request.number }}
178
+ run: $SFT ci validate-comment
179
+
180
+ - name: 検証失敗時はマージをブロック
181
+ if: always()
182
+ env:
183
+ EXIT_CODE: ${{ steps.sf_validate.outputs.exit_code }}
184
+ run: $SFT ci validate-gate