From 6145af66e203f3c8be1a027a141c4bb84e3e868e Mon Sep 17 00:00:00 2001 From: zeshanziya Date: Mon, 3 Jun 2024 10:30:12 +0000 Subject: [PATCH] install platform.sh cli --- src/main.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.ts b/src/main.ts index 1ab395d..62df7b8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,31 @@ import * as core from '@actions/core' +import { exec } from '@actions/exec' /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. */ export async function run(): Promise { + const action = core.getInput('action') + if (!['deploy', 'clean'].includes(action)) { + throw new Error('Invalid action to perform') + } + + core.startGroup('Install Platform.sh cli') + const cliVersion = core.getInput('cli-version') + let cliInstallUrl = + 'curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash' + if (cliVersion !== 'latest') { + // Validate version input to prevent command injection + if (!/^[\d.]+$/.test(cliVersion)) { + throw new Error( + 'Invalid version format. Only numbers and dots are allowed.' + ) + } + cliInstallUrl = `curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | VERSION=${cliVersion} bash` + } + await exec(cliInstallUrl) + core.endGroup() + core.info('Inside custom action') }