From 077498e320c9f87e0cc48a6b002d3733f6f50edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dezs=C5=91=20BICZ=C3=93?= Date: Mon, 22 Sep 2025 11:01:33 +0200 Subject: [PATCH] Reduce billing costs --- lib/main.js | 94 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6fb2e41..1a470d1 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,3 +1,4 @@ + "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; @@ -31,6 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(require("@actions/core")); const child_process_1 = require("child_process"); const path = __importStar(require("path")); + /** * Executes a shell command and return it as a Promise. */ @@ -53,54 +55,83 @@ function execShellCommand(cmd) { }); }); } + +function execBatchCommands(commands, description = "batch commands") { + return new Promise((resolve, reject) => { + console.log(`Executing ${description}:`); + commands.forEach(cmd => console.log(cmd)); + + const batchCmd = commands.join(' && '); + const process = child_process_1.spawn('bash', ['-c', batchCmd]); + + let stdout = ""; + process.stdout.on('data', (data) => { + const output = data.toString(); + console.log(output); + stdout += output; + }); + + process.stderr.on('data', (data) => { + console.error(data.toString()); + }); + + process.on('exit', (code) => { + if (code !== 0) { + reject(new Error(`${description} failed with exit code: ${code}`)); + } + resolve(stdout); + }); + }); +} + function run() { return __awaiter(this, void 0, void 0, function* () { try { const ddevDir = core.getInput('ddevDir') || '.'; const autostart = core.getBooleanInput('autostart'); - yield execShellCommand('echo \'dir: ' + __dirname + '\''); - let cmd = 'sudo install -m 0755 -d /etc/apt/keyrings'; - console.log(cmd); - yield execShellCommand(cmd); - cmd = 'curl -fsSL https://pkg.ddev.com/apt/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/ddev.gpg > /dev/null'; - console.log(cmd); - yield execShellCommand(cmd); - cmd = 'sudo chmod a+r /etc/apt/keyrings/ddev.gpg'; - console.log(cmd); - yield execShellCommand(cmd); - cmd = 'echo "deb [signed-by=/etc/apt/keyrings/ddev.gpg] https://pkg.ddev.com/apt/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list >/dev/null'; - console.log(cmd); - yield execShellCommand(cmd); const version = core.getInput('version') || 'latest'; + + yield execShellCommand('echo \'dir: ' + __dirname + '\''); + + // Prepare version-specific package name let ddevPackage = 'ddev'; if (version !== 'latest') { ddevPackage += `=${version}`; } - cmd = `(sudo apt-get update || true) && sudo apt-get install -y ${ddevPackage} && mkcert -install`; - console.log(cmd); - yield execShellCommand(cmd); + const setupCommands = [ + 'sudo install -m 0755 -d /etc/apt/keyrings', + 'curl -fsSL https://pkg.ddev.com/apt/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/ddev.gpg > /dev/null', + 'sudo chmod a+r /etc/apt/keyrings/ddev.gpg', + 'echo "deb [signed-by=/etc/apt/keyrings/ddev.gpg] https://pkg.ddev.com/apt/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list >/dev/null', + `(sudo apt-get update || true) && sudo apt-get install -y ${ddevPackage} && mkcert -install` + ]; + + yield execBatchCommands(setupCommands, "DDEV repository setup and installation"); + // Handle version hold separately to maintain error isolation if (version !== 'latest') { - cmd = 'sudo apt-mark hold ddev'; - console.log(cmd); - yield execShellCommand(cmd); + const holdCmd = 'sudo apt-mark hold ddev'; + console.log(holdCmd); + yield execShellCommand(holdCmd); } - cmd = 'ddev --version'; - console.log(cmd); - yield execShellCommand(cmd); - cmd = 'ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent'; - console.log(cmd); - yield execShellCommand(cmd); - if(autostart){ - if (ddevDir != '.') { - cmd = 'cd ' + ddevDir + ' && ddev start'; + const configCommands = [ + 'ddev --version', + 'ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent' + ]; + + yield execBatchCommands(configCommands, "DDEV version check and configuration"); + + if (autostart) { + let startCmd; + if (ddevDir !== '.') { + startCmd = 'cd ' + ddevDir + ' && ddev start'; } else { - cmd = 'ddev start'; + startCmd = 'ddev start'; } - console.log(cmd); - yield execShellCommand(cmd); + console.log(startCmd); + yield execShellCommand(startCmd); } } catch (error) { @@ -108,4 +139,5 @@ function run() { } }); } + run();