Update build-healthcheck.js

This script is designed to manage the platform-specific build process for a health check tool, particularly for Linux on the armv7 architecture. It handles renaming pre-built healthcheck files, removing outdated versions, and performing a Go-based build when necessary.
This commit is contained in:
Tushar Kumar 2024-10-24 21:35:26 +05:30 committed by GitHub
parent 79a26180af
commit 1067908154
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,27 +1,62 @@
const childProcess = require("child_process");
const fs = require("fs");
const path = require("path");
const platform = process.argv[2];
const healthcheckPath = "./extra/healthcheck";
const healthcheckArmPath = "./extra/healthcheck-armv7";
const healthcheckGoFile = "./extra/healthcheck.go";
if (!platform) {
console.error("No platform??");
console.error("Error: No platform specified.");
process.exit(1);
}
if (platform === "linux/arm/v7") {
console.log("Arch: armv7");
if (fs.existsSync("./extra/healthcheck-armv7")) {
fs.renameSync("./extra/healthcheck-armv7", "./extra/healthcheck");
console.log("Already built in the host, skip.");
process.exit(0);
} else {
console.log("prebuilt not found, it will be slow! You should execute `npm run build-healthcheck-armv7` before build.");
}
} else {
if (fs.existsSync("./extra/healthcheck-armv7")) {
fs.rmSync("./extra/healthcheck-armv7");
function renamePrebuiltHealthcheck() {
try {
fs.renameSync(healthcheckArmPath, healthcheckPath);
console.log("Prebuilt healthcheck for armv7 renamed successfully.");
} catch (error) {
console.error("Error renaming prebuilt healthcheck:", error.message);
process.exit(1);
}
}
const output = childProcess.execSync("go build -x -o ./extra/healthcheck ./extra/healthcheck.go").toString("utf8");
console.log(output);
function removeArmHealthcheck() {
if (fs.existsSync(healthcheckArmPath)) {
try {
fs.rmSync(healthcheckArmPath);
console.log("Old armv7 healthcheck removed.");
} catch (error) {
console.error("Error removing armv7 healthcheck:", error.message);
}
}
}
function buildHealthcheck() {
try {
const output = childProcess.execSync(`go build -x -o ${healthcheckPath} ${healthcheckGoFile}`).toString("utf8");
console.log("Build output:\n", output);
} catch (error) {
console.error("Error during build process:", error.message);
process.exit(1);
}
}
if (platform === "linux/arm/v7") {
console.log("Architecture: armv7");
if (fs.existsSync(healthcheckArmPath)) {
renamePrebuiltHealthcheck();
console.log("Already built in the host, skipping build.");
process.exit(0);
} else {
console.log("Prebuilt healthcheck not found. The build might be slow.");
console.log("Recommendation: Run `npm run build-healthcheck-armv7` before building.");
}
} else {
removeArmHealthcheck();
}
// Build the healthcheck
buildHealthcheck();