@tama-create/sf-tools 0.0.0-stage → 1.4.0-dev.10
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/config/changeset-types.txt +350 -0
- package/config/install/gitmessage +6 -0
- package/config/install/release/README.md +26 -0
- package/config/install/release/deploy-target.txt +368 -0
- package/config/install/release/remove-target.txt +279 -0
- package/config/metadata-capability.txt +118 -0
- package/config/metadata-dirs.txt +79 -0
- package/config/metasync-detect.txt +52 -0
- package/config/metasync-extra.txt +30 -0
- package/config/metasync-fingerprint.txt +90 -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 +37 -0
- package/dist/commands/job.js +31 -0
- package/dist/commands/launcher.js +57 -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 +102 -0
- package/dist/commands/push.js +16 -0
- package/dist/commands/release.js +19 -0
- package/dist/commands/start.js +67 -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/cli-update-notice.js +47 -0
- package/dist/core/command.js +25 -0
- package/dist/core/create-connect.js +519 -0
- package/dist/core/create-setup.js +358 -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 +215 -0
- package/dist/core/lines.js +25 -0
- package/dist/core/log-auto.js +56 -0
- package/dist/core/log-box.js +109 -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/new-version.js +93 -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 +217 -0
- package/dist/core/project-create.js +733 -0
- package/dist/core/project-reconnect.js +126 -0
- package/dist/core/project-status.js +246 -0
- package/dist/core/project-tier.js +374 -0
- package/dist/core/project-upgrade.js +138 -0
- package/dist/core/project-verify.js +517 -0
- package/dist/core/promote-check.js +401 -0
- package/dist/core/promote.js +141 -0
- package/dist/core/push.js +163 -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 +69 -0
- package/dist/io/doctor-deps.js +32 -0
- package/dist/io/hook-install-deps.js +11 -0
- package/dist/io/job-deps.js +39 -0
- package/dist/io/key-file.js +17 -0
- package/dist/io/keys.js +172 -0
- package/dist/io/log-deps.js +107 -0
- package/dist/io/metasync-deps.js +22 -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 +28 -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 +24 -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 +163 -0
- package/dist/ui/prompt.js +66 -0
- package/lib/apexlog.js +819 -0
- package/lib/metasync.js +1364 -0
- package/lib/package.json +4 -0
- package/lib/typecheck.js +547 -0
- package/package.json +44 -4
- package/templates/.forceignore +12 -0
- package/templates/.gitattributes +58 -0
- package/templates/.github/workflows/wf-metasync.yml +177 -0
- package/templates/.github/workflows/wf-release.yml +454 -0
- package/templates/.github/workflows/wf-sequence.yml +292 -0
- package/templates/.github/workflows/wf-validate.yml +389 -0
- package/templates/.prettierignore +11 -0
- package/templates/.prettierrc +17 -0
- package/templates/.vscode/extensions.json +9 -0
- package/templates/.vscode/launch.json +16 -0
- package/templates/.vscode/settings.json +39 -0
- package/templates/AGENTS.md +3 -0
- package/templates/CLAUDE.md +4 -0
- package/templates/README.md +11 -0
- package/templates/config/project-scratch-def.json +13 -0
- package/templates/eslint.config.js +55 -0
- package/templates/force-app/main/default/.gitkeep +0 -0
- package/templates/gitignore.template +62 -0
- package/templates/jest.config.js +6 -0
- package/templates/package.json +29 -0
- package/templates/scripts/apex/hello.apex +10 -0
- package/templates/scripts/soql/account.soql +6 -0
- package/templates/sf-tools/config/branches.txt +24 -0
- package/templates/sf-tools/config/metadata.txt +576 -0
- package/templates/sfdx-project.json +12 -0
- package/templates-ts/.github/workflows/wf-metasync.yml +109 -0
- package/templates-ts/.github/workflows/wf-release.yml +263 -0
- package/templates-ts/.github/workflows/wf-sequence.yml +153 -0
- package/templates-ts/.github/workflows/wf-validate.yml +185 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 管理者用のクローンの照合と、セットアップ完了の印。シェル版の lib/admin-clone.sh のうち、判定の部分
|
|
2
|
+
// (clone_matches_repo・state_matches_repo・mark_setup_complete・clear_setup_mark・clone_setup_completed)の移し先
|
|
3
|
+
// (doc/rebuild-design.md 11.2 の段階 1)。git は、渡された道具の箱だけで呼ぶ(7.2)。
|
|
4
|
+
// 目的: 別のリポジトリのクローンに、書き込み・push しないための番人(XXXX だけのフォルダ名で扱うため)
|
|
5
|
+
import { originRepo } from "./origin.js";
|
|
6
|
+
/** DIR が Git のクローンで、origin が GitHub の owner/repo か。大文字と小文字は区別しない(GitHub は区別しない) */
|
|
7
|
+
export async function cloneMatchesRepo(box, dir, owner, repo) {
|
|
8
|
+
if (dir === "" || owner === "" || repo === "" || !box.files.exists(dir))
|
|
9
|
+
return false;
|
|
10
|
+
const r = await originRepo(box, dir);
|
|
11
|
+
if (r.kind !== "ok")
|
|
12
|
+
return false;
|
|
13
|
+
return `${r.owner}/${r.repo}`.toLowerCase() === `${owner}/${repo}`.toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
/** 状態ファイル(.sf-init-XXXX.env)の最後の REPO_FULL_NAME が、owner/repo か(大文字と小文字は区別しない)。ファイルがない・読めないときは false */
|
|
16
|
+
export function stateMatchesRepo(box, file, owner, repo) {
|
|
17
|
+
if (file === "" || owner === "" || repo === "" || !box.files.exists(file))
|
|
18
|
+
return false;
|
|
19
|
+
let text;
|
|
20
|
+
try {
|
|
21
|
+
text = box.files.readText(file);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const values = text.split("\n").filter((l) => l.startsWith("REPO_FULL_NAME="));
|
|
27
|
+
const last = values[values.length - 1];
|
|
28
|
+
if (last === undefined)
|
|
29
|
+
return false;
|
|
30
|
+
const value = last
|
|
31
|
+
.slice(last.indexOf("=") + 1)
|
|
32
|
+
.replace(/\r$/, "")
|
|
33
|
+
.replace(/^"/, "")
|
|
34
|
+
.replace(/"$/, "")
|
|
35
|
+
.toLowerCase();
|
|
36
|
+
return value !== "" && value === `${owner}/${repo}`.toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
// セットアップ完了の印: クローンの git config(sf-tools.setup-complete。.git/config にあり、GitHub には送られない)。
|
|
39
|
+
// 1 = 完了した / 0 = やり直し中 / 未設定 = 印を導入する前の版で完了したプロジェクト、または、一度も完了していないクローン。
|
|
40
|
+
// やり直し中は、印を消さず 0 にして、未設定と区別する(印を導入する前に完了した運用中のリポジトリを、未完了と誤判定して、
|
|
41
|
+
// 新規セットアップとして上書きしないため)
|
|
42
|
+
const MARK_KEY = "sf-tools.setup-complete";
|
|
43
|
+
/** 印を 1(完了)にする。DIR がない・git config の失敗は false */
|
|
44
|
+
export async function markSetupComplete(box, dir) {
|
|
45
|
+
if (dir === "" || !box.files.exists(dir))
|
|
46
|
+
return false;
|
|
47
|
+
return (await box.run("git", ["-C", dir, "config", MARK_KEY, "1"])).code === 0;
|
|
48
|
+
}
|
|
49
|
+
/** やり直しの開始時に、印を 0(やり直し中)にする。失敗しても、やり直しは進める(意図的に無視)。クローンがなければ何もしない */
|
|
50
|
+
export async function clearSetupMark(box, dir) {
|
|
51
|
+
if (dir === "" || !box.files.exists(dir))
|
|
52
|
+
return;
|
|
53
|
+
try {
|
|
54
|
+
await box.run("git", ["-C", dir, "config", MARK_KEY, "0"]);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// 失敗しても、やり直しは進める
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* DIR が、owner/repo の、セットアップ済みのクローンか。origin が owner/repo(大文字と小文字は区別しない)で、かつ:
|
|
62
|
+
* 印が 1 → 完了済み / 0 → やり直し中(未完了) / 未設定 → ローカルに admin ブランチがあれば、印を導入する前の版で完了したものと
|
|
63
|
+
* みなして、印を 1 にする(その版は、完了時に admin ブランチを作り、状態ファイルを消すだけだった)。admin ブランチがなければ未完了
|
|
64
|
+
*/
|
|
65
|
+
export async function cloneSetupCompleted(box, dir, owner, repo) {
|
|
66
|
+
if (!(await cloneMatchesRepo(box, dir, owner, repo)))
|
|
67
|
+
return false;
|
|
68
|
+
const got = await box.run("git", ["-C", dir, "config", "--get", MARK_KEY]);
|
|
69
|
+
const value = got.stdout.trim();
|
|
70
|
+
if (value === "1")
|
|
71
|
+
return true;
|
|
72
|
+
if (value === "0")
|
|
73
|
+
return false;
|
|
74
|
+
const admin = await box.run("git", ["-C", dir, "rev-parse", "--verify", "--quiet", "refs/heads/admin"]);
|
|
75
|
+
if (admin.code !== 0)
|
|
76
|
+
return false;
|
|
77
|
+
await markSetupComplete(box, dir); // 印を付けられなくても、完了済みとして扱う(次回も、同じ判定になる)
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const ITEM = /^([a-z][a-z0-9-]*(?:\.[a-z0-9-]+)+)=([yn])$/;
|
|
2
|
+
/** SF_TOOLS_ANSWERS を読む。形が違う・同じ名前が 2 つあれば、失敗 */
|
|
3
|
+
export function parseAnswers(text) {
|
|
4
|
+
const items = new Map();
|
|
5
|
+
for (const item of text.split(/\s+/).filter((s) => s !== "")) {
|
|
6
|
+
const m = ITEM.exec(item);
|
|
7
|
+
if (m === null)
|
|
8
|
+
return { ok: false, error: `SF_TOOLS_ANSWERS の形が正しくありません: ${item}(名前=y または 名前=n。名前は <コマンド>.<質問>)` };
|
|
9
|
+
const name = m[1];
|
|
10
|
+
if (items.has(name))
|
|
11
|
+
return { ok: false, error: `SF_TOOLS_ANSWERS に、同じ名前が 2 つあります: ${name}` };
|
|
12
|
+
items.set(name, m[2]);
|
|
13
|
+
}
|
|
14
|
+
return { ok: true, items };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* command は、自分のコマンドの短い名前(deploy など)。human は、人に聞く部品(画面)。
|
|
18
|
+
* AI 操作で、SF_TOOLS_ANSWERS の形が誤っていれば、問い合わせのたびに失敗を返さず、ここで例外にする(中断)
|
|
19
|
+
*/
|
|
20
|
+
export function createAsk(box, command, human) {
|
|
21
|
+
if (box.env("SF_TOOLS_AI") !== "1")
|
|
22
|
+
return (_name, question) => human(question);
|
|
23
|
+
const table = parseAnswers(box.env("SF_TOOLS_ANSWERS") ?? "");
|
|
24
|
+
if (!table.ok)
|
|
25
|
+
throw new Error(table.error);
|
|
26
|
+
const mine = new Map([...table.items].filter(([name]) => name.split(".")[0] === command || name.split(".")[0] === "update"));
|
|
27
|
+
if (mine.size > 0)
|
|
28
|
+
box.output.err(` (AI 経由の答えを受け取りました: ${[...mine].map(([k, v]) => `${k}=${v}`).join(" ")})`);
|
|
29
|
+
const used = new Set();
|
|
30
|
+
return async (name, question) => {
|
|
31
|
+
const answer = name === "" || used.has(name) ? undefined : mine.get(name);
|
|
32
|
+
if (answer === undefined) {
|
|
33
|
+
box.output.err(`[確認待ち] ${name === "" ? "(名前なし)" : name}: ${question.trim()}`);
|
|
34
|
+
return "need";
|
|
35
|
+
}
|
|
36
|
+
used.add(name);
|
|
37
|
+
box.output.err(` (AI 経由の回答: ${name}=${answer})`);
|
|
38
|
+
return answer === "y" ? "yes" : "no";
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// ブランチと段階(branches.txt)の判定。シェル版の lib/branches.sh の移し先(doc/rebuild-design.md 11.2 の段階 1)。
|
|
2
|
+
// core は Node 専用の機能を使わない(3.4)ので、ファイルは読まず、中身の文字列を受け取る。
|
|
3
|
+
// 画面に出す警告は、戻り値の warnings に入れて返す(出すかどうかは、呼ぶ側が決める)
|
|
4
|
+
/** 共有環境の組織エイリアス(予約名)。ローカルからのリリースを禁止する(lib/common.sh の SF_RESERVED_ORG_ALIASES と同じ) */
|
|
5
|
+
export const RESERVED_ORG_ALIASES = ["prod", "staging", "develop", "main"];
|
|
6
|
+
/** 行末の CR を除き、空の行と # で始まる行(前に空白があってもよい)を除いた行(行の中身は、トリムしない) */
|
|
7
|
+
export function contentLines(text) {
|
|
8
|
+
return text
|
|
9
|
+
.split("\n")
|
|
10
|
+
.map((line) => line.replace(/\r$/, ""))
|
|
11
|
+
.filter((line) => !/^\s*#/.test(line) && line.trim() !== "");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* branches.txt のブランチ一覧(名前を問わない全行)。保護するブランチの判定に使う。
|
|
15
|
+
* text が null(ファイルがない)・ブランチが 1 つもないときは、警告つきで main だけ
|
|
16
|
+
*/
|
|
17
|
+
export function branchList(text, fileName = "sf-tools/config/branches.txt") {
|
|
18
|
+
if (text === null) {
|
|
19
|
+
return { branches: ["main"], warnings: [`ブランチ構成ファイルが見つかりません: ${fileName}(デフォルト: main のみ)`] };
|
|
20
|
+
}
|
|
21
|
+
const branches = contentLines(text);
|
|
22
|
+
if (branches.length === 0) {
|
|
23
|
+
return { branches: ["main"], warnings: [`${fileName} にブランチが定義されていません。デフォルト: main のみ`] };
|
|
24
|
+
}
|
|
25
|
+
return { branches, warnings: [] };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 有効な段階(main / staging / develop)を、決まった順で返す。規則の正本は doc/tier-scaling-design.md の 3.1。
|
|
29
|
+
* - 前後の空白を除く。段階の名前でない行は無視(strict でない場合は警告)。同じ名前が 2 行あっても 1 つ。main の行がなくても main は有効
|
|
30
|
+
* - develop は、staging も有効なときだけ有効
|
|
31
|
+
* - strict(一方通行の確認): ファイルがない・main の行がない・develop があって staging がない、は失敗にする
|
|
32
|
+
*/
|
|
33
|
+
export function tierList(text, options = {}) {
|
|
34
|
+
const strict = options.strict ?? false;
|
|
35
|
+
const fileName = options.fileName ?? "sf-tools/config/branches.txt";
|
|
36
|
+
if (text === null) {
|
|
37
|
+
if (strict)
|
|
38
|
+
return { ok: false, error: `ブランチ構成ファイルが見つかりません(読めません): ${fileName}` };
|
|
39
|
+
return { ok: true, tiers: ["main"], warnings: [`ブランチ構成ファイルが見つかりません: ${fileName}(デフォルト: main のみ)`] };
|
|
40
|
+
}
|
|
41
|
+
const warnings = [];
|
|
42
|
+
let hasLine = false;
|
|
43
|
+
const has = { main: false, staging: false, develop: false };
|
|
44
|
+
for (const raw of text.split("\n")) {
|
|
45
|
+
const line = raw.replace(/\r$/, "").trim();
|
|
46
|
+
if (line === "" || line.startsWith("#"))
|
|
47
|
+
continue;
|
|
48
|
+
hasLine = true;
|
|
49
|
+
if (line === "main" || line === "staging" || line === "develop") {
|
|
50
|
+
has[line] = true;
|
|
51
|
+
}
|
|
52
|
+
else if (!strict) {
|
|
53
|
+
warnings.push(`${fileName} の「${line}」は、段階の名前(main / staging / develop)ではないため、段階としては無視します。`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (strict) {
|
|
57
|
+
if (!has.main)
|
|
58
|
+
return { ok: false, error: `${fileName} に main の行がありません(段階の構成を判断できません)。` };
|
|
59
|
+
if (has.develop && !has.staging) {
|
|
60
|
+
return { ok: false, error: `${fileName} に develop がありますが、staging がありません(段階の構成の誤り)。` };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (!hasLine) {
|
|
64
|
+
warnings.push(`${fileName} にブランチが定義されていません。デフォルト: main のみ`);
|
|
65
|
+
}
|
|
66
|
+
const tiers = ["main"];
|
|
67
|
+
if (has.staging)
|
|
68
|
+
tiers.push("staging");
|
|
69
|
+
if (has.develop) {
|
|
70
|
+
if (has.staging)
|
|
71
|
+
tiers.push("develop");
|
|
72
|
+
else
|
|
73
|
+
warnings.push(`${fileName} に develop がありますが、staging がないため、develop は段階として無効です。`);
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, tiers, warnings };
|
|
76
|
+
}
|
|
77
|
+
/** ブランチが保護対象か。branchList の一覧との完全一致(大文字と小文字は区別する。固定の文字列として比べる) */
|
|
78
|
+
export function isProtectedBranch(branch, list) {
|
|
79
|
+
return list.includes(branch);
|
|
80
|
+
}
|
|
81
|
+
/** 共有環境の組織エイリアス(予約名)か。完全一致(大文字と小文字は区別する) */
|
|
82
|
+
export function isReservedOrgAlias(alias) {
|
|
83
|
+
return RESERVED_ORG_ALIASES.includes(alias);
|
|
84
|
+
}
|
|
85
|
+
/** ブランチ保護(Ruleset)の必須ステータスチェックの名前。ワークフローのジョブ名(ワークフロー名は含めない) */
|
|
86
|
+
export function requiredStatusCheckNames() {
|
|
87
|
+
return ["対象ファイル確認", "デプロイ検証", "順序チェック"];
|
|
88
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// ターゲットファイル(deploy-target.txt / remove-target.txt)の構文チェック。シェル版の bin/sf-check.sh の移し先
|
|
2
|
+
// (doc/rebuild-design.md 11.2 の段階 2。仕様の正本は、移し元の冒頭コメント)。release・push・フック・ランチャーが呼ぶ。
|
|
3
|
+
// 外との出入りは、渡された道具の箱だけ(7.2)。作業ディレクトリは、プロジェクトのルート
|
|
4
|
+
//
|
|
5
|
+
// 【処理】
|
|
6
|
+
// 1. 各ターゲットファイルを 1 行ずつ検証する(CR と前後の空白を除き、空行と # の行は読み飛ばす。セクションは [files] / [members]。
|
|
7
|
+
// 最初のマーカーより前は [files])
|
|
8
|
+
// [files] : リポジトリの外を指すパス(絶対パス・.. を含むパス)・存在しないパス・認めないフォルダはエラー。
|
|
9
|
+
// フォルダは、lwc/<名前>・aura/<名前>・objects/<名前> だけ書ける(リリース・削除の対象が広がりすぎるため)
|
|
10
|
+
// [members]: 「種別名:メンバー名」の形でない(: がない・先頭か末尾が :)ときはエラー
|
|
11
|
+
// 2. エラーでない行について、種類の可否を確認する(metadata-capability.txt。deploy は release 列・remove は delete 列。
|
|
12
|
+
// ng はエラー・limited は警告)。SF_CHECK_IGNORE_CAPABILITY=1 で省略できる
|
|
13
|
+
// 3. テストクラス不足を確認する(警告のみ)
|
|
14
|
+
// 【シェル版との違い】@isTest を含む .cls の探索(Step B)は、.git と node_modules の中を見ない(速さのため。リリースの対象になる場所ではない)
|
|
15
|
+
import { checkCapability, typeOfPath } from "./metadata-types.js";
|
|
16
|
+
const stripDot = (p) => (p.startsWith("./") ? p.slice(2) : p);
|
|
17
|
+
function isOutsideRepo(p) {
|
|
18
|
+
return /^\//.test(p) || /^[A-Za-z]:[\\/]/.test(p) || p === ".." || p.startsWith("../") || p.includes("/../") || p.endsWith("/..");
|
|
19
|
+
}
|
|
20
|
+
/** 1 行の指摘を、画面の 2 行にする */
|
|
21
|
+
function report(box, level, file, line, content, message) {
|
|
22
|
+
box.output.out(` ${file}:${line === null ? "" : `${line}:`} ${level}: ${message}`);
|
|
23
|
+
box.output.out(` → ${content}`);
|
|
24
|
+
}
|
|
25
|
+
function capabilityCheck(c, label, lineno, content, type) {
|
|
26
|
+
if (c.capability === null)
|
|
27
|
+
return;
|
|
28
|
+
const r = checkCapability(c.capability, label, type, c.ignoreCapability);
|
|
29
|
+
if (r.level === "ok")
|
|
30
|
+
return;
|
|
31
|
+
const note = r.note === "" ? "" : `(${r.note})`;
|
|
32
|
+
if (r.level === "error") {
|
|
33
|
+
report(c.box, "error", label, lineno, content, `「${r.type}」は、API で${r.what}できないことを確認済みです${note}。組織の権限で、できる場合は、SF_CHECK_IGNORE_CAPABILITY=1 で、この確認を省略できます`);
|
|
34
|
+
c.errors++;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
report(c.box, "warning", label, lineno, content, `「${r.type}」は、条件によって、${r.what}できないことがあります${note}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function checkTargetFile(c, file, label) {
|
|
41
|
+
const { box } = c;
|
|
42
|
+
if (!box.files.exists(file)) {
|
|
43
|
+
box.output.err(`[INFO] ${label}: ファイルが存在しません。スキップします。(${file})`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
box.output.err(`[INFO] ${label} を検証します: ${file}`);
|
|
47
|
+
const start = c.errors;
|
|
48
|
+
const fail = (lineno, content, message) => {
|
|
49
|
+
report(box, "error", label, lineno, content, message);
|
|
50
|
+
c.errors++;
|
|
51
|
+
};
|
|
52
|
+
let section = "files";
|
|
53
|
+
let entries = 0;
|
|
54
|
+
const lines = box.files.readText(file).split("\n");
|
|
55
|
+
for (let i = 0; i < lines.length; i++) {
|
|
56
|
+
const lineno = i + 1;
|
|
57
|
+
const clean = lines[i].replace(/\r/g, "").trim();
|
|
58
|
+
if (clean === "" || clean.startsWith("#"))
|
|
59
|
+
continue;
|
|
60
|
+
if (clean === "[files]") {
|
|
61
|
+
section = "files";
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (clean === "[members]") {
|
|
65
|
+
section = "members";
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
entries++;
|
|
69
|
+
if (section === "members") {
|
|
70
|
+
if (!clean.includes(":") || clean.startsWith(":") || clean.endsWith(":"))
|
|
71
|
+
fail(lineno, clean, "書式エラー(種別名:メンバー名)");
|
|
72
|
+
else
|
|
73
|
+
capabilityCheck(c, label, lineno, clean, clean.slice(0, clean.indexOf(":")));
|
|
74
|
+
}
|
|
75
|
+
else if (isOutsideRepo(clean)) {
|
|
76
|
+
fail(lineno, clean, "リポジトリの外を指すパスは使えません(絶対パス・.. を含むパス)");
|
|
77
|
+
}
|
|
78
|
+
else if (box.files.isDir(clean)) {
|
|
79
|
+
// フォルダは、1 つのコンポーネント・オブジェクトを丸ごと指すものだけ認める(広いフォルダは、対象が意図より広がるため)
|
|
80
|
+
if (/(^|\/)(lwc|aura|objects)\/[^/]+\/?$/.test(clean))
|
|
81
|
+
capabilityCheck(c, label, lineno, clean, typeOfPath(clean));
|
|
82
|
+
else
|
|
83
|
+
fail(lineno, clean, "フォルダは、LWC・Aura のコンポーネントとオブジェクト(lwc/<名前>・aura/<名前>・objects/<名前>)だけ書けます。ほかのフォルダは、リリース・削除の対象が広がりすぎます");
|
|
84
|
+
}
|
|
85
|
+
else if (!box.files.exists(clean)) {
|
|
86
|
+
fail(lineno, clean, "パスが存在しません");
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
capabilityCheck(c, label, lineno, clean, typeOfPath(clean));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (entries === 0)
|
|
93
|
+
box.output.err(`[WARNING] ${label}: 何も書かれていません。`);
|
|
94
|
+
else if (c.errors === start)
|
|
95
|
+
box.output.err(`[SUCCESS] ${label}: 問題なし。`);
|
|
96
|
+
}
|
|
97
|
+
/** テストクラス不足の確認(警告のみ)。deploy-target.txt の [files] の .cls のうち、@isTest のないものに、対応するテストクラスがあるか */
|
|
98
|
+
function checkMissingTests(box, deployList) {
|
|
99
|
+
if (!box.files.exists(deployList))
|
|
100
|
+
return;
|
|
101
|
+
const deployed = [];
|
|
102
|
+
let section = "files";
|
|
103
|
+
for (const raw of box.files.readText(deployList).split("\n")) {
|
|
104
|
+
const clean = raw.replace(/\r/g, "").trim();
|
|
105
|
+
if (clean === "" || clean.startsWith("#"))
|
|
106
|
+
continue;
|
|
107
|
+
if (clean === "[files]")
|
|
108
|
+
section = "files";
|
|
109
|
+
else if (clean === "[members]")
|
|
110
|
+
section = "members";
|
|
111
|
+
else if (section === "files" && clean.endsWith(".cls"))
|
|
112
|
+
deployed.push(clean);
|
|
113
|
+
}
|
|
114
|
+
if (deployed.length === 0)
|
|
115
|
+
return;
|
|
116
|
+
box.output.err("[INFO] テストクラス不足チェックを実行します...");
|
|
117
|
+
const deploySet = new Set(deployed.map(stripDot));
|
|
118
|
+
let tests = null; // @isTest を含む .cls(大文字・小文字を区別する)。最初に 1 回だけ読む
|
|
119
|
+
let warnings = 0;
|
|
120
|
+
for (const path of deployed) {
|
|
121
|
+
if (!box.files.exists(path))
|
|
122
|
+
continue;
|
|
123
|
+
if (box.files.readText(path).toLowerCase().includes("@istest"))
|
|
124
|
+
continue; // テストクラス自身
|
|
125
|
+
const name = path.split("/").pop().replace(/\.cls$/, "");
|
|
126
|
+
const dir = path.includes("/") ? path.slice(0, path.lastIndexOf("/")) || "/" : ".";
|
|
127
|
+
// Step A: 命名規則(同じフォルダの <名前>Test.cls / <名前>_Test.cls)
|
|
128
|
+
let found = [`${dir}/${name}Test.cls`, `${dir}/${name}_Test.cls`].find((p) => box.files.exists(p)) ?? "";
|
|
129
|
+
// Step B: 見つからなければ、@isTest を含む .cls のうち、クラス名を単語として含む最初のもの
|
|
130
|
+
if (found === "") {
|
|
131
|
+
tests ??= box.files
|
|
132
|
+
.walkFiles(".")
|
|
133
|
+
.filter((p) => p.endsWith(".cls"))
|
|
134
|
+
.map((p) => ({ path: p, text: box.files.readText(p) }))
|
|
135
|
+
.filter((t) => t.text.includes("@isTest"));
|
|
136
|
+
const word = new RegExp(`(^|[^A-Za-z0-9_])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^A-Za-z0-9_]|$)`);
|
|
137
|
+
found = tests.find((t) => word.test(t.text))?.path ?? "";
|
|
138
|
+
}
|
|
139
|
+
if (found === "")
|
|
140
|
+
continue;
|
|
141
|
+
found = stripDot(found);
|
|
142
|
+
if (!deploySet.has(found)) {
|
|
143
|
+
report(box, "warning", deployList, null, found, `${name} のテストクラスが deploy-target.txt に含まれていません(本番/Sandbox に存在する場合は無視可)`);
|
|
144
|
+
warnings++;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (warnings > 0)
|
|
148
|
+
box.output.err(`[WARNING] テストクラス不足の可能性: ${warnings}件`);
|
|
149
|
+
else
|
|
150
|
+
box.output.err("[SUCCESS] テストクラスチェック: 問題なし。");
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* ターゲットファイルを検証する。戻り値は、エラーの数(0 = エラーなし。警告のみ・検証を飛ばした場合を含む)。
|
|
154
|
+
* removeList が空文字なら、deploy-target.txt だけを検証する。
|
|
155
|
+
* capability は、可否の表(なければ null = 可否の確認をしない)。SF_CHECK_IGNORE_CAPABILITY=1 なら、可否の確認を省略する
|
|
156
|
+
*/
|
|
157
|
+
export function checkTargets(box, deployList, removeList, capability) {
|
|
158
|
+
box.output.err("[HEADER] デプロイターゲットファイルを検証します (sf-check)");
|
|
159
|
+
const c = { box, capability, ignoreCapability: box.env("SF_CHECK_IGNORE_CAPABILITY") === "1", errors: 0 };
|
|
160
|
+
checkTargetFile(c, deployList, "deploy-target.txt");
|
|
161
|
+
if (removeList !== "")
|
|
162
|
+
checkTargetFile(c, removeList, "remove-target.txt");
|
|
163
|
+
checkMissingTests(box, deployList);
|
|
164
|
+
if (c.errors > 0) {
|
|
165
|
+
box.output.out(`\nerror: ${c.errors} 件のエラーが検出されました。ターゲットファイルを修正してください。\n`);
|
|
166
|
+
return c.errors;
|
|
167
|
+
}
|
|
168
|
+
box.output.err("[SUCCESS] 構文チェック完了。問題はありませんでした。");
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// sft check の中身: 引数から、確かめるターゲットファイルを決めて、検証する(シェル版の sf-check.sh の入口。検証の本体は check-targets.ts)。
|
|
2
|
+
// sft push からも、同じ中身を呼ぶ
|
|
3
|
+
import { checkTargets } from "./check-targets.js";
|
|
4
|
+
import { EXIT } from "./exit-codes.js";
|
|
5
|
+
const BRANCH_NAME_FILE = "sf-tools/release/branch_name.txt";
|
|
6
|
+
/** 引数なし = branch_name.txt のブランチのファイル(なければ、警告して成功)。1 つ = deploy だけ。2 つ以上 = deploy と remove */
|
|
7
|
+
export function runCheck(args, box, capability) {
|
|
8
|
+
const paths = [];
|
|
9
|
+
for (const a of args) {
|
|
10
|
+
if (a === "-v" || a === "--verbose")
|
|
11
|
+
continue;
|
|
12
|
+
if (a.startsWith("-")) {
|
|
13
|
+
box.output.err(`[ERROR] 不明なオプションです: ${a}`);
|
|
14
|
+
return EXIT.failure;
|
|
15
|
+
}
|
|
16
|
+
paths.push(a);
|
|
17
|
+
}
|
|
18
|
+
let deploy;
|
|
19
|
+
let remove;
|
|
20
|
+
if (paths.length >= 1) {
|
|
21
|
+
deploy = paths[0];
|
|
22
|
+
remove = paths[1] ?? "";
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
if (!box.files.exists(BRANCH_NAME_FILE)) {
|
|
26
|
+
box.output.err(`[WARNING] ブランチ情報ファイル(${BRANCH_NAME_FILE})がありません。ターゲットファイルの構文チェックを、スキップしました。`);
|
|
27
|
+
return EXIT.ok;
|
|
28
|
+
}
|
|
29
|
+
const branch = box.files.readText(BRANCH_NAME_FILE).replace(/[\r\n]/g, "");
|
|
30
|
+
deploy = `sf-tools/release/${branch}/deploy-target.txt`;
|
|
31
|
+
remove = `sf-tools/release/${branch}/remove-target.txt`;
|
|
32
|
+
}
|
|
33
|
+
return checkTargets(box, deploy, remove, capability) > 0 ? EXIT.failure : EXIT.ok;
|
|
34
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// sft ci check-branch: wf-validate の「対象ファイル確認」ジョブの中身。templates/.github/workflows/wf-validate.yml の
|
|
2
|
+
// 該当ステップ(tier-switch v1 と、デプロイ対象ファイルの確認)の移し先(doc/rebuild-design.md 4.6・11.2 の段階 2)。
|
|
3
|
+
// 入力は環境変数 HEAD_REF(PR の元のブランチ)・BASE_REF(マージ先)。結果は GITHUB_OUTPUT に skip=true|false で書く。
|
|
4
|
+
// wf-release の「リリース対象確認」も、同じ手順を使う(BASE_REF = PR のマージ先。main・staging・develop のどれか)。REPOSITORY・PR_NUMBER
|
|
5
|
+
// (と GH_TOKEN)があれば、対象が空で skip=true のとき、PR が変えるファイルに版・ワークフロー(sf-tools/package.json・
|
|
6
|
+
// package-lock.json・.github/workflows/)があるかを調べ、あれば mark_only=true も書く(wf-release の「印だけ付ける」ジョブが使う。設計 4.3)。
|
|
7
|
+
// 終了コード: 0 = 判定できた(skip の値を見る)/ 1 = main を取得できない(段階が分からないまま進めない)
|
|
8
|
+
import { isToolingPath } from "./promote.js";
|
|
9
|
+
/** GitHub の「PR のファイルの一覧」の上限(これ以上の PR は、一覧が切れているかもしれない) */
|
|
10
|
+
const GITHUB_FILES_LIMIT = 3000;
|
|
11
|
+
/**
|
|
12
|
+
* PR が変えるファイルに、版・ワークフローのもの(isToolingPath。設計 4.3)があるか。入力は環境変数 REPOSITORY・PR_NUMBER
|
|
13
|
+
* (どちらかが空なら、判定せず "no" = これまでの動き)。gh が失敗したら "unknown"(呼ぶ側が、素通りも・印も出さない側に倒す)
|
|
14
|
+
*/
|
|
15
|
+
export async function toolingChange(box) {
|
|
16
|
+
const repo = box.env("REPOSITORY") ?? "";
|
|
17
|
+
const number = box.env("PR_NUMBER") ?? "";
|
|
18
|
+
if (repo === "" || number === "")
|
|
19
|
+
return { state: "no", path: "" };
|
|
20
|
+
const r = await box
|
|
21
|
+
// 移動(rename)の前のパスも見る。この API は、3000 ファイルまでしか返さない(それ以上は、確かめられないので unknown)
|
|
22
|
+
.run("gh", [
|
|
23
|
+
"api",
|
|
24
|
+
"--paginate",
|
|
25
|
+
`repos/${repo}/pulls/${number}/files?per_page=100`,
|
|
26
|
+
"--jq",
|
|
27
|
+
".[] | .filename, (.previous_filename // empty)",
|
|
28
|
+
])
|
|
29
|
+
.catch(() => null);
|
|
30
|
+
if (r === null || r.code !== 0)
|
|
31
|
+
return { state: "unknown", path: "" };
|
|
32
|
+
const paths = r.stdout
|
|
33
|
+
.split("\n")
|
|
34
|
+
.map((l) => l.trim())
|
|
35
|
+
.filter((l) => l !== "");
|
|
36
|
+
const path = paths.find((l) => isToolingPath(l));
|
|
37
|
+
if (path === undefined && paths.length >= GITHUB_FILES_LIMIT)
|
|
38
|
+
return { state: "unknown", path: "" };
|
|
39
|
+
return path === undefined ? { state: "no", path: "" } : { state: "yes", path };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* origin/main の branches.txt から、有効な段階を読む(tier-switch v1 の load_tiers)。
|
|
43
|
+
* 行の前後の空白と CR を除き、# の行・空行を除く。main を取得できなければ null(呼ぶ側が、ジョブを失敗にする)。
|
|
44
|
+
* branches.txt がなければ、known=false(tierEnabled は、今までの動きのため、常に有効を返す)
|
|
45
|
+
*/
|
|
46
|
+
export async function loadTiers(box) {
|
|
47
|
+
const shallow = await box.run("git", ["rev-parse", "--is-shallow-repository"]).catch(() => null);
|
|
48
|
+
// 浅いリポジトリなら --depth=1 で軽く、全履歴なら --depth を付けない(全履歴を浅くすると、あとのマージ・祖先の確認が失敗するため)
|
|
49
|
+
const depth = shallow?.stdout.trim() === "true" ? ["--depth=1"] : [];
|
|
50
|
+
const fetched = await box.run("git", ["fetch", "origin", "main", ...depth, "-q"]).catch(() => null);
|
|
51
|
+
if (fetched === null || fetched.code !== 0)
|
|
52
|
+
return null;
|
|
53
|
+
const shown = await box.run("git", ["show", "FETCH_HEAD:sf-tools/config/branches.txt"]).catch(() => null);
|
|
54
|
+
if (shown === null || shown.code !== 0) {
|
|
55
|
+
return {
|
|
56
|
+
known: false,
|
|
57
|
+
tiers: [],
|
|
58
|
+
warnings: [
|
|
59
|
+
"::warning title=段階の切り替え::main に sf-tools/config/branches.txt がありません。段階の切り替えを使わず、今までの動きにします。",
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const tiers = shown.stdout
|
|
64
|
+
.split("\n")
|
|
65
|
+
.map((l) => l.replace(/\r/g, "").trim())
|
|
66
|
+
.filter((l) => l !== "" && !l.startsWith("#"));
|
|
67
|
+
const warnings = tiers
|
|
68
|
+
.filter((t) => t !== "main" && t !== "staging" && t !== "develop")
|
|
69
|
+
.map((t) => `::warning title=段階の切り替え::branches.txt の「${t}」は、段階の名前ではないため、無視します。`);
|
|
70
|
+
return { known: true, tiers, warnings };
|
|
71
|
+
}
|
|
72
|
+
/** 段階が有効か。main は常に有効。develop は、staging も有効なときだけ有効。branches.txt がなければ、常に有効(今までの動き) */
|
|
73
|
+
export function tierEnabled(tier, sw) {
|
|
74
|
+
if (tier === "main")
|
|
75
|
+
return true;
|
|
76
|
+
if (!sw.known)
|
|
77
|
+
return true;
|
|
78
|
+
if (tier !== "staging" && tier !== "develop")
|
|
79
|
+
return false;
|
|
80
|
+
if (!sw.tiers.includes(tier))
|
|
81
|
+
return false;
|
|
82
|
+
if (tier === "develop" && !sw.tiers.includes("staging"))
|
|
83
|
+
return false;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
/** コメント行・空行・セクション行([files] / [members])を除いた、実質的な内容があるか */
|
|
87
|
+
export function hasContent(box, path) {
|
|
88
|
+
if (!box.files.exists(path))
|
|
89
|
+
return false;
|
|
90
|
+
return box.files
|
|
91
|
+
.readText(path)
|
|
92
|
+
.split("\n")
|
|
93
|
+
.some((line) => !/^\s*(#|$|\[files\]|\[members\])/.test(line));
|
|
94
|
+
}
|
|
95
|
+
export async function runCheckBranch(box) {
|
|
96
|
+
const head = box.env("HEAD_REF") ?? "";
|
|
97
|
+
const base = box.env("BASE_REF") ?? "";
|
|
98
|
+
const outFile = box.env("GITHUB_OUTPUT");
|
|
99
|
+
const say = (line) => box.output.out(line);
|
|
100
|
+
const setSkip = (skip) => {
|
|
101
|
+
const line = `skip=${skip}\n`;
|
|
102
|
+
if (outFile)
|
|
103
|
+
box.files.appendText(outFile, line);
|
|
104
|
+
else
|
|
105
|
+
say(line.trim());
|
|
106
|
+
};
|
|
107
|
+
if (head === "") {
|
|
108
|
+
box.output.err("[ERROR] HEAD_REF(PR の元のブランチ)が空です。");
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
// 段階の判定(doc/tier-scaling-design.md 3.4): マージ先から、検証に使う段階を決める。
|
|
112
|
+
// main → 判定しない(main を取得する通信の失敗で、main への PR の必須チェックを止めないため)
|
|
113
|
+
// staging → staging の段階 / それ以外 → develop の段階。段階として無効なら skip=true
|
|
114
|
+
if (base !== "main") {
|
|
115
|
+
const tier = base === "staging" ? "staging" : "develop";
|
|
116
|
+
const sw = await loadTiers(box);
|
|
117
|
+
if (sw === null) {
|
|
118
|
+
say("::error title=段階を判定できません::main を取得できません。段階を判定できないため、止めます。");
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
for (const w of sw.warnings)
|
|
122
|
+
say(w);
|
|
123
|
+
if (!tierEnabled(tier, sw)) {
|
|
124
|
+
setSkip(true);
|
|
125
|
+
say(`::notice title=検証しません::この PR の検証に使う ${tier} は、branches.txt にない(develop は staging もないときを含む)ため、段階として無効です。この PR は検証しません。`);
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const deploy = `sf-tools/release/${head}/deploy-target.txt`;
|
|
130
|
+
const remove = `sf-tools/release/${head}/remove-target.txt`;
|
|
131
|
+
if (!hasContent(box, deploy) && !hasContent(box, remove)) {
|
|
132
|
+
setSkip(true);
|
|
133
|
+
say(`デプロイ対象なし(${deploy} / ${remove} に内容なし)のためスキップします。`);
|
|
134
|
+
// 版・ワークフローだけを変える PR は、組織へは何も出さないが、次の段階が R1 で止まらないよう、リリースの印だけは付ける
|
|
135
|
+
// (wf-release の「印だけ付ける」ジョブが見る。REPOSITORY・PR_NUMBER があるときだけ。変更の一覧を読めなければ、印は付けない)
|
|
136
|
+
const tooling = await toolingChange(box);
|
|
137
|
+
if (tooling.state === "yes") {
|
|
138
|
+
if (outFile)
|
|
139
|
+
box.files.appendText(outFile, "mark_only=true\n");
|
|
140
|
+
say(`${tooling.path} を変える PR のため、組織へは出さず、リリースの印だけを付けます。`);
|
|
141
|
+
}
|
|
142
|
+
else if (tooling.state === "unknown") {
|
|
143
|
+
say("::warning::変更の一覧を読めないため、リリースの印は付けません(版・ワークフローの PR なら、この実行を Re-run jobs してください)。");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
setSkip(false);
|
|
148
|
+
}
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// wf-validate.yml・wf-release.yml・wf-metasync.yml の「接続先組織を選択」「Salesforce 組織にログイン」の移し先(sft ci select-org・login)。
|
|
2
|
+
// 秘密(秘密鍵・コンシューマーキー)は、環境変数でだけ受け取り、画面にもログにも出さない。
|
|
3
|
+
// 秘密鍵のファイルは、本人だけが読める権限で作り、ログインの成否にかかわらず(失敗しても・例外でも)、必ず消す
|
|
4
|
+
import { EXIT } from "./exit-codes.js";
|
|
5
|
+
import { maskSecrets } from "./mask.js";
|
|
6
|
+
/**
|
|
7
|
+
* 「接続先組織を選択」: マージ先のブランチから、接続先(main → PROD・staging → STG・それ以外 → DEV)を決め、
|
|
8
|
+
* SF_CONSUMER_KEY・SF_USERNAME・SF_INSTANCE_URL を GITHUB_ENV に書く。
|
|
9
|
+
* 入力: BASE_REF と、段階ごとの SF_CONSUMER_KEY_<段階>・SF_USERNAME_<段階>・SF_INSTANCE_URL_<段階>
|
|
10
|
+
*/
|
|
11
|
+
export function runSelectOrg(box) {
|
|
12
|
+
const base = box.env("BASE_REF") ?? "";
|
|
13
|
+
const [suffix, label] = base === "main" ? ["PROD", "main"] : base === "staging" ? ["STG", "staging"] : ["DEV", "develop"];
|
|
14
|
+
const file = box.env("GITHUB_ENV");
|
|
15
|
+
if (!file) {
|
|
16
|
+
box.output.err("[ERROR] GITHUB_ENV がありません。GitHub Actions の上で動かしてください。");
|
|
17
|
+
return EXIT.failure;
|
|
18
|
+
}
|
|
19
|
+
const line = (name) => `${name}=${box.env(`${name}_${suffix}`) ?? ""}\n`;
|
|
20
|
+
box.files.appendText(file, line("SF_CONSUMER_KEY") + line("SF_USERNAME") + line("SF_INSTANCE_URL"));
|
|
21
|
+
box.output.out(`接続先: ${label} の組織`);
|
|
22
|
+
return EXIT.ok;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 「Salesforce 組織にログイン」: JWT Bearer Flow。入力: SF_PRIVATE_KEY(base64)・SF_CONSUMER_KEY・SF_USERNAME・SF_INSTANCE_URL・ORG_ALIAS(既定 ci-org)。
|
|
26
|
+
* 秘密鍵が空・base64 でなければ、ログインを試みずに失敗にする
|
|
27
|
+
*/
|
|
28
|
+
export async function runLogin(box, deps) {
|
|
29
|
+
const encoded = (box.env("SF_PRIVATE_KEY") ?? "").trim();
|
|
30
|
+
if (encoded === "") {
|
|
31
|
+
box.output.err("[ERROR] SF_PRIVATE_KEY(秘密鍵)が空です。Secret の設定を確認してください。");
|
|
32
|
+
return EXIT.failure;
|
|
33
|
+
}
|
|
34
|
+
let text;
|
|
35
|
+
try {
|
|
36
|
+
text = new TextDecoder().decode(Uint8Array.from(atob(encoded.replace(/\s+/g, "")), (c) => c.charCodeAt(0)));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
box.output.err("[ERROR] SF_PRIVATE_KEY が base64 ではありません。Secret の設定を確認してください。");
|
|
40
|
+
return EXIT.failure;
|
|
41
|
+
}
|
|
42
|
+
let keyPath = null;
|
|
43
|
+
try {
|
|
44
|
+
keyPath = deps.write(text);
|
|
45
|
+
const r = await box.run("sf", [
|
|
46
|
+
"org",
|
|
47
|
+
"login",
|
|
48
|
+
"jwt",
|
|
49
|
+
"--client-id",
|
|
50
|
+
box.env("SF_CONSUMER_KEY") ?? "",
|
|
51
|
+
"--jwt-key-file",
|
|
52
|
+
keyPath,
|
|
53
|
+
"--username",
|
|
54
|
+
box.env("SF_USERNAME") ?? "",
|
|
55
|
+
"--instance-url",
|
|
56
|
+
box.env("SF_INSTANCE_URL") ?? "",
|
|
57
|
+
"--set-default",
|
|
58
|
+
"--alias",
|
|
59
|
+
box.env("ORG_ALIAS") || "ci-org",
|
|
60
|
+
]);
|
|
61
|
+
if (r.output !== "")
|
|
62
|
+
box.output.out(maskSecrets(r.output));
|
|
63
|
+
return r.code === 0 ? EXIT.ok : EXIT.failure;
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
box.output.err(`[ERROR] ログインを実行できません: ${maskSecrets(e instanceof Error ? e.message : String(e))}`);
|
|
67
|
+
return EXIT.failure;
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (keyPath !== null)
|
|
71
|
+
deps.remove(keyPath);
|
|
72
|
+
}
|
|
73
|
+
}
|