iop
Version:
Ship Docker Anywhere
45 lines • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateReleaseId = generateReleaseId;
const child_process_1 = require("child_process");
const util_1 = require("util");
const execAsync = (0, util_1.promisify)(child_process_1.exec);
async function generateReleaseId() {
try {
// Check for uncommitted changes first
// Disabling this check for testing
/*
const { stdout: statusOutput } = await execAsync("git status --porcelain");
if (statusOutput.trim() !== "") {
console.error("Error: Uncommitted changes detected in the repository.");
console.error("Please commit or stash your changes before deploying.");
throw new Error("Uncommitted Git changes detected. Halting deployment.");
}
*/
// If clean, proceed to get the SHA
const { stdout: shaStdout } = await execAsync("git rev-parse --short HEAD");
const sha = shaStdout.trim();
if (sha) {
return sha;
}
// This part should ideally not be reached if git rev-parse fails after a clean status, but as a safeguard:
throw new Error("Failed to retrieve Git SHA even though repository is clean.");
}
catch (error) {
if (error instanceof Error) {
if (error.message.startsWith("Uncommitted Git changes")) {
throw error; // Re-throw to halt deployment
}
console.warn("Failed to get Git SHA or check repository status, falling back to timestamp for release ID:", error.message);
}
else {
// Handle non-Error objects thrown
console.warn("An unexpected error type was caught while generating release ID, falling back to timestamp:", error);
}
}
// Fallback to timestamp if Git checks fail for other reasons (e.g., not a git repo)
const timestampId = Date.now().toString();
console.log(`Using timestamp for release ID: ${timestampId}`);
return timestampId;
}
//# sourceMappingURL=release.js.map