From f5fa899b3d2f33ff397bbc1d11071d167e9ce058 Mon Sep 17 00:00:00 2001 From: Aaron Tainter Date: Tue, 30 Jul 2024 09:13:10 -0700 Subject: [PATCH] Pull logic into functions and fix issue with url when a specific version is passed --- .github/workflows/main.yml | 2 +- index.js | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e4f73c..9ff7753 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, ubuntu-20.04, macos-latest, macos-11, windows-latest, windows-2019] + os: [ubuntu-latest, ubuntu-20.04, macos-latest, windows-latest, windows-2019] name: Install the cli steps: - name: Checkout diff --git a/index.js b/index.js index e0f1988..d8e4991 100644 --- a/index.js +++ b/index.js @@ -7,19 +7,8 @@ run().catch(error => { async function run() { const version = core.getInput('version'); - const downloadUrlWithVersion = `https://github.com/workos/workos-cli/releases/${version}/download` - - let cliArch; - switch (process.arch) { - case "arm64": - cliArch = "arm64"; - break; - case "x64": - cliArch = "x86_64"; - break; - default: - throw new Error(`Unsupported architecture '${process.arch}'`); - } + const downloadUrlWithVersion = getURLForVersion(version); + const cliArch = getCliArch() switch (process.platform) { case "win32": { @@ -39,6 +28,25 @@ async function run() { } } +function getURLForVersion(version) { + if (version === 'latest') { + return `https://github.com/workos/workos-cli/releases/${version}/download` + } else { + return `https://github.com/workos/workos-cli/releases/download/${version}` + } +} + +function getCliArch() { + switch (process.arch) { + case "arm64": + return "arm64"; + case "x64": + return "x86_64"; + default: + throw new Error(`Unsupported architecture '${process.arch}'`); + } +} + async function installZip(url) { const downloadPath = await tc.downloadTool(url); const pathToCLI = await tc.extractZip(downloadPath);