Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 63 additions & 31 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -53,59 +55,89 @@ 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) {
core.setFailed(error.message);
}
});
}

run();