@tama-create/sf-tools 1.4.0-dev.7 → 1.4.0-dev.9
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/dist/commands/index.js +7 -6
- package/dist/core/launcher-status.js +29 -2
- package/dist/core/log-box.js +32 -8
- package/dist/core/pr.js +12 -0
- package/dist/core/promote-check.js +2 -1
- package/dist/io/job-deps.js +21 -13
- package/dist/io/log-deps.js +2 -1
- package/dist/io/metasync-deps.js +3 -2
- package/dist/io/promote-deps.js +4 -3
- package/dist/io/temp-dir.js +15 -1
- package/dist/ui/launcher.js +41 -11
- package/package.json +1 -1
- package/templates-ts/.github/workflows/wf-sequence.yml +5 -2
- package/templates-ts/.github/workflows/wf-validate.yml +5 -4
package/dist/commands/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { commandLogged } from "../core/log-box.js";
|
|
1
2
|
import { adminCommand } from "./admin.js";
|
|
2
3
|
import { checkCommand } from "./check.js";
|
|
3
4
|
import { ciCommand } from "./ci.js";
|
|
@@ -17,19 +18,19 @@ import { updateCliCommand } from "./update-cli.js";
|
|
|
17
18
|
import { versionCommand } from "./version.js";
|
|
18
19
|
export const commands = [
|
|
19
20
|
adminCommand,
|
|
20
|
-
checkCommand,
|
|
21
|
+
commandLogged(checkCommand),
|
|
21
22
|
ciCommand,
|
|
22
|
-
deployCommand,
|
|
23
|
+
commandLogged(deployCommand),
|
|
23
24
|
doctorCommand,
|
|
24
|
-
dryrunCommand,
|
|
25
|
+
commandLogged(dryrunCommand),
|
|
25
26
|
hookCommand,
|
|
26
27
|
jobCommand,
|
|
27
28
|
logCommand,
|
|
28
29
|
metasyncCommand,
|
|
29
|
-
prCommand,
|
|
30
|
+
commandLogged(prCommand),
|
|
30
31
|
projectCommand,
|
|
31
|
-
pushCommand,
|
|
32
|
-
releaseCommand,
|
|
32
|
+
commandLogged(pushCommand),
|
|
33
|
+
commandLogged(releaseCommand),
|
|
33
34
|
switchOrgCommand,
|
|
34
35
|
updateCliCommand,
|
|
35
36
|
versionCommand,
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// 1 行目: 「 >> LAUNCHER << <ブランチ> @ <組織> / 変更 N 件 / Log: <デバッグログの状態>」(ないものは出さない)
|
|
4
4
|
// ブランチの上にいなければ「(ブランチの上にいません)」(と組織)だけ
|
|
5
5
|
// Log の WARNING があれば「⚠ Log: …」をもう 1 行。環境ブランチの上なら「⚠ 環境ブランチの上です…」で終わる
|
|
6
|
-
// 2 行目: 「Branch: <段階の並び>」(sf-tools/logs/next-status.txt。HEAD=
|
|
6
|
+
// 2 行目: 「Branch: <段階の並び>」(sf-tools/logs/next-status.txt。HEAD= が今の先端と同じで、形が正しく、
|
|
7
|
+
// SKIPPED= が今の対象のファイル(作業ツリー)の空・空でないと合うときだけ使う)。
|
|
8
|
+
// 対象を書いたファイルにコミット前の変更があるときは「コミット前の変更があります」(次の PR 先は出さない・判定も頼まない)
|
|
7
9
|
// 使えないときは、裏の判定(sft pr --status)を頼み、動いているあいだは「(確かめています…)」、
|
|
8
10
|
// 終わった・頼めないときは「(<番号> PullRequest で確かめる)」
|
|
9
11
|
// 表示する値は cleanText で掃除する(制御文字・幅のない文字・文字の向きを変える文字・BOM を除き、画面を崩させない)
|
|
@@ -52,6 +54,23 @@ export function parseGitStatus(text) {
|
|
|
52
54
|
}
|
|
53
55
|
return { branch: branch === "(detached)" ? "" : branch, head: head === "(initial)" ? "" : head, changes };
|
|
54
56
|
}
|
|
57
|
+
/** git status --porcelain=v2 の出力で、このブランチの対象のファイル(deploy-target.txt・remove-target.txt)にコミット前の変更があるか */
|
|
58
|
+
export function uncommittedTargets(statusText, branch) {
|
|
59
|
+
if (branch === "")
|
|
60
|
+
return false;
|
|
61
|
+
const targets = ["deploy-target.txt", "remove-target.txt"].map((f) => `sf-tools/release/${branch}/${f}`);
|
|
62
|
+
// パスより前の欄の数(1: 変更・2: 名前の変更・u: 衝突・?: 追跡していない)
|
|
63
|
+
const skip = { "1": 8, "2": 9, u: 10, "?": 1 };
|
|
64
|
+
return statusText.split("\n").some((raw) => {
|
|
65
|
+
const fields = raw.replace(/\r$/, "").split(" ");
|
|
66
|
+
const n = skip[fields[0] ?? ""];
|
|
67
|
+
if (n === undefined)
|
|
68
|
+
return false;
|
|
69
|
+
const path = fields.slice(n).join(" ").split("\t")[0] ?? "";
|
|
70
|
+
// 追跡していないフォルダは「sf-tools/release/」のように、まとめて出る
|
|
71
|
+
return targets.some((t) => t === path || (path.endsWith("/") && t.startsWith(path)));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
55
74
|
/** .sf/config.json の target-org(読めなければ空。掃除して、60 文字を超えたら切って … を付ける) */
|
|
56
75
|
export function targetOrg(json) {
|
|
57
76
|
if (json === null)
|
|
@@ -148,8 +167,16 @@ export function statusLines(input, paint) {
|
|
|
148
167
|
lines.push(`${PAD}${paint.yellow("⚠ 環境ブランチの上です。作業は、sft job で作ったブランチで行います")}`);
|
|
149
168
|
return { lines, wantCheck: false };
|
|
150
169
|
}
|
|
170
|
+
// 対象を書いてもコミット前は、PR に入らないので、次の PR 先を出さない
|
|
171
|
+
if (input.uncommitted && input.targetsEmpty === false) {
|
|
172
|
+
lines.push(`${PAD}Branch: ${paint.yellow("コミット前の変更があります(Push のあとで確かめます)")}`);
|
|
173
|
+
return { lines, wantCheck: false };
|
|
174
|
+
}
|
|
151
175
|
const ask = paint.dim(`(${input.prNumber} PullRequest で確かめる)`);
|
|
152
|
-
|
|
176
|
+
let st = parseNextStatus(input.nextStatus, input.git.head);
|
|
177
|
+
// 判定は対象のファイルの中身にもよる。先端のコミットが同じでも、空・空でないが変わっていたら、古い結果は使わない
|
|
178
|
+
if (st && input.targetsEmpty != null && st.skipped !== input.targetsEmpty)
|
|
179
|
+
st = null;
|
|
153
180
|
let rel;
|
|
154
181
|
let wantCheck = false;
|
|
155
182
|
if (st?.skipped) {
|
package/dist/core/log-box.js
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
// - 外のコマンドは、[CMD] の行(引数)と、[OUT] の行(出力)と、終了コードを書く(画面には出さない)
|
|
6
6
|
// - 伏せ字: maskSecrets に加えて、--client-id の値(コンシューマーキー)を伏せる。標準入力に渡した値(Token など)は書かない
|
|
7
7
|
// - ログが書けなくても、コマンドは止めない(ログは補助)
|
|
8
|
+
// - 毎日のコマンド(check・dryrun・deploy・release・push・pr)は commandLogged で、sf-tools/logs/<サブコマンド>.log に残す。
|
|
9
|
+
// 書くのは、画面に出した行(標準出力・標準エラー)と、[CMD] の行と、終了コードだけ。外のコマンドの出力は書かない
|
|
10
|
+
// (画面に出さない応答には、接続の確認の中身など、形の分からない秘密がありうるため)
|
|
8
11
|
import { fileLine, prefixLines, stripTermCodes, timestamp } from "./log-format.js";
|
|
9
12
|
import { maskSecrets } from "./mask.js";
|
|
10
13
|
const LEVEL_RE = /^\s*\[(HEADER|INFO|SUCCESS|WARNING|ERROR|FATAL)\]\s?(.*)$/;
|
|
@@ -26,7 +29,20 @@ export function logEntry(ts, line) {
|
|
|
26
29
|
const text = maskSecrets(m ? (m[2] ?? "") : clean.trim());
|
|
27
30
|
return fileLine(ts, level, level === "HEADER" ? text.trim() : text);
|
|
28
31
|
}
|
|
29
|
-
|
|
32
|
+
/** 実行のたびに sf-tools/logs/<サブコマンド>.log を書くコマンドにする。sf-tools/ のない場所と、pr --status(裏の判定)では書かない */
|
|
33
|
+
export function commandLogged(command) {
|
|
34
|
+
return {
|
|
35
|
+
...command,
|
|
36
|
+
run: (args, box) => {
|
|
37
|
+
if (!box.files.isDir("sf-tools") || args.includes("--status"))
|
|
38
|
+
return command.run(args, box);
|
|
39
|
+
const file = `sf-tools/logs/${command.name}.log`;
|
|
40
|
+
return command.run(args, fileLoggedBox(box, file, `sft ${command.name}`, { screenOnly: true }));
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** screenOnly: 標準出力の行も書き、外のコマンドの出力は書かない */
|
|
45
|
+
export function fileLoggedBox(box, file, name, options = {}) {
|
|
30
46
|
let ok = true;
|
|
31
47
|
const write = (text) => {
|
|
32
48
|
if (!ok || text === "")
|
|
@@ -49,21 +65,28 @@ export function fileLoggedBox(box, file, name) {
|
|
|
49
65
|
}
|
|
50
66
|
const now = () => timestamp(box.clock.now());
|
|
51
67
|
write(`[${now()}] [INFO] ${name} を開始しました\n`);
|
|
68
|
+
const record = (line) => {
|
|
69
|
+
const ts = now();
|
|
70
|
+
for (const l of line.split("\n"))
|
|
71
|
+
write(logEntry(ts, l) ?? "");
|
|
72
|
+
};
|
|
52
73
|
return {
|
|
53
74
|
...box,
|
|
54
75
|
output: {
|
|
55
|
-
out: (line) =>
|
|
76
|
+
out: (line) => {
|
|
77
|
+
box.output.out(line);
|
|
78
|
+
if (options.screenOnly)
|
|
79
|
+
record(line);
|
|
80
|
+
},
|
|
56
81
|
err: (line) => {
|
|
57
82
|
box.output.err(line);
|
|
58
|
-
|
|
59
|
-
for (const l of line.split("\n"))
|
|
60
|
-
write(logEntry(ts, l) ?? "");
|
|
83
|
+
record(line);
|
|
61
84
|
},
|
|
62
85
|
},
|
|
63
|
-
run: async (command, args,
|
|
86
|
+
run: async (command, args, runOptions) => {
|
|
64
87
|
write(fileLine(now(), "CMD", `[${name}] ${commandText(command, args)}`));
|
|
65
88
|
try {
|
|
66
|
-
const r = await box.run(command, args,
|
|
89
|
+
const r = await box.run(command, args, runOptions);
|
|
67
90
|
const ts = now();
|
|
68
91
|
// 出力に含まれうる、秘密を入れる引数の値(コンシューマーキー)も伏せる。Actions のログ全体(gh run view --log)は、大きいので記録しない
|
|
69
92
|
const secrets = args.filter((_, i) => i > 0 && SECRET_ARGS.has(args[i - 1]) && args[i] !== "");
|
|
@@ -71,7 +94,8 @@ export function fileLoggedBox(box, file, name) {
|
|
|
71
94
|
let text = maskSecrets(stripTermCodes(r.output));
|
|
72
95
|
for (const s of secrets)
|
|
73
96
|
text = text.split(s).join("***masked***");
|
|
74
|
-
|
|
97
|
+
if (!options.screenOnly)
|
|
98
|
+
write(quiet ? `[${ts}] [OUT] (Actions のログ全体は、記録しません)\n` : prefixLines(`[${ts}] [OUT] `, text));
|
|
75
99
|
if (r.code !== 0)
|
|
76
100
|
write(`[${ts}] [OUT] (終了コード ${r.code}${r.timedOut ? "・時間切れ" : ""}${r.aborted ? "・中断" : ""})\n`);
|
|
77
101
|
return r;
|
package/dist/core/pr.js
CHANGED
|
@@ -124,6 +124,18 @@ export async function runPr(args, box, deps, ask) {
|
|
|
124
124
|
log("SUCCESS", `判定の結果を書きました(${NEXT_STATUS_FILE}。次の段階: ${plan.next})`);
|
|
125
125
|
return EXIT.ok;
|
|
126
126
|
}
|
|
127
|
+
// 対象のファイルにコミット前の変更があるときは、PR に入らないので、次の PR 先を勧めない
|
|
128
|
+
if (!plan.skipped) {
|
|
129
|
+
const targets = ["deploy-target.txt", "remove-target.txt"].map((f) => `sf-tools/release/${current}/${f}`);
|
|
130
|
+
const dirty = await box.run("git", ["status", "--porcelain", "--", ...targets]).catch(() => null);
|
|
131
|
+
if (dirty !== null && dirty.code === 0 && dirty.stdout.trim() !== "") {
|
|
132
|
+
const fact = "ターゲットファイルに、コミットしていない変更があります(PR に入りません)。先に Push してください。";
|
|
133
|
+
if (create)
|
|
134
|
+
return die(fact);
|
|
135
|
+
log("WARNING", fact);
|
|
136
|
+
return EXIT.ok;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
127
139
|
// --- 表示(段階は、下から順) ---
|
|
128
140
|
const width = Math.max(...plan.tiers.map((t) => t.length));
|
|
129
141
|
box.output.err("");
|
|
@@ -17,7 +17,8 @@ function succeeded(r) {
|
|
|
17
17
|
class CannotJudge extends Error {
|
|
18
18
|
}
|
|
19
19
|
/** deploy-target.txt・remove-target.txt の、実質的な行の数。ファイルがなければ null */
|
|
20
|
-
|
|
20
|
+
/** 対象のファイル(deploy-target.txt・remove-target.txt)の実質的な行の数。ファイルがなければ null(ランチャーも使う) */
|
|
21
|
+
export function countTargets(box, path) {
|
|
21
22
|
if (!box.files.exists(path))
|
|
22
23
|
return null;
|
|
23
24
|
let n = 0;
|
package/dist/io/job-deps.js
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
// sft job
|
|
2
|
-
//
|
|
1
|
+
// sft job の外の部品の本物。クローンのあとは、そのフォルダへ移って、そこで sft(引数なし)を打ったのと同じ手順
|
|
2
|
+
// (版の固定の確認・中の版への受け渡し → 起動の準備とランチャー)を動かす(src/launch.ts。循環を避けるため、動かすときに読み込む)。
|
|
3
|
+
// 自分の版のまま起動すると、版を固定したプロジェクトで、固定と違う版が動き、中の版もフックも入らない(設計 4.2 の 4)
|
|
4
|
+
import { realpathSync } from "node:fs";
|
|
3
5
|
import { basename, resolve } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
4
7
|
import { chooseNumber, readOrQuit } from "../ui/prompt.js";
|
|
8
|
+
/** クローン先に移って、引数なしの sft を起動する。戻り値は終了コード。移れなければ null */
|
|
9
|
+
export async function launchInClone(box, repoDir, load) {
|
|
10
|
+
try {
|
|
11
|
+
process.chdir(resolve(repoDir));
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
box.output.err(`[ERROR] クローン先に移れません: ${repoDir}`);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const { launch } = await import("../launch.js");
|
|
18
|
+
// 中の版は、process.argv の引数で動く(受け渡しの約束: src/launch.ts)。job の引数を残すと、中の版で job がもう一度動く
|
|
19
|
+
process.argv.splice(2);
|
|
20
|
+
const selfEntry = realpathSync(fileURLToPath(new URL("../../bin/sft.js", import.meta.url)));
|
|
21
|
+
return launch({ argv: [], selfEntry, cwd: process.cwd(), env: process.env, box, load });
|
|
22
|
+
}
|
|
5
23
|
export function realJobDeps(box) {
|
|
6
24
|
return {
|
|
7
25
|
prompts: {
|
|
@@ -16,16 +34,6 @@ export function realJobDeps(box) {
|
|
|
16
34
|
},
|
|
17
35
|
folderName: basename(process.cwd()),
|
|
18
36
|
cwd: process.cwd(),
|
|
19
|
-
startLauncher:
|
|
20
|
-
try {
|
|
21
|
-
process.chdir(resolve(repoDir));
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
box.output.err(`[ERROR] クローン先に移れません: ${repoDir}`);
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
const [{ commands }, { openStart }] = await Promise.all([import("../commands/index.js"), import("../commands/start.js")]);
|
|
28
|
-
return openStart(box, commands);
|
|
29
|
-
},
|
|
37
|
+
startLauncher: (repoDir) => launchInClone(box, repoDir),
|
|
30
38
|
};
|
|
31
39
|
}
|
package/dist/io/log-deps.js
CHANGED
|
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { RUNTIME_SELF } from "../core/log-pull.js";
|
|
7
|
+
import { removeTree } from "./temp-dir.js";
|
|
7
8
|
import { upgradeRunning } from "./update-cli-deps.js";
|
|
8
9
|
/** 別の環境のロックは、10 分で古いとみなす(シェル版の FOREIGN_LOCK_AGE と同じ) */
|
|
9
10
|
const FOREIGN_LOCK_AGE = 600;
|
|
@@ -78,7 +79,7 @@ export function realLogPullDeps(box) {
|
|
|
78
79
|
...realLogSummarizeDeps(box),
|
|
79
80
|
lock: folderLock(),
|
|
80
81
|
makeTempDir: () => mkdtempSync(join(tmpdir(), "sft-log-")),
|
|
81
|
-
removeDir:
|
|
82
|
+
removeDir: removeTree,
|
|
82
83
|
pidAlive,
|
|
83
84
|
};
|
|
84
85
|
}
|
package/dist/io/metasync-deps.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// sft metasync の外の部品の本物(一時フォルダ・lib/metasync.js と config/ の場所・今日の日付)。テストは、偽物を渡す(src/core/metasync.ts)
|
|
2
|
-
import { mkdtempSync
|
|
2
|
+
import { mkdtempSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { askYesNo } from "../ui/confirm.js";
|
|
7
|
+
import { removeTree } from "./temp-dir.js";
|
|
7
8
|
export function realMetasyncDeps(box) {
|
|
8
9
|
const here = (rel) => fileURLToPath(new URL(rel, import.meta.url));
|
|
9
10
|
return {
|
|
10
11
|
makeTempDir: () => mkdtempSync(join(process.env.TMPDIR || tmpdir(), "sf-metasync-")),
|
|
11
|
-
removeDir:
|
|
12
|
+
removeDir: removeTree,
|
|
12
13
|
confirm: (q) => askYesNo(box.input, q),
|
|
13
14
|
metasyncJs: box.env("SF_METASYNC_JS") || here("../../lib/metasync.js"),
|
|
14
15
|
configDir: box.env("SF_METASYNC_CONFIG_DIR") || here("../../config"),
|
package/dist/io/promote-deps.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
// promote-check の外の部品の本物(一時フォルダ・マニフェストの作成)。テストは、偽物を渡す(src/core/promote-check.ts)
|
|
2
|
-
import { mkdtempSync
|
|
2
|
+
import { mkdtempSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { buildManifest } from "../core/manifest-build.js";
|
|
6
6
|
import { pairsAll } from "../core/promote.js";
|
|
7
|
+
import { removeTree } from "./temp-dir.js";
|
|
7
8
|
export function realPromoteDeps(box) {
|
|
8
9
|
let count = 0;
|
|
9
10
|
let base = null;
|
|
10
11
|
return {
|
|
11
12
|
makeTempDir: () => mkdtempSync(join(tmpdir(), "sf-promote-check-")),
|
|
12
13
|
removeDir: (path) => {
|
|
13
|
-
|
|
14
|
+
removeTree(path);
|
|
14
15
|
if (base)
|
|
15
|
-
|
|
16
|
+
removeTree(base);
|
|
16
17
|
},
|
|
17
18
|
buildPairs: async (dir, branch) => {
|
|
18
19
|
base ??= mkdtempSync(join(tmpdir(), "sf-promote-manifest-"));
|
package/dist/io/temp-dir.js
CHANGED
|
@@ -2,9 +2,23 @@
|
|
|
2
2
|
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
/**
|
|
6
|
+
* フォルダを消す。Windows では、ウイルス対策・インデクサー・終わったばかりの子プロセスが、フォルダをつかんでいて、EPERM・EBUSY で
|
|
7
|
+
* 消せないことがある(ときどき起きる)ため、再試行する(maxRetries・retryDelay)。それでも消せなければ、止めずに、消せなかった場所を
|
|
8
|
+
* 警告に出す(中に、アクセストークンなどが残ることがある。手で消してもらう)。呼ぶ側の処理を、後始末の失敗で、失敗にしない
|
|
9
|
+
*/
|
|
10
|
+
export function removeTree(path) {
|
|
11
|
+
try {
|
|
12
|
+
rmSync(path, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 });
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
const code = e.code ?? "";
|
|
16
|
+
process.stderr.write(`[WARNING] 一時フォルダを消せませんでした(${code})。中に、秘密の値が残っているかもしれません。手で消してください: ${path}\n`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
5
19
|
export function realTempDeps(prefix) {
|
|
6
20
|
return {
|
|
7
21
|
makeTempDir: () => mkdtempSync(join(process.env.TMPDIR || tmpdir(), prefix)),
|
|
8
|
-
removeDir:
|
|
22
|
+
removeDir: removeTree,
|
|
9
23
|
};
|
|
10
24
|
}
|
package/dist/ui/launcher.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// ランチャー(sft を引数なしで、force-* の中で打ったときのメニュー)。phases/start/launcher.sh の移し先(doc/rebuild-design.md 6.1)。
|
|
2
2
|
// 項目は、サブコマンドの表(menu を持つもの)から作る。番号のキーを押すとすぐ動き(Enter は要らない)、終わるとメニューに戻る。
|
|
3
3
|
// q と入力の終わりで終了(0)。範囲外の数字・ほかのキーは聞き直す。Ctrl+C は、メニューの中では無効(誤って閉じない: 6.3)。
|
|
4
|
+
// 何も打たずに Enter: メニューを描き直し、裏の判定をやり直す(PR のマージは先端のコミットを変えないため、保存した結果では次の段階に変わらない)。
|
|
5
|
+
// 判定が動いているあいだの Enter は、描き直すだけ(2 つ同時には動かさない)。
|
|
4
6
|
// 見出し(core/launcher-status.ts)は、メニューを描くたびに作る。入力を 5 秒ずつ待ち、デバッグログの状態(準備中・取得中)が
|
|
5
7
|
// 変わった・裏の判定(sft pr --status)が終わったら、コマンドを動かさずに描き直す(待っている入力は、そのまま続ける)。
|
|
6
8
|
// 結果は 1 行: 0 →「✓ <名前>: 終わりました(成功)」/ それ以外 →「✗ <名前>: 失敗、または中断しました(終了コード N)」。
|
|
7
9
|
// なくしたもの: 自分のファイルの書き換わりを見て読み込み直す動き(版を固定するため: 設計 2.4.2)。
|
|
8
10
|
// 組織への接続・doctor・デバッグログの取得は、開く前に src/core/start.ts が行う。項目 Start は、組織の接続・VS Code・doctor をやり直す(src/commands/start.ts。ランチャーは開き直さない)
|
|
9
|
-
import { apexlogState, makePaint, parseGitStatus, statusLines, targetOrg } from "../core/launcher-status.js";
|
|
11
|
+
import { apexlogState, makePaint, parseGitStatus, statusLines, targetOrg, uncommittedTargets } from "../core/launcher-status.js";
|
|
12
|
+
import { countTargets } from "../core/promote-check.js";
|
|
10
13
|
const LINE = "──────────────────────────────────────────────────";
|
|
11
14
|
const readOrNull = (box, path) => {
|
|
12
15
|
try {
|
|
@@ -29,11 +32,23 @@ export async function runLauncher(args, box, deps) {
|
|
|
29
32
|
}
|
|
30
33
|
const { items } = deps;
|
|
31
34
|
const prNumber = items.findIndex((i) => i.name === "pr") + 1;
|
|
32
|
-
const prompt = ` 番号を入力 (1-${items.length} / q で終了): `;
|
|
33
|
-
|
|
35
|
+
const prompt = ` 番号を入力 (1-${items.length} / Enter で再表示 / q で終了): `;
|
|
36
|
+
/** 裏の判定を最後に頼んだときの、先端のコミットと対象のファイルの空・空でない */
|
|
37
|
+
let checkedKey = "";
|
|
34
38
|
let checking = false;
|
|
35
39
|
let checkDone = false;
|
|
36
|
-
|
|
40
|
+
/** Enter で頼まれた判定のやり直し(次に描くとき、保存した結果を使わずに判定する) */
|
|
41
|
+
let recheck = false;
|
|
42
|
+
const wantCheckFor = (head, key) => head !== "" && key !== checkedKey;
|
|
43
|
+
const targetsEmpty = (branch) => {
|
|
44
|
+
try {
|
|
45
|
+
const counts = ["deploy-target.txt", "remove-target.txt"].map((f) => countTargets(box, `sf-tools/release/${branch}/${f}`));
|
|
46
|
+
return counts.every((n) => n === null) ? null : counts.every((n) => !n);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
37
52
|
const envBranches = () => {
|
|
38
53
|
const text = readOrNull(box, "sf-tools/config/branches.txt") ?? "";
|
|
39
54
|
return text
|
|
@@ -43,19 +58,28 @@ export async function runLauncher(args, box, deps) {
|
|
|
43
58
|
};
|
|
44
59
|
const draw = async () => {
|
|
45
60
|
const st = await box.run("git", ["status", "--porcelain=v2", "--branch"]).catch(() => null);
|
|
46
|
-
const
|
|
61
|
+
const statusText = st !== null && st.code === 0 ? st.stdout : "";
|
|
62
|
+
const git = parseGitStatus(statusText);
|
|
63
|
+
const empty = targetsEmpty(git.branch);
|
|
64
|
+
const key = `${git.head} ${empty}`;
|
|
65
|
+
const fresh = recheck && !checking && deps.startPrStatus !== null;
|
|
66
|
+
if (fresh)
|
|
67
|
+
checkedKey = "";
|
|
68
|
+
recheck = false;
|
|
47
69
|
const { lines, wantCheck } = statusLines({
|
|
48
70
|
git,
|
|
49
71
|
org: targetOrg(readOrNull(box, ".sf/config.json")),
|
|
50
72
|
apexlog: readOrNull(box, "logs/apex/.status"),
|
|
51
|
-
nextStatus: readOrNull(box, "sf-tools/logs/next-status.txt"),
|
|
73
|
+
nextStatus: fresh ? null : readOrNull(box, "sf-tools/logs/next-status.txt"),
|
|
74
|
+
targetsEmpty: empty,
|
|
75
|
+
uncommitted: uncommittedTargets(statusText, git.branch),
|
|
52
76
|
envBranches: envBranches(),
|
|
53
|
-
checking: checking || (wantCheckFor(git.head) && deps.startPrStatus !== null), // これから始める分も「確かめています」
|
|
77
|
+
checking: checking || (wantCheckFor(git.head, key) && deps.startPrStatus !== null), // これから始める分も「確かめています」
|
|
54
78
|
prNumber,
|
|
55
79
|
}, paint);
|
|
56
|
-
// 使える結果がない →
|
|
57
|
-
if (wantCheck && wantCheckFor(git.head) && deps.startPrStatus !== null) {
|
|
58
|
-
|
|
80
|
+
// 使える結果がない → 裏で判定する(先端のコミットと対象の空・空でないの組ごとに 1 回。失敗しても繰り返さない)
|
|
81
|
+
if (wantCheck && wantCheckFor(git.head, key) && deps.startPrStatus !== null) {
|
|
82
|
+
checkedKey = key;
|
|
59
83
|
checking = true;
|
|
60
84
|
deps
|
|
61
85
|
.startPrStatus()
|
|
@@ -82,7 +106,7 @@ export async function runLauncher(args, box, deps) {
|
|
|
82
106
|
let shown = apexlogState(readOrNull(box, "logs/apex/.status"));
|
|
83
107
|
let pending = box.input.readKey(prompt);
|
|
84
108
|
let chosen = null;
|
|
85
|
-
while (chosen === null) {
|
|
109
|
+
while (chosen === null && !recheck) {
|
|
86
110
|
const got = await Promise.race([pending.then((key) => ({ key })), deps.tick().then(() => null)]);
|
|
87
111
|
if (got === null) {
|
|
88
112
|
// 待ち切れ: 準備中・取得中の状態が変わった・裏の判定が終わったら、描き直す(本数・期限の更新では描き直さない)
|
|
@@ -106,6 +130,10 @@ export async function runLauncher(args, box, deps) {
|
|
|
106
130
|
err("");
|
|
107
131
|
return 0;
|
|
108
132
|
}
|
|
133
|
+
if (key === "" || key === "\r" || key === "\n") {
|
|
134
|
+
recheck = true;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
109
137
|
const n = /^[1-9]$/.test(key) ? Number(key) : 0;
|
|
110
138
|
const item = n >= 1 && n <= items.length ? items[n - 1] : undefined;
|
|
111
139
|
if (item)
|
|
@@ -113,6 +141,8 @@ export async function runLauncher(args, box, deps) {
|
|
|
113
141
|
else
|
|
114
142
|
pending = box.input.readKey(prompt); // 範囲外・ほかのキー・Ctrl+C は聞き直す
|
|
115
143
|
}
|
|
144
|
+
if (chosen === null)
|
|
145
|
+
continue; // Enter: 描き直す
|
|
116
146
|
err("");
|
|
117
147
|
err(paint.green(` ▶ sft ${chosen.name}`));
|
|
118
148
|
err("");
|
package/package.json
CHANGED
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
# Actions の画面での名前は「[sequence] マージ順序チェック」(最上位の name:)。
|
|
14
14
|
#
|
|
15
15
|
# 【起動の条件】
|
|
16
|
-
# - pull_request(opened / synchronize / reopened)で、マージ先が main または staging のとき
|
|
17
|
-
# -
|
|
16
|
+
# - pull_request(opened / synchronize / reopened / edited)で、マージ先が main または staging のとき
|
|
17
|
+
# - edited は、マージ先を main / staging に変えたときにも確かめるため。タイトル・本文だけの変更でも動く(ジョブの if で絞らない:
|
|
18
|
+
# スキップされたジョブは必須チェックで成功の扱いになり、失敗した結果が隠れるため)
|
|
19
|
+
# - 起動しない場合: develop など、main / staging 以外への PR。closed・直接の push・コンフリクトのある PR
|
|
18
20
|
#
|
|
19
21
|
# 【ジョブ】
|
|
20
22
|
# 1. 対象ファイル確認(check-branch): sft ci sequence-branch。順序チェックが必要かを判定し、出力 skip を返す。常に実行する
|
|
@@ -43,6 +45,7 @@
|
|
|
43
45
|
name: "[sequence] マージ順序チェック"
|
|
44
46
|
on:
|
|
45
47
|
pull_request:
|
|
48
|
+
types: [opened, synchronize, reopened, edited]
|
|
46
49
|
branches:
|
|
47
50
|
- main
|
|
48
51
|
- staging
|
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
# (手順の中身は src/core/ci-*.ts)。sf-tools は、git clone ではなく、force-* の sf-tools/package.json の版を npm で入れる。
|
|
9
9
|
#
|
|
10
10
|
# 【起動の条件】
|
|
11
|
-
# - pull_request の opened / synchronize / reopened。マージ先のブランチは問わない
|
|
12
|
-
# -
|
|
13
|
-
#
|
|
11
|
+
# - pull_request の opened / synchronize / reopened / edited。マージ先のブランチは問わない
|
|
12
|
+
# - edited は、マージ先を変えたとき、新しいマージ先の組織で検証し直すため。タイトル・本文だけの変更でも動く。
|
|
13
|
+
# ジョブの if で絞らない(スキップされたジョブは必須チェックで成功の扱いになり、タイトルを直すだけで、失敗した結果が隠れるため)
|
|
14
|
+
# - 起動しない場合: マージ・クローズ、ブランチへの直接の push、コンフリクトのある PR。workflow_dispatch・schedule はない
|
|
14
15
|
#
|
|
15
16
|
# 【ジョブ】
|
|
16
17
|
# 1. 対象ファイル確認(check-branch): sft ci check-branch。デプロイ対象があるかを判定し、出力 skip を返す。常に実行する
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
name: "[validate] デプロイ前検証"
|
|
48
49
|
on:
|
|
49
50
|
pull_request:
|
|
50
|
-
types: [opened, synchronize, reopened]
|
|
51
|
+
types: [opened, synchronize, reopened, edited]
|
|
51
52
|
|
|
52
53
|
env:
|
|
53
54
|
# sft の入口(絶対パス。working-directory を変えるステップからも呼ぶため)
|