Execute scoped deploy action reliably
vadimenovikau/Platform-CI: Immutable QuickStack OCI deployment / Build once and deploy exact digest (push) Successful in 23s
vadimenovikau/Platform-CI: Immutable QuickStack OCI deployment / Build once and deploy exact digest (push) Successful in 23s
This commit is contained in:
@@ -259,6 +259,27 @@ export function validateTarget(target) {
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveDeploymentBranch({ eventName, environment = process.env, eventPayload } = {}) {
|
||||
if (eventName !== "pull_request") {
|
||||
return requiredString(environment.GITHUB_REF_NAME || environment.GITEA_REF_NAME, "Git branch");
|
||||
}
|
||||
|
||||
const direct = String(environment.GITHUB_BASE_REF || environment.GITEA_BASE_REF || "").trim();
|
||||
if (direct) return direct;
|
||||
|
||||
let payload = eventPayload;
|
||||
if (payload === undefined) {
|
||||
const eventPath = String(environment.GITHUB_EVENT_PATH || environment.GITEA_EVENT_PATH || "").trim();
|
||||
if (eventPath) {
|
||||
payload = JSON.parse(fs.readFileSync(eventPath, "utf8"));
|
||||
}
|
||||
}
|
||||
return requiredString(
|
||||
payload?.pull_request?.base?.ref || payload?.pull_request?.base?.repo?.default_branch,
|
||||
"Pull request base branch",
|
||||
);
|
||||
}
|
||||
|
||||
function appendSummary(text) {
|
||||
const summary = process.env.GITHUB_STEP_SUMMARY ?? process.env.GITEA_STEP_SUMMARY;
|
||||
if (summary) fs.appendFileSync(summary, `${text}\n`);
|
||||
@@ -273,10 +294,8 @@ async function main() {
|
||||
}
|
||||
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
||||
const eventName = process.env.GITHUB_EVENT_NAME ?? process.env.GITEA_EVENT_NAME ?? "";
|
||||
const branch = eventName === "pull_request"
|
||||
? process.env.GITHUB_BASE_REF ?? process.env.GITEA_BASE_REF
|
||||
: process.env.GITHUB_REF_NAME ?? process.env.GITEA_REF_NAME;
|
||||
const deployment = selectDeployment(config, requiredString(branch, "Git branch"));
|
||||
const branch = resolveDeploymentBranch({ eventName });
|
||||
const deployment = selectDeployment(config, branch);
|
||||
if (!deployment) {
|
||||
console.log(`No deployment is declared for branch ${branch}.`);
|
||||
return;
|
||||
@@ -351,7 +370,9 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
const invokedPath = process.argv[1] ? fs.realpathSync(process.argv[1]) : "";
|
||||
const modulePath = fs.realpathSync(fileURLToPath(import.meta.url));
|
||||
if (invokedPath === modulePath) {
|
||||
main().catch((error) => {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exitCode = 1;
|
||||
|
||||
Reference in New Issue
Block a user