63 行
1.9 KiB
JavaScript
可执行文件
63 行
1.9 KiB
JavaScript
可执行文件
#!/usr/bin/env node
|
|
import { execSync } from "node:child_process";
|
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import process from "node:process";
|
|
|
|
const rootDir = path.resolve(new URL("../..", import.meta.url).pathname);
|
|
const reportDir = process.env.QA_REPORT_DIR || process.argv[2];
|
|
|
|
if (!reportDir) {
|
|
console.error("Usage: QA_REPORT_DIR=<dir> node scripts/qa/write-qa-summary.mjs");
|
|
process.exit(2);
|
|
}
|
|
|
|
function currentCommit() {
|
|
if (process.env.QA_COMMIT?.trim()) {
|
|
return process.env.QA_COMMIT.trim();
|
|
}
|
|
try {
|
|
return execSync("git rev-parse --short HEAD", {
|
|
cwd: rootDir,
|
|
encoding: "utf8",
|
|
stdio: ["ignore", "pipe", "ignore"],
|
|
}).trim();
|
|
} catch {
|
|
return "unknown";
|
|
}
|
|
}
|
|
|
|
function optionalValue(value) {
|
|
return value?.trim() || null;
|
|
}
|
|
|
|
function reportRef(file) {
|
|
const absolute = path.resolve(file);
|
|
const relative = path.relative(rootDir, absolute);
|
|
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) {
|
|
return relative;
|
|
}
|
|
return path.basename(absolute);
|
|
}
|
|
|
|
const reportDirRef = reportRef(reportDir);
|
|
|
|
const summary = {
|
|
issueId: optionalValue(process.env.QA_ISSUE_ID),
|
|
baseURL: optionalValue(process.env.QA_BASE_URL) ||
|
|
optionalValue(process.env.E2E_BASE_URL) ||
|
|
optionalValue(process.env.LIVE_SMOKE_BASE_URL),
|
|
commit: currentCommit(),
|
|
checkedAt: new Date().toISOString(),
|
|
status: optionalValue(process.env.QA_STATUS) || "UNKNOWN",
|
|
mode: optionalValue(process.env.QA_MODE),
|
|
reportDir: reportDirRef,
|
|
reportRef: reportDirRef,
|
|
groups: optionalValue(process.env.BUSINESS_FLOW_GROUPS),
|
|
notes: optionalValue(process.env.QA_SUMMARY_NOTES),
|
|
};
|
|
|
|
mkdirSync(reportDir, { recursive: true });
|
|
writeFileSync(path.join(reportDir, "summary.json"), JSON.stringify(summary, null, 2), "utf8");
|
|
console.log(`[qa-summary] ${summary.status} ${reportRef(path.join(reportDir, "summary.json"))}`);
|