feat: share go env reuse artifact
This commit is contained in:
@@ -25,6 +25,10 @@ export const GO_RUNTIME_DEP_PATHS = Object.freeze([
|
||||
"deploy/runtime/launcher/hwlab-go-env-reuse-launcher.mjs"
|
||||
]);
|
||||
|
||||
const COMMENT_INSENSITIVE_ENV_IDENTITY_PATHS = new Set([
|
||||
"deploy/runtime/launcher/hwlab-go-env-reuse-launcher.mjs"
|
||||
]);
|
||||
|
||||
export const DEFAULT_RUNTIME_PACKAGE_FIELDS = Object.freeze([
|
||||
"dependencies",
|
||||
"optionalDependencies",
|
||||
@@ -629,12 +633,25 @@ export async function runtimeDependencyChangedPaths(repoRoot, baseRef, targetRef
|
||||
result.add(filePath);
|
||||
continue;
|
||||
}
|
||||
if (COMMENT_INSENSITIVE_ENV_IDENTITY_PATHS.has(filePath)) {
|
||||
if (await envIdentityTextChanged(repoRoot, baseRef, targetRef, filePath)) result.add(filePath);
|
||||
continue;
|
||||
}
|
||||
if (filePath !== "package.json") continue;
|
||||
if (await packageRuntimeFieldsChanged(repoRoot, baseRef, targetRef, filePath)) result.add(filePath);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async function envIdentityTextChanged(repoRoot, baseRef, targetRef, filePath) {
|
||||
const [before, after] = await Promise.all([
|
||||
readTextFromGit(repoRoot, baseRef, filePath, null),
|
||||
readTextFromGit(repoRoot, targetRef, filePath, null)
|
||||
]);
|
||||
if (before === null || after === null) return true;
|
||||
return stableJson(normalizeEnvIdentityText(filePath, before)) !== stableJson(normalizeEnvIdentityText(filePath, after));
|
||||
}
|
||||
|
||||
async function serviceRuntimeConfigChanged(repoRoot, deployConfigPath, baseRef, targetRef, lane, serviceId) {
|
||||
const [before, after] = await Promise.all([
|
||||
readDeployConfigFromGit(repoRoot, baseRef, deployConfigPath),
|
||||
@@ -690,13 +707,21 @@ function pickRuntimePackageJson(packageJson) {
|
||||
|
||||
async function readJsonFromGit(repoRoot, ref, filePath, fallback) {
|
||||
try {
|
||||
const value = await gitValue(repoRoot, ["show", `${ref}:${filePath}`]);
|
||||
const value = await readTextFromGit(repoRoot, ref, filePath, "");
|
||||
return JSON.parse(value);
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
async function readTextFromGit(repoRoot, ref, filePath, fallback) {
|
||||
try {
|
||||
return await gitValue(repoRoot, ["show", `${ref}:${filePath}`]);
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
export function enabledEnvReuseServices(deployJson, lane, serviceIds) {
|
||||
const configured = deployJson?.lanes?.[lane]?.envReuseServices;
|
||||
const values = Array.isArray(configured) ? configured : [];
|
||||
@@ -925,6 +950,10 @@ export async function hashGitPaths(repoRoot, targetRef, paths, options = {}) {
|
||||
const packageJson = await readJsonFromGit(repoRoot, targetRef, filePath, null);
|
||||
return `100644 blob ${stableHash(pickRuntimePackageJson(packageJson))}\t${filePath}`;
|
||||
}
|
||||
if (COMMENT_INSENSITIVE_ENV_IDENTITY_PATHS.has(filePath)) {
|
||||
const source = await readTextFromGit(repoRoot, targetRef, filePath, "");
|
||||
return `100644 blob ${stableHash(normalizeEnvIdentityText(filePath, source))}\t${filePath}`;
|
||||
}
|
||||
return line;
|
||||
})))
|
||||
.filter(Boolean)
|
||||
@@ -932,6 +961,19 @@ export async function hashGitPaths(repoRoot, targetRef, paths, options = {}) {
|
||||
return stableHash({ entries: lines });
|
||||
}
|
||||
|
||||
function normalizeEnvIdentityText(filePath, source) {
|
||||
const normalizedPath = normalizeRepoPath(filePath);
|
||||
const text = String(source ?? "").replace(/\r\n?/gu, "\n");
|
||||
if (!COMMENT_INSENSITIVE_ENV_IDENTITY_PATHS.has(normalizedPath)) return text;
|
||||
return text
|
||||
.split("\n")
|
||||
.filter((line) => {
|
||||
const trimmed = line.trim();
|
||||
return trimmed && !trimmed.startsWith("//");
|
||||
})
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
async function hashEnvReuseInputs(repoRoot, targetRef, paths, recipe, options = {}) {
|
||||
return stableHash({
|
||||
gitPaths: await hashGitPaths(repoRoot, targetRef, paths, options),
|
||||
|
||||
Reference in New Issue
Block a user