Refactor Jenkinsfile and update build scripts
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
- Introduced a new runBuild function in Jenkinsfile to streamline build command execution across different environments. - Updated package.json to use a new cleanBuild script for improved build cleanup. - Enhanced build-macos.mjs to support architecture-specific builds with better cross-compilation handling. - Added a new clean-build.mjs script for efficient removal of build artifacts.
This commit is contained in:
parent
f21224becc
commit
c14a12648a
26
Jenkinsfile
vendored
26
Jenkinsfile
vendored
@ -36,6 +36,23 @@ def writeBuildMetadata() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def releaseBaseUrl =
|
||||||
|
"https://dist.farmcontrol.app/jenkins/farmcontrol/farmcontrol-server"
|
||||||
|
|
||||||
|
def runBuild(buildCommand) {
|
||||||
|
withEnv([
|
||||||
|
"VITE_BUILD_NUMBER=${env.BUILD_NUMBER ?: 'dev'}",
|
||||||
|
'NODE_ENV=production',
|
||||||
|
"ELECTROBUN_RELEASE_BASE_URL=${releaseBaseUrl}",
|
||||||
|
]) {
|
||||||
|
if (isUnix()) {
|
||||||
|
sh buildCommand
|
||||||
|
} else {
|
||||||
|
bat buildCommand
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def buildLinux() {
|
def buildLinux() {
|
||||||
node('ubuntu') {
|
node('ubuntu') {
|
||||||
try {
|
try {
|
||||||
@ -70,9 +87,6 @@ def buildLinux() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def releaseBaseUrl =
|
|
||||||
"https://dist.farmcontrol.app/jenkins/farmcontrol/farmcontrol-server"
|
|
||||||
|
|
||||||
def buildOnLabel(label, buildCommand) {
|
def buildOnLabel(label, buildCommand) {
|
||||||
return {
|
return {
|
||||||
node(label) {
|
node(label) {
|
||||||
@ -98,11 +112,7 @@ def buildOnLabel(label, buildCommand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage("Build (${label})") {
|
stage("Build (${label})") {
|
||||||
if (isUnix()) {
|
runBuild(buildCommand)
|
||||||
sh "VITE_BUILD_NUMBER=${env.BUILD_NUMBER} NODE_ENV=production ELECTROBUN_RELEASE_BASE_URL=${releaseBaseUrl} ${buildCommand}"
|
|
||||||
} else {
|
|
||||||
bat "set VITE_BUILD_NUMBER=${env.BUILD_NUMBER} && set NODE_ENV=production && set ELECTROBUN_RELEASE_BASE_URL=${releaseBaseUrl} && ${buildCommand}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
"build:linux": "bun run cleanBuild && bun run build:server && bun run build:linux-binary && bun run build:linux-packages",
|
"build:linux": "bun run cleanBuild && bun run build:server && bun run build:linux-binary && bun run build:linux-packages",
|
||||||
"build:linux-binary": "bun scripts/build-linux-binary.mjs",
|
"build:linux-binary": "bun scripts/build-linux-binary.mjs",
|
||||||
"build:linux-packages": "bash scripts/build-linux-packages.sh",
|
"build:linux-packages": "bash scripts/build-linux-packages.sh",
|
||||||
"cleanBuild": "rm -rf build dist"
|
"cleanBuild": "bun scripts/clean-build.mjs"
|
||||||
},
|
},
|
||||||
"author": "Tom Butcher",
|
"author": "Tom Butcher",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const hostArch = process.arch === "arm64" ? "arm64" : "x64";
|
||||||
const targetArchs = ["arm64", "x64"];
|
const targetArchs = ["arm64", "x64"];
|
||||||
|
|
||||||
function run(command, args, options = {}) {
|
function run(command, args, options = {}) {
|
||||||
@ -18,15 +19,39 @@ function run(command, args, options = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getElectrobunInvocation(targetArch) {
|
||||||
|
const electrobunArgs = ["electrobun", "build", "--env=stable"];
|
||||||
|
const env = {
|
||||||
|
...process.env,
|
||||||
|
ELECTROBUN_ARCH: targetArch,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (targetArch === hostArch) {
|
||||||
|
return { command: "bun", args: electrobunArgs, env };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hostArch === "arm64" && targetArch === "x64") {
|
||||||
|
return { command: "arch", args: ["-x86_64", "bun", ...electrobunArgs], env };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hostArch === "x64" && targetArch === "arm64") {
|
||||||
|
return { command: "arch", args: ["-arm64", "bun", ...electrobunArgs], env };
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
run("bun", ["run", "build"]);
|
run("bun", ["run", "build"]);
|
||||||
|
|
||||||
for (const targetArch of targetArchs) {
|
for (const targetArch of targetArchs) {
|
||||||
console.log(`\n=== Building macOS ${targetArch} ===\n`);
|
const invocation = getElectrobunInvocation(targetArch);
|
||||||
|
if (!invocation) {
|
||||||
|
console.warn(
|
||||||
|
`Skipping macOS ${targetArch} build: unsupported cross-compile from ${hostArch}.`,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
run("bun", ["electrobun", "build", "--env=stable"], {
|
console.log(`\n=== Building macOS ${targetArch} ===\n`);
|
||||||
env: {
|
run(invocation.command, invocation.args, { env: invocation.env });
|
||||||
...process.env,
|
|
||||||
ELECTROBUN_ARCH: targetArch,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
9
scripts/clean-build.mjs
Normal file
9
scripts/clean-build.mjs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { rmSync } from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
|
||||||
|
for (const dir of ["build", "dist"]) {
|
||||||
|
rmSync(path.join(rootDir, dir), { recursive: true, force: true });
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user