@tama-create/sf-tools 0.0.0-stage → 1.4.0-dev.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.
- package/LICENSE +24 -0
- package/README.md +212 -2
- package/bin/sft.js +22 -0
- package/dist/cli.js +35 -0
- package/dist/commands/admin.js +46 -0
- package/dist/commands/check.js +20 -0
- package/dist/commands/ci.js +123 -0
- package/dist/commands/deploy.js +31 -0
- package/dist/commands/doctor.js +11 -0
- package/dist/commands/dryrun.js +17 -0
- package/dist/commands/hook.js +46 -0
- package/dist/commands/index.js +36 -0
- package/dist/commands/job.js +31 -0
- package/dist/commands/launcher.js +40 -0
- package/dist/commands/log.js +58 -0
- package/dist/commands/metasync.js +21 -0
- package/dist/commands/pr.js +32 -0
- package/dist/commands/project.js +93 -0
- package/dist/commands/push.js +16 -0
- package/dist/commands/release.js +19 -0
- package/dist/commands/start.js +19 -0
- package/dist/commands/switch-org.js +12 -0
- package/dist/commands/update-cli.js +11 -0
- package/dist/commands/version.js +18 -0
- package/dist/core/admin-clone.js +79 -0
- package/dist/core/ai-answers.js +40 -0
- package/dist/core/branches.js +88 -0
- package/dist/core/check-targets.js +170 -0
- package/dist/core/check.js +34 -0
- package/dist/core/ci-check-branch.js +150 -0
- package/dist/core/ci-login-steps.js +73 -0
- package/dist/core/ci-release-steps.js +193 -0
- package/dist/core/ci-sequence-steps.js +188 -0
- package/dist/core/ci-validate-steps.js +140 -0
- package/dist/core/command.js +25 -0
- package/dist/core/create-connect.js +519 -0
- package/dist/core/create-setup.js +314 -0
- package/dist/core/create-state.js +82 -0
- package/dist/core/delegate.js +45 -0
- package/dist/core/deploy.js +66 -0
- package/dist/core/diag.js +200 -0
- package/dist/core/doctor.js +211 -0
- package/dist/core/eca.js +259 -0
- package/dist/core/exit-codes.js +12 -0
- package/dist/core/gh-identity.js +46 -0
- package/dist/core/hook-install.js +130 -0
- package/dist/core/hook.js +116 -0
- package/dist/core/identity.js +48 -0
- package/dist/core/job.js +243 -0
- package/dist/core/launcher-status.js +184 -0
- package/dist/core/lines.js +25 -0
- package/dist/core/log-auto.js +56 -0
- package/dist/core/log-box.js +85 -0
- package/dist/core/log-collector.js +370 -0
- package/dist/core/log-format.js +44 -0
- package/dist/core/log-pull.js +565 -0
- package/dist/core/log-select.js +126 -0
- package/dist/core/log-session.js +362 -0
- package/dist/core/log-start.js +421 -0
- package/dist/core/log-status.js +223 -0
- package/dist/core/log-summarize.js +127 -0
- package/dist/core/logger.js +71 -0
- package/dist/core/login-url.js +50 -0
- package/dist/core/manifest-build.js +118 -0
- package/dist/core/mask.js +70 -0
- package/dist/core/metadata-types.js +79 -0
- package/dist/core/metasync.js +684 -0
- package/dist/core/org.js +115 -0
- package/dist/core/origin.js +62 -0
- package/dist/core/package-xml.js +157 -0
- package/dist/core/pr.js +199 -0
- package/dist/core/project-create.js +733 -0
- package/dist/core/project-reconnect.js +126 -0
- package/dist/core/project-status.js +235 -0
- package/dist/core/project-tier.js +374 -0
- package/dist/core/project-verify.js +517 -0
- package/dist/core/promote-check.js +368 -0
- package/dist/core/promote.js +141 -0
- package/dist/core/push.js +152 -0
- package/dist/core/release.js +256 -0
- package/dist/core/scoped-box.js +29 -0
- package/dist/core/start.js +155 -0
- package/dist/core/switch-org.js +49 -0
- package/dist/core/test-types.js +212 -0
- package/dist/core/toolbox.js +4 -0
- package/dist/core/update-cli.js +156 -0
- package/dist/core/update-secret.js +301 -0
- package/dist/core/update-workflows.js +132 -0
- package/dist/core/verify-gh.js +286 -0
- package/dist/core/verify-samples.js +152 -0
- package/dist/core/windows-shim.js +21 -0
- package/dist/io/capability-file.js +11 -0
- package/dist/io/create-deps.js +68 -0
- package/dist/io/doctor-deps.js +32 -0
- package/dist/io/hook-install-deps.js +11 -0
- package/dist/io/job-deps.js +31 -0
- package/dist/io/key-file.js +17 -0
- package/dist/io/keys.js +161 -0
- package/dist/io/log-deps.js +106 -0
- package/dist/io/metasync-deps.js +21 -0
- package/dist/io/open-browser.js +21 -0
- package/dist/io/package-version.js +10 -0
- package/dist/io/pinned-project.js +111 -0
- package/dist/io/promote-deps.js +27 -0
- package/dist/io/push-refs.js +20 -0
- package/dist/io/resolve.js +74 -0
- package/dist/io/run.js +201 -0
- package/dist/io/switch-org-deps.js +10 -0
- package/dist/io/temp-dir.js +10 -0
- package/dist/io/tool-versions.js +14 -0
- package/dist/io/toolbox.js +68 -0
- package/dist/io/update-cli-deps.js +75 -0
- package/dist/io/update-secret-deps.js +27 -0
- package/dist/launch.js +152 -0
- package/dist/ui/confirm.js +18 -0
- package/dist/ui/launcher.js +132 -0
- package/dist/ui/prompt.js +66 -0
- package/package.json +37 -4
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import { runDiag, tierSuffix } from "./diag.js";
|
|
2
|
+
import { stripTermCodes } from "./log-format.js";
|
|
3
|
+
import { maskSecrets } from "./mask.js";
|
|
4
|
+
import { originRepo } from "./origin.js";
|
|
5
|
+
import { orgKindLabel } from "./project-status.js";
|
|
6
|
+
import { ghOwnerProblem } from "./update-secret.js";
|
|
7
|
+
import { EMPTY_TARGET, HELLO_SET, VerifyGh } from "./verify-gh.js";
|
|
8
|
+
import { labelsFileIsOurs, SAMPLE_LABELS_PATH, SAMPLE_OBJ, sampleSet } from "./verify-samples.js";
|
|
9
|
+
class Stop extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(code, message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const TOKEN_RE = /ghp_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{30,}|xox[bp]-[0-9A-Za-z-]{20,}|force:\/\/\S*:\S*:[^@\s]{20,}@/;
|
|
17
|
+
const JOB_RE = /^verify-(hello|comp)(-delete2?)?-[0-9]{6}$/;
|
|
18
|
+
const TIER_ORDER = ["develop", "staging", "main"];
|
|
19
|
+
/** ワークフローの、段階のログインのステップ名(文言を中立化する前に作られたリポジトリは、古い名前) */
|
|
20
|
+
export function loginStepNames(tier) {
|
|
21
|
+
const old = { main: "本番組織", staging: "ステージング組織", develop: "開発組織" };
|
|
22
|
+
return [`${tier} の組織にログイン(JWT)`, `${old[tier] ?? tier}にログイン(JWT)`];
|
|
23
|
+
}
|
|
24
|
+
/** リモートのブランチの一覧から、段階(リリースの順)。main がなければ null */
|
|
25
|
+
export function verifyTiers(branches) {
|
|
26
|
+
if (!branches.includes("main"))
|
|
27
|
+
return null;
|
|
28
|
+
const tiers = [];
|
|
29
|
+
if (branches.includes("develop") && branches.includes("staging"))
|
|
30
|
+
tiers.push("develop");
|
|
31
|
+
if (branches.includes("staging"))
|
|
32
|
+
tiers.push("staging");
|
|
33
|
+
tiers.push("main");
|
|
34
|
+
return tiers;
|
|
35
|
+
}
|
|
36
|
+
const err = (r, l) => r.box.output.err(l);
|
|
37
|
+
/** 1 件の確認を数えて表示する */
|
|
38
|
+
function check(r, desc, pass) {
|
|
39
|
+
if (pass) {
|
|
40
|
+
r.ok++;
|
|
41
|
+
err(r, `[SUCCESS] [OK] ${desc}`);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
r.ng++;
|
|
45
|
+
err(r, `[ERROR] [NG] ${desc}`);
|
|
46
|
+
}
|
|
47
|
+
return pass;
|
|
48
|
+
}
|
|
49
|
+
/** 実行が成功したか。失敗したらログの末尾を表示して、1 回だけ再実行する */
|
|
50
|
+
async function runOk(r, id, label) {
|
|
51
|
+
if ((await r.g.conclusion(id)) === "success")
|
|
52
|
+
return true;
|
|
53
|
+
err(r, `[WARNING] ${label}: 失敗しました。失敗したステップのログ(末尾 30 行):`);
|
|
54
|
+
for (const line of await r.g.failedLogTail(id, 30))
|
|
55
|
+
err(r, ` ${maskSecrets(stripTermCodes(line))}`);
|
|
56
|
+
err(r, `[WARNING] ${label}: 一時的な失敗の可能性があるため、1 回だけ再実行します。`);
|
|
57
|
+
if (!(await r.g.rerunAndWait(id)))
|
|
58
|
+
return false;
|
|
59
|
+
if ((await r.g.conclusion(id)) !== "success")
|
|
60
|
+
return false;
|
|
61
|
+
r.flaky++;
|
|
62
|
+
err(r, `[WARNING] ${label}: 再実行で成功しました(一時的な失敗だった可能性があります)。`);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
/** 段階のログインのステップの結果。候補の名前を 1 回ずつ読み、どれもなければ新しい名前を既定の回数まで読み直す */
|
|
66
|
+
async function loginConclusion(r, id, tier) {
|
|
67
|
+
const names = loginStepNames(tier);
|
|
68
|
+
for (const n of names) {
|
|
69
|
+
const c = await r.g.stepConclusion(id, n, 1);
|
|
70
|
+
if (c !== "")
|
|
71
|
+
return c;
|
|
72
|
+
}
|
|
73
|
+
return r.g.stepConclusion(id, names[0]);
|
|
74
|
+
}
|
|
75
|
+
/** 段階ごとの確認(その段階の組織に入り、別の組織に入っていないか) */
|
|
76
|
+
async function evidence(r, tier, id, kind) {
|
|
77
|
+
const sfx = tierSuffix(tier);
|
|
78
|
+
const user = r.vars.get(`SF_USERNAME_${sfx}`) ?? "";
|
|
79
|
+
check(r, `${kind}(${tier}): ${tier} の組織への JWT ログインが成功した`, (await loginConclusion(r, id, tier)) === "success");
|
|
80
|
+
for (const u of TIER_ORDER) {
|
|
81
|
+
if (u === tier)
|
|
82
|
+
continue;
|
|
83
|
+
const c = await loginConclusion(r, id, u);
|
|
84
|
+
if (c !== "")
|
|
85
|
+
check(r, `${kind}(${tier}): ${u} の組織へのログインは、実行されていない(別の組織に入っていない)`, c === "skipped");
|
|
86
|
+
else
|
|
87
|
+
err(r, `[WARNING] [注意] ${kind}(${tier}): ${u} のログインのステップを、見つけられませんでした(古いワークフローの可能性)。`);
|
|
88
|
+
}
|
|
89
|
+
check(r, `${kind}(${tier}): ${tier} の接続ユーザー(SF_USERNAME_${sfx})が、登録されている`, user !== "");
|
|
90
|
+
if (user !== "")
|
|
91
|
+
check(r, `${kind}(${tier}): ログインしたユーザーが、${tier} の接続ユーザー(${user})と一致する`, await r.g.logHas(id, user));
|
|
92
|
+
check(r, `${kind}(${tier}): ログに、${r.set.marker} が出ている`, await r.g.logHas(id, r.set.marker));
|
|
93
|
+
const log = (await r.g.log(id)) ?? "";
|
|
94
|
+
const slack = log.split("\n").some((l) => /Slack (の応答|response)/.test(l) && l.includes('"ok":true'));
|
|
95
|
+
if (!slack)
|
|
96
|
+
err(r, `[WARNING] [注意] ${kind}(${tier}): Slack への通知の成功(ok:true)を、確認できませんでした(検証の成否には、含めません)。`);
|
|
97
|
+
}
|
|
98
|
+
/** PR → wf-validate → マージ → wf-release。最後まで進めば、wf-release の実行 ID。途中で失敗すれば null */
|
|
99
|
+
async function prFlow(r, label, branch, title, base, mode) {
|
|
100
|
+
const bVal = await r.g.latestPrRun("wf-validate.yml", branch);
|
|
101
|
+
const bRel = await r.g.latestPrRun("wf-release.yml", branch);
|
|
102
|
+
const pr = await r.g.prCreate(branch, title, `sft project verify による検証(${r.what})。`, base);
|
|
103
|
+
if (!check(r, `${label}: PR を作成した(${base} 向け)`, pr !== null) || pr === null)
|
|
104
|
+
return null;
|
|
105
|
+
const val = await r.g.waitPrRun("wf-validate.yml", branch, bVal);
|
|
106
|
+
if (!check(r, `${label}: wf-validate(検証)が実行され、完了した`, val !== null) || val === null)
|
|
107
|
+
return null;
|
|
108
|
+
if (!check(r, `${label}: wf-validate が成功した`, await runOk(r, val, `${label}: wf-validate`)))
|
|
109
|
+
return null;
|
|
110
|
+
if (mode === "validate") {
|
|
111
|
+
// 検証のみ: ログにサンプルが出ていること(注意のみ)→ PR は、マージせずに閉じる(組織には何も反映しない)
|
|
112
|
+
if (!(await r.g.logHas(val, r.set.marker)))
|
|
113
|
+
err(r, `[WARNING] [注意] ${label}: wf-validate のログに、${r.set.marker} が出ていません(検証の成否には、含めません)。`);
|
|
114
|
+
return check(r, `${label}: PR を、マージせずに閉じた`, await r.g.prClose(pr)) ? val : null;
|
|
115
|
+
}
|
|
116
|
+
if (!check(r, `${label}: PR をマージした`, await r.g.prMerge(pr)))
|
|
117
|
+
return null;
|
|
118
|
+
if (mode === "release" && !r.left.includes(base))
|
|
119
|
+
r.left.push(base); // マージした時点から、組織にクラスが入った可能性がある
|
|
120
|
+
const rel = await r.g.waitPrRun("wf-release.yml", branch, bRel);
|
|
121
|
+
if (!check(r, `${label}: wf-release が実行され、完了した`, rel !== null) || rel === null)
|
|
122
|
+
return null;
|
|
123
|
+
if (!check(r, `${label}: wf-release が成功した`, await runOk(r, rel, `${label}: wf-release`)))
|
|
124
|
+
return null;
|
|
125
|
+
return rel;
|
|
126
|
+
}
|
|
127
|
+
async function makeReleaseBranch(r, branch) {
|
|
128
|
+
const sha = await r.g.branchSha("main");
|
|
129
|
+
if (!sha || !(await r.g.branchCreate(branch, sha)))
|
|
130
|
+
return false;
|
|
131
|
+
for (const p of r.set.paths("all")) {
|
|
132
|
+
if (!(await r.g.filePut(branch, p, r.set.content(p) ?? "", `verify: ${r.what} を追加`)))
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (!(await r.g.filePut(branch, `sf-tools/release/${branch}/deploy-target.txt`, r.set.deployTarget(), "verify: リリース対象")))
|
|
136
|
+
return false;
|
|
137
|
+
return r.g.filePut(branch, `sf-tools/release/${branch}/remove-target.txt`, EMPTY_TARGET, "verify: 削除対象(なし)");
|
|
138
|
+
}
|
|
139
|
+
/** 削除用のブランチ(ファイルの削除と削除対象)。--components は、リリースした先(develop)の先頭から作る */
|
|
140
|
+
async function makeDeleteBranch(r, branch, stage, base) {
|
|
141
|
+
const sha = await r.g.branchSha(base);
|
|
142
|
+
if (!sha || !(await r.g.branchCreate(branch, sha)))
|
|
143
|
+
return false;
|
|
144
|
+
for (const p of r.set.paths(stage)) {
|
|
145
|
+
if (!(await r.g.fileDelete(branch, p, `verify: ${r.what} を削除`)))
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (!(await r.g.filePut(branch, `sf-tools/release/${branch}/deploy-target.txt`, EMPTY_TARGET, "verify: リリース対象(なし)")))
|
|
149
|
+
return false;
|
|
150
|
+
// --cleanup: どこまで消えているか分からないため、存在しない削除対象をエラーにしない(sf-release が解釈する)
|
|
151
|
+
const target = `${r.cleanup ? "# @ignore-missing\n" : ""}${r.set.removeTarget(stage)}`;
|
|
152
|
+
return r.g.filePut(branch, `sf-tools/release/${branch}/remove-target.txt`, target, "verify: 削除対象");
|
|
153
|
+
}
|
|
154
|
+
function logsClean(r) {
|
|
155
|
+
const home = r.box.env("HOME") || r.box.env("USERPROFILE") || "";
|
|
156
|
+
// シェル版の記録(~/sf-tools/logs)と、sft の記録(この force-* の sf-tools/logs。project-*.log もここに入る)の両方を見る
|
|
157
|
+
const dirs = [`${home}/sf-tools/logs`, "sf-tools/logs"];
|
|
158
|
+
let found = false;
|
|
159
|
+
for (const dir of dirs) {
|
|
160
|
+
for (const name of r.box.files.listDir(dir)) {
|
|
161
|
+
if (!name.endsWith(".log"))
|
|
162
|
+
continue;
|
|
163
|
+
let text = "";
|
|
164
|
+
try {
|
|
165
|
+
text = r.box.files.readText(`${dir}/${name}`);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (TOKEN_RE.test(text)) {
|
|
171
|
+
err(r, `[ERROR] Token(または認証 URL)らしい文字列が、ログに残っています: ${dir}/${name}`);
|
|
172
|
+
found = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return !found;
|
|
177
|
+
}
|
|
178
|
+
async function metasyncCheck(r) {
|
|
179
|
+
const id = await r.g.dispatch("wf-metasync.yml", "main");
|
|
180
|
+
if (!check(r, "環境(wf-metasync): 起動した", id !== null) || id === null)
|
|
181
|
+
return;
|
|
182
|
+
if (!check(r, "環境(wf-metasync): 完了した", await r.g.waitRun(id)))
|
|
183
|
+
return;
|
|
184
|
+
if (!check(r, "環境(wf-metasync): 成功した(Salesforce → Git の同期)", await runOk(r, id, "wf-metasync")))
|
|
185
|
+
return;
|
|
186
|
+
check(r, "環境(wf-metasync): Salesforce 組織への JWT ログインが成功した", (await r.g.stepConclusion(id, "Salesforce 組織にログイン")) === "success");
|
|
187
|
+
check(r, "環境(wf-metasync): sf-tools の取得が成功した(公開リポジトリを、Token なしで clone)", (await r.g.stepConclusion(id, "自動化ツール(sf-tools)を取得")) === "success");
|
|
188
|
+
}
|
|
189
|
+
function guidance(r, repo) {
|
|
190
|
+
err(r, "");
|
|
191
|
+
err(r, "[ERROR] 検証を、途中で止めました。");
|
|
192
|
+
if (r.left.length > 0) {
|
|
193
|
+
err(r, `[WARNING] ${r.what} が、次の段階の組織に、残っている可能性があります: ${r.left.join(" ")}`);
|
|
194
|
+
err(r, `[WARNING] 削除のみを、やり直すには、次を実行してください: ${r.cleanupCmd}`);
|
|
195
|
+
}
|
|
196
|
+
err(r, `[WARNING] PR が残っているときは、GitHub の画面で、確認してください(https://github.com/${repo}/pulls)。`);
|
|
197
|
+
}
|
|
198
|
+
async function deleteJobBranches(r, branches, repo) {
|
|
199
|
+
err(r, "=== 後始末(作業用ブランチの削除) ===");
|
|
200
|
+
let deleted = 0;
|
|
201
|
+
for (const b of branches) {
|
|
202
|
+
if (!JOB_RE.test(b)) {
|
|
203
|
+
err(r, `[WARNING] ${b}: 想定の形式の名前ではないため、削除しません。`);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (await r.g.branchHasOpenPr(b)) {
|
|
207
|
+
err(r, `[WARNING] ${b}: 開いている PR がある(または、確認できない)ため、削除しません。`);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (await r.g.branchDelete(b)) {
|
|
211
|
+
err(r, `[INFO] 作業用ブランチを削除しました: ${b}`);
|
|
212
|
+
deleted++;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
err(r, `[WARNING] ${b}: 削除できませんでした(GitHub の画面か、gh api -X DELETE repos/${repo}/git/refs/heads/${b} で、削除できます)。`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (deleted > 0)
|
|
219
|
+
err(r, `[INFO] PR の履歴は、PR の番号で残っています(${repo} の Pull requests)。`);
|
|
220
|
+
}
|
|
221
|
+
function stamp(box) {
|
|
222
|
+
const d = box.clock.now();
|
|
223
|
+
const p = (n) => String(n).padStart(2, "0");
|
|
224
|
+
return `${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`;
|
|
225
|
+
}
|
|
226
|
+
async function verify(args, box, deps, ask) {
|
|
227
|
+
let plan = false;
|
|
228
|
+
let cleanup = false;
|
|
229
|
+
let noMetasync = false;
|
|
230
|
+
let components = false;
|
|
231
|
+
let validateOnly = false;
|
|
232
|
+
let withObjects = false;
|
|
233
|
+
for (const a of args) {
|
|
234
|
+
if (a === "--plan")
|
|
235
|
+
plan = true;
|
|
236
|
+
else if (a === "--cleanup")
|
|
237
|
+
cleanup = true;
|
|
238
|
+
else if (a === "--no-metasync")
|
|
239
|
+
noMetasync = true;
|
|
240
|
+
else if (a === "--components")
|
|
241
|
+
components = true;
|
|
242
|
+
else if (a === "--validate-only")
|
|
243
|
+
validateOnly = true;
|
|
244
|
+
else if (a === "--with-objects")
|
|
245
|
+
withObjects = true;
|
|
246
|
+
else
|
|
247
|
+
throw new Stop(1, `不明なオプションです: ${a}`);
|
|
248
|
+
}
|
|
249
|
+
if (validateOnly && !components)
|
|
250
|
+
throw new Stop(1, "--validate-only は、--components と一緒に指定してください。");
|
|
251
|
+
if (validateOnly && cleanup)
|
|
252
|
+
throw new Stop(1, "--validate-only と --cleanup は、一緒に指定できません(検証だけのときは、組織に、何も残りません)。");
|
|
253
|
+
if (withObjects && !components)
|
|
254
|
+
throw new Stop(1, "--with-objects は、--components と一緒に指定してください。");
|
|
255
|
+
// オブジェクト系: 検証のみは常に含める(何も作らない)。通しは --with-objects のときだけ(削除した名前が 15 日間予約されるため)
|
|
256
|
+
const objects = components && (validateOnly || withObjects);
|
|
257
|
+
// Flow: API で削除できない場合があるため、通しには含めない。検証のみと --cleanup(リポジトリのファイルの削除)では含める
|
|
258
|
+
const flow = components && (validateOnly || cleanup);
|
|
259
|
+
const delPrs = objects ? 2 : 1;
|
|
260
|
+
const what = components ? "サンプル(パターン別のコンポーネント)" : "Hello World";
|
|
261
|
+
const cleanupCmd = components
|
|
262
|
+
? `sft project verify --components${objects ? " --with-objects" : ""} --cleanup`
|
|
263
|
+
: "sft project verify --cleanup";
|
|
264
|
+
if (box.env("GITHUB_ACTIONS") === "true")
|
|
265
|
+
throw new Stop(1, "GitHub Actions 上では、実行できません。");
|
|
266
|
+
if (!deps.folderName.startsWith("force-"))
|
|
267
|
+
throw new Stop(1, "force-* フォルダで実行してください。");
|
|
268
|
+
const origin = await originRepo(box);
|
|
269
|
+
if (origin.kind !== "ok")
|
|
270
|
+
throw new Stop(1, "origin が GitHub のリポジトリではありません(origin を確認してください)。");
|
|
271
|
+
const repo = `${origin.owner}/${origin.repo}`;
|
|
272
|
+
const out = (l) => box.output.err(l);
|
|
273
|
+
out(`=== リポジトリの検証(${repo}) ===`);
|
|
274
|
+
const owner = await ghOwnerProblem(box, origin.owner);
|
|
275
|
+
if (owner !== null)
|
|
276
|
+
throw new Stop(1, owner);
|
|
277
|
+
const g = new VerifyGh(box, repo);
|
|
278
|
+
const list = await g.branches();
|
|
279
|
+
if (list === null)
|
|
280
|
+
throw new Stop(1, "ブランチの一覧を取得できません。");
|
|
281
|
+
let tiers = verifyTiers(list);
|
|
282
|
+
if (tiers === null)
|
|
283
|
+
throw new Stop(1, "ブランチ main が見つかりません。");
|
|
284
|
+
// --components: サンプルは develop の組織だけに入れる(本番・staging には入れない)
|
|
285
|
+
let labels = true;
|
|
286
|
+
if (components) {
|
|
287
|
+
if (!tiers.includes("develop"))
|
|
288
|
+
throw new Stop(1, "--components は、develop の組織がある構成(develop・staging・main の 3 層)だけで、実行できます(サンプルを、staging・本番の組織には、入れません)。");
|
|
289
|
+
tiers = ["develop"];
|
|
290
|
+
// 既存の labels のファイルを上書きして消さない。サンプルのラベルだけのファイル(前回の検証の残り)は、サンプルとして扱う
|
|
291
|
+
if ((await g.fileSha("develop", SAMPLE_LABELS_PATH)) !== null) {
|
|
292
|
+
if (labelsFileIsOurs((await g.fileText("develop", SAMPLE_LABELS_PATH)) ?? "")) {
|
|
293
|
+
out("[INFO] develop の labels のファイルは、サンプルのラベル(前回の検証の残り)だけです。サンプルの一部として扱います。");
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
labels = false;
|
|
297
|
+
out(`[WARNING] develop に、すでに labels のファイル(${SAMPLE_LABELS_PATH})があるため、CustomLabels は、サンプルに含めません(上書きを避けるため)。`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const set = components ? sampleSet({ objects, flow, labels }) : HELLO_SET;
|
|
302
|
+
const r = { box, g, set, what, cleanup, cleanupCmd, ok: 0, ng: 0, flaky: 0, left: [], vars: new Map() };
|
|
303
|
+
// 1. 診断
|
|
304
|
+
if ((await (deps.diag ?? runDiag)(box, repo, tiers)) > 0)
|
|
305
|
+
throw new Stop(1, "セットアップに不足があるため、検証を始められません(上の「直し方」を実行してください)。");
|
|
306
|
+
if (!cleanup) {
|
|
307
|
+
for (const t of tiers) {
|
|
308
|
+
for (const p of set.paths("all")) {
|
|
309
|
+
if ((await g.fileSha(t, p)) !== null) {
|
|
310
|
+
out(`[ERROR] ${t} ブランチに、検証用と同じ名前のファイルが、すでにあります: ${p}`);
|
|
311
|
+
out(`[WARNING] このまま実行すると、そのファイルを、上書きして、削除します。前回の検証の残りであれば、${cleanupCmd} を実行してください。`);
|
|
312
|
+
throw new Stop(1, `検証用と同名のファイルが、すでにあります(${t}: ${p})。`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// 2. 実行内容の表示
|
|
318
|
+
let needProd = false;
|
|
319
|
+
out("");
|
|
320
|
+
out(" 【これから行うこと】");
|
|
321
|
+
out(` リポジトリ : ${repo}`);
|
|
322
|
+
out(" 段階(リリースの順):");
|
|
323
|
+
for (const t of tiers) {
|
|
324
|
+
const sfx = tierSuffix(t);
|
|
325
|
+
for (const n of ["SF_ORG_KIND", "SF_ORG_NAME", "SF_USERNAME"])
|
|
326
|
+
r.vars.set(`${n}_${sfx}`, await g.variable(`${n}_${sfx}`));
|
|
327
|
+
const kind = r.vars.get(`SF_ORG_KIND_${sfx}`) ?? "";
|
|
328
|
+
const prod = !["developer", "sandbox", "trial"].includes(kind);
|
|
329
|
+
if (prod)
|
|
330
|
+
needProd = true;
|
|
331
|
+
out(` ${t} → ${r.vars.get(`SF_ORG_NAME_${sfx}`) || "(名前なし)"} / ${orgKindLabel(kind || "unknown")} / ${r.vars.get(`SF_USERNAME_${sfx}`) || "(ユーザー未設定)"}${prod ? " ← 本番(または、種類を判定できない)組織" : ""}`);
|
|
332
|
+
}
|
|
333
|
+
const n = tiers.length;
|
|
334
|
+
const files = set.paths("all").length;
|
|
335
|
+
const lbl = labels ? "・表示ラベル" : "";
|
|
336
|
+
if (components && validateOnly) {
|
|
337
|
+
out(` 内容 : サンプル(${files} ファイル)の検証のみ(wf-validate = dry-run)。PR は、マージせずに閉じる`);
|
|
338
|
+
out(" 組織には、何も反映しません(develop のみ)");
|
|
339
|
+
}
|
|
340
|
+
else if (components && cleanup) {
|
|
341
|
+
out(` 内容 : 削除のみ(サンプルを、develop の組織から消す。${delPrs} 本の PR)`);
|
|
342
|
+
}
|
|
343
|
+
else if (components && objects) {
|
|
344
|
+
out(` 内容 : サンプル(${files} ファイル。Apex・トリガー・LWC・Aura・権限セット・Layout・メール テンプレート${lbl}・`);
|
|
345
|
+
out(" オブジェクト・項目)を、develop の組織にリリースして、削除する(develop のみ。Flow は、含めません: 検証のみ(--validate-only)で検証します)");
|
|
346
|
+
out(" PR を 3 本(リリース 1・削除 2: 段階 1 → 段階 2)作成してマージする。組織と、リポジトリのファイルは、最後に消える");
|
|
347
|
+
out(" ※ 削除したカスタムオブジェクトの名前は、15 日間、予約されます(再作成には、ごみ箱から消す必要があります)");
|
|
348
|
+
}
|
|
349
|
+
else if (components) {
|
|
350
|
+
out(` 内容 : サンプル(${files} ファイル。Apex・LWC・Aura・権限セット・メール テンプレート${lbl})を、`);
|
|
351
|
+
out(" develop の組織にリリースして、削除する(develop のみ。オブジェクト系・Flow は、含めません: 検証のみ(--validate-only)で検証します)");
|
|
352
|
+
out(" PR を 2 本(リリース 1・削除 1)作成してマージする。組織と、リポジトリのファイルは、最後に消える");
|
|
353
|
+
}
|
|
354
|
+
else if (cleanup) {
|
|
355
|
+
out(` 内容 : 削除のみ(Hello World のクラスを、各段階の組織から消す。${n} 本の PR)`);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
out(` 内容 : Hello World(${HELLO_SET.marker} / SfToolsE2eHelloTest)を、各段階にリリースして、削除する`);
|
|
359
|
+
out(` PR を ${n * 2} 本(リリース ${n}・削除 ${n})作成してマージする。組織のクラスと、リポジトリのファイルは、最後に消える`);
|
|
360
|
+
}
|
|
361
|
+
if (!cleanup) {
|
|
362
|
+
out(` 最初の確認 : 環境全体(SF_TOOLS_BRANCH・ログに Token が残っていないこと${noMetasync ? "" : "・wf-metasync の実行"})。NG があれば、リリースへ進みません`);
|
|
363
|
+
if (!noMetasync)
|
|
364
|
+
out(" ※ wf-metasync は、Salesforce(main の組織)の変更を、main に同期します。変更があれば、main にコミットされます");
|
|
365
|
+
}
|
|
366
|
+
// 目安: PR 1 本(検証 → マージ → リリース)が約 3 分。wf-metasync が約 3 分
|
|
367
|
+
let est = n * (cleanup ? 1 : 2) * 3;
|
|
368
|
+
if (components)
|
|
369
|
+
est = validateOnly ? 4 : cleanup ? delPrs * 3 : (1 + delPrs) * 3 + 1;
|
|
370
|
+
if (!cleanup && !noMetasync)
|
|
371
|
+
est += 3;
|
|
372
|
+
out(` 目安の時間 : 約 ${est} 分(Actions の混み具合で、前後します)`);
|
|
373
|
+
out(" 残るもの : リポジトリに、PR・コミットの履歴(作業用ブランチは、最後に削除します)。Slack に、通知(段階ごとに数通)");
|
|
374
|
+
if (plan) {
|
|
375
|
+
out("[INFO] --plan のため、ここで終了します(何も変更していません)。");
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
378
|
+
// 3. 確認(本番を含むときは、文面で明示する。sf-project から呼ばれたとき(SF_VERIFY_CONFIRMED=1)は、二重に聞かない)
|
|
379
|
+
if (box.env("SF_VERIFY_CONFIRMED") !== "1") {
|
|
380
|
+
const doing = validateOnly
|
|
381
|
+
? "サンプルを、検証します(反映はしません)"
|
|
382
|
+
: components
|
|
383
|
+
? "サンプルを、リリースして、削除します"
|
|
384
|
+
: "Hello World を、リリースして、削除します";
|
|
385
|
+
out("");
|
|
386
|
+
for (const l of ["!! 実際のリポジトリと組織に、リリースします", ` ${doing}`, " 管理者以外は、実行しないでください"])
|
|
387
|
+
out(l);
|
|
388
|
+
out("");
|
|
389
|
+
if (needProd)
|
|
390
|
+
out(` 本番(または、種類を判定できない)組織に、${what} を、リリースして、削除します。`);
|
|
391
|
+
const a = await ask("", `${needProd ? "本番の組織を含みます。" : ""}${repo} の検証を始めますか?`);
|
|
392
|
+
if (a === "need")
|
|
393
|
+
throw new Stop(20, "");
|
|
394
|
+
if (a !== "yes")
|
|
395
|
+
throw new Stop(1, "中断しました。");
|
|
396
|
+
}
|
|
397
|
+
const st = stamp(box);
|
|
398
|
+
const kindName = components ? "comp" : "hello";
|
|
399
|
+
const jobRelease = `verify-${kindName}-${st}`;
|
|
400
|
+
const jobDelete = `verify-${kindName}-delete-${st}`;
|
|
401
|
+
const jobDelete2 = `verify-comp-delete2-${st}`;
|
|
402
|
+
let madeDelete2 = false;
|
|
403
|
+
// 3b・4. 環境の確認とリリース(検証のみは、PR をマージせずに閉じる)
|
|
404
|
+
if (!cleanup) {
|
|
405
|
+
out("=== 環境の確認 ===");
|
|
406
|
+
const stopIfNg = () => {
|
|
407
|
+
if (r.ng === 0)
|
|
408
|
+
return;
|
|
409
|
+
out("");
|
|
410
|
+
out("[ERROR] 環境の確認で、NG があります。これ以上は、進みません(リリースも、wf-metasync も、行っていません)。");
|
|
411
|
+
out("[WARNING] 上の [NG] を直してから、もう一度、実行してください。");
|
|
412
|
+
throw new Stop(1, "");
|
|
413
|
+
};
|
|
414
|
+
const tb = await g.variable("SF_TOOLS_BRANCH");
|
|
415
|
+
out(`[INFO] SF_TOOLS_BRANCH = ${tb || "(未設定)"}`);
|
|
416
|
+
check(r, "環境: SF_TOOLS_BRANCH が、main または development である", tb === "main" || tb === "development");
|
|
417
|
+
check(r, "環境: ローカルのログに、Token・認証 URL が残っていない", logsClean(r));
|
|
418
|
+
stopIfNg();
|
|
419
|
+
if (!noMetasync)
|
|
420
|
+
await metasyncCheck(r);
|
|
421
|
+
else
|
|
422
|
+
out("[INFO] wf-metasync の実行は、省略しました(--no-metasync)。");
|
|
423
|
+
stopIfNg();
|
|
424
|
+
out(validateOnly ? `=== 検証のみ(${tiers.join(" ")}。マージしない) ===` : `=== リリース(${tiers.join(" ")}) ===`);
|
|
425
|
+
let stopped = !check(r, `リリース用のブランチ ${jobRelease} を作成した(${what}のファイルとリリース対象)`, await makeReleaseBranch(r, jobRelease));
|
|
426
|
+
for (const t of stopped ? [] : tiers) {
|
|
427
|
+
if (validateOnly) {
|
|
428
|
+
if ((await prFlow(r, `検証(${t})`, jobRelease, `verify: ${what} を検証(マージしない)`, t, "validate")) === null)
|
|
429
|
+
stopped = true;
|
|
430
|
+
if (stopped)
|
|
431
|
+
break;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
const id = await prFlow(r, `リリース(${t})`, jobRelease, `verify: ${what} をリリース`, t, "release");
|
|
435
|
+
if (id === null) {
|
|
436
|
+
stopped = true;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
await evidence(r, t, id, "リリース"); // 確認の失敗は記録して続ける(削除まで行って、組織を元に戻すため)
|
|
440
|
+
}
|
|
441
|
+
if (stopped) {
|
|
442
|
+
guidance(r, repo);
|
|
443
|
+
return 1;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (!validateOnly) {
|
|
447
|
+
// 5. 削除(--cleanup は、どの段階に残っているか分からないため、すべての段階を対象にする)。--components は develop の先頭から作る
|
|
448
|
+
out(`=== 削除(${tiers.join(" ")}) ===`);
|
|
449
|
+
if (cleanup)
|
|
450
|
+
r.left.push(...tiers);
|
|
451
|
+
const delBase = components ? tiers[0] : "main";
|
|
452
|
+
let stopped = !check(r, `削除用のブランチ ${jobDelete} を作成した(${what}のファイルの削除と削除対象)`, await makeDeleteBranch(r, jobDelete, "stage1", delBase));
|
|
453
|
+
for (const t of stopped ? [] : tiers) {
|
|
454
|
+
const id = await prFlow(r, `削除(${t})`, jobDelete, `verify: ${what} を削除`, t, "delete");
|
|
455
|
+
if (id === null) {
|
|
456
|
+
stopped = true;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
await evidence(r, t, id, "削除");
|
|
460
|
+
if (!objects)
|
|
461
|
+
r.left = r.left.filter((x) => x !== t); // オブジェクト系を含めるときは、段階 2 のあとで消えたとみなす
|
|
462
|
+
}
|
|
463
|
+
// --with-objects: 段階 2(項目・オブジェクト)。段階 1 で、参照するもの(トリガー・テストクラスなど)を消したあとに消す
|
|
464
|
+
if (!stopped && objects) {
|
|
465
|
+
out(`=== 削除(項目・オブジェクト。${tiers.join(" ")}) ===`);
|
|
466
|
+
madeDelete2 = true;
|
|
467
|
+
stopped = !check(r, `削除用のブランチ ${jobDelete2} を作成した(項目・オブジェクトの削除と削除対象)`, await makeDeleteBranch(r, jobDelete2, "stage2", delBase));
|
|
468
|
+
for (const t of stopped ? [] : tiers) {
|
|
469
|
+
const id = await prFlow(r, `削除・項目とオブジェクト(${t})`, jobDelete2, `verify: ${what}(項目・オブジェクト)を削除`, t, "delete");
|
|
470
|
+
if (id === null) {
|
|
471
|
+
stopped = true;
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
check(r, `削除・項目とオブジェクト(${t}): ログに、${SAMPLE_OBJ} が出ている`, await g.logHas(id, SAMPLE_OBJ));
|
|
475
|
+
r.left = r.left.filter((x) => x !== t);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (stopped) {
|
|
479
|
+
guidance(r, repo);
|
|
480
|
+
return 1;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
// 5b・6. 後始末と結果(--cleanup はリリース用、--validate-only は削除用のブランチを作っていない)
|
|
484
|
+
const jobs = validateOnly ? [jobRelease] : [...(cleanup ? [] : [jobRelease]), jobDelete, ...(madeDelete2 ? [jobDelete2] : [])];
|
|
485
|
+
await deleteJobBranches(r, jobs, repo);
|
|
486
|
+
out("");
|
|
487
|
+
out("=== 結果 ===");
|
|
488
|
+
out(`[INFO] 確認: ${r.ok} 件成功 / ${r.ng} 件失敗`);
|
|
489
|
+
if (r.flaky > 0)
|
|
490
|
+
out(`[WARNING] 再実行で成功したワークフローが ${r.flaky} 件あります(一時的な失敗の可能性)。`);
|
|
491
|
+
if (r.ng === 0) {
|
|
492
|
+
if (validateOnly)
|
|
493
|
+
out("[SUCCESS] 検証: すべて成功しました。サンプル(パターン別のコンポーネント)の検証(dry-run)が、develop の組織に対して通りました(反映はしていません)。");
|
|
494
|
+
else if (components) {
|
|
495
|
+
out("[SUCCESS] 検証: すべて成功しました。サンプル(パターン別のコンポーネント)の、リリースと削除が、develop の組織に対して動いています。");
|
|
496
|
+
if (!objects)
|
|
497
|
+
out("[INFO] オブジェクト系(トリガー・Layout・オブジェクト・項目)と Flow は、通しには含めていません(--validate-only で検証できます)。");
|
|
498
|
+
}
|
|
499
|
+
else
|
|
500
|
+
out(`[SUCCESS] 検証: すべて成功しました。${repo} は、段階ごとの組織に対して、リリースと削除が動いています。`);
|
|
501
|
+
return 0;
|
|
502
|
+
}
|
|
503
|
+
out("[ERROR] 検証: 失敗した確認があります(上の [NG] を確認してください)。");
|
|
504
|
+
return 1;
|
|
505
|
+
}
|
|
506
|
+
export async function runProjectVerify(args, box, deps, ask) {
|
|
507
|
+
try {
|
|
508
|
+
return await verify(args, box, deps, ask);
|
|
509
|
+
}
|
|
510
|
+
catch (e) {
|
|
511
|
+
if (!(e instanceof Stop))
|
|
512
|
+
throw e;
|
|
513
|
+
if (e.message !== "")
|
|
514
|
+
box.output.err(`[ERROR] ${e.message}`);
|
|
515
|
+
return e.code;
|
|
516
|
+
}
|
|
517
|
+
}
|