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
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:
parent
1b7bb03456
commit
ebc3920d65
3
Jenkinsfile
vendored
3
Jenkinsfile
vendored
@ -90,9 +90,6 @@ def prepareMacBuildWorkspace() {
|
||||
if (isUnix()) {
|
||||
sh '''
|
||||
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
|
||||
if [ -d "$vol" ]; then
|
||||
hdiutil detach "$vol" -force || true
|
||||
|
||||
@ -185,46 +185,14 @@ function cleanStagingArtifacts(keepNames) {
|
||||
}
|
||||
}
|
||||
|
||||
function findCreateDmgCommand() {
|
||||
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 });
|
||||
const CREATE_DMG_PATH = "/usr/local/bin/create-dmg";
|
||||
|
||||
function buildMacDmgWithCreateDmg(
|
||||
createDmg,
|
||||
appBundlePath,
|
||||
dmgPath,
|
||||
stagingDir,
|
||||
) {
|
||||
const appName = path.basename(appBundlePath);
|
||||
symlinkSync(appBundlePath, path.join(stagingDir, appName), "dir");
|
||||
|
||||
@ -246,8 +214,6 @@ function buildMacDmg(appBundlePath, arch) {
|
||||
{ stdio: "inherit" },
|
||||
);
|
||||
|
||||
rmSync(stagingDir, { recursive: true, force: true });
|
||||
|
||||
if (result.status !== 0) {
|
||||
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}`);
|
||||
}
|
||||
|
||||
console.log(`Published ${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) {
|
||||
const platformDir = path.join(getBuildRoot(), `stable-macos-${arch}`);
|
||||
if (existsSync(platformDir)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user