Refactor macOS DMG creation process in finalize-desktop-artifacts.mjs
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit

- Removed the dynamic search for `create-dmg` and replaced it with a fixed path for improved reliability.
- Updated the buildMacDmg function to handle staging directories more effectively and ensure cleanup after DMG creation.
- Simplified error handling for the DMG creation process, enhancing clarity and maintainability.
This commit is contained in:
Tom Butcher 2026-08-01 22:07:31 +01:00
parent 1b7bb03456
commit ebc3920d65
2 changed files with 43 additions and 45 deletions

3
Jenkinsfile vendored
View File

@ -90,9 +90,6 @@ def prepareMacBuildWorkspace() {
if (isUnix()) { if (isUnix()) {
sh ''' sh '''
df -h . df -h .
if ! command -v create-dmg >/dev/null 2>&1; then
brew install create-dmg
fi
for vol in /Volumes/Farm\\ Control\\ Server*; do for vol in /Volumes/Farm\\ Control\\ Server*; do
if [ -d "$vol" ]; then if [ -d "$vol" ]; then
hdiutil detach "$vol" -force || true hdiutil detach "$vol" -force || true

View File

@ -185,46 +185,14 @@ function cleanStagingArtifacts(keepNames) {
} }
} }
function findCreateDmgCommand() { const CREATE_DMG_PATH = "/usr/local/bin/create-dmg";
const which = spawnSync("which", ["create-dmg"], { encoding: "utf8" });
if (which.status === 0 && which.stdout.trim()) {
return which.stdout.trim();
}
for (const candidate of [
"/opt/homebrew/bin/create-dmg",
"/usr/local/bin/create-dmg",
]) {
if (existsSync(candidate)) {
return candidate;
}
}
return null;
}
function buildMacDmg(appBundlePath, arch) {
const createDmg = findCreateDmgCommand();
if (!createDmg) {
throw new Error(
"create-dmg not found. Install with: brew install create-dmg",
);
}
const dmgPath = path.join(
artifactDir,
getReleaseArtifactName(version, arch, "dmg"),
);
mkdirSync(artifactDir, { recursive: true });
const stagingDir = path.join(
path.dirname(appBundlePath),
".finalize-dmg-staging",
);
rmSync(stagingDir, { recursive: true, force: true });
mkdirSync(stagingDir, { recursive: true });
function buildMacDmgWithCreateDmg(
createDmg,
appBundlePath,
dmgPath,
stagingDir,
) {
const appName = path.basename(appBundlePath); const appName = path.basename(appBundlePath);
symlinkSync(appBundlePath, path.join(stagingDir, appName), "dir"); symlinkSync(appBundlePath, path.join(stagingDir, appName), "dir");
@ -246,8 +214,6 @@ function buildMacDmg(appBundlePath, arch) {
{ stdio: "inherit" }, { stdio: "inherit" },
); );
rmSync(stagingDir, { recursive: true, force: true });
if (result.status !== 0) { if (result.status !== 0) {
throw new Error(`create-dmg failed with exit code ${result.status ?? 1}`); throw new Error(`create-dmg failed with exit code ${result.status ?? 1}`);
} }
@ -256,10 +222,45 @@ function buildMacDmg(appBundlePath, arch) {
throw new Error(`create-dmg did not produce ${dmgPath}`); throw new Error(`create-dmg did not produce ${dmgPath}`);
} }
console.log(`Published ${dmgPath}`);
return dmgPath; return dmgPath;
} }
function buildMacDmg(appBundlePath, arch) {
if (!existsSync(CREATE_DMG_PATH)) {
throw new Error(`create-dmg not found at ${CREATE_DMG_PATH}`);
}
const dmgPath = path.join(
artifactDir,
getReleaseArtifactName(version, arch, "dmg"),
);
mkdirSync(artifactDir, { recursive: true });
const stagingDir = path.join(
path.dirname(appBundlePath),
".finalize-dmg-staging",
);
rmSync(stagingDir, { recursive: true, force: true });
mkdirSync(stagingDir, { recursive: true });
let builtDmgPath;
try {
builtDmgPath = buildMacDmgWithCreateDmg(
CREATE_DMG_PATH,
appBundlePath,
dmgPath,
stagingDir,
);
} finally {
rmSync(stagingDir, { recursive: true, force: true });
}
console.log(`Published ${builtDmgPath}`);
return builtDmgPath;
}
function cleanMacBuildDir(arch) { function cleanMacBuildDir(arch) {
const platformDir = path.join(getBuildRoot(), `stable-macos-${arch}`); const platformDir = path.join(getBuildRoot(), `stable-macos-${arch}`);
if (existsSync(platformDir)) { if (existsSync(platformDir)) {