diff --git a/action.yml b/action.yml index d735dcc8..69b6c10c 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,7 @@ name: 'Setup Julia environment' description: 'Setup a Julia environment and add it to the PATH' author: 'Sascha Mann' -inputs: +inputs: version: description: 'The Julia version to download (if necessary) and use. Example: 1.0.4' default: '1' @@ -12,7 +12,7 @@ inputs: arch: description: 'Architecture of the Julia binaries. Defaults to the architecture of the runner executing the job.' required: false - default: '${{ runner.arch }}' + default: 'default' show-versioninfo: description: 'Display InteractiveUtils.versioninfo() after installing' required: false diff --git a/lib/setup-julia.js b/lib/setup-julia.js index 2b967b3b..8ce63236 100644 --- a/lib/setup-julia.js +++ b/lib/setup-julia.js @@ -36,15 +36,17 @@ const core = __importStar(require("@actions/core")); const tc = __importStar(require("@actions/tool-cache")); const fs = __importStar(require("fs")); const https = __importStar(require("https")); +const os = __importStar(require("os")); const path = __importStar(require("path")); const installer = __importStar(require("./installer")); +// Note: before we index into this dict, we always first do `.toLowerCase()` on +// the key. +// +// Therefore, this dict does not need to account for differences in case. const archSynonyms = { 'x86': 'x86', - 'X86': 'x86', 'x64': 'x64', - 'X64': 'x64', 'aarch64': 'aarch64', - 'ARM64': 'aarch64', 'arm64': 'aarch64' }; function run() { @@ -65,22 +67,36 @@ function run() { core.debug(`ERROR: Could not retrieve runner IP: ${err}`); }); } - // Inputs - const versionInput = core.getInput('version'); - const includePrereleases = core.getInput('include-all-prereleases') == 'true'; - const originalArchInput = core.getInput('arch'); + // Inputs. + // Note that we intentionally strip leading and lagging whitespace by using `.trim()` + const versionInput = core.getInput('version').trim(); + const includePrereleases = core.getInput('include-all-prereleases').trim() == 'true'; + const originalArchInput = core.getInput('arch').trim(); // It can easily happen that, for example, a workflow file contains an input `version: ${{ matrix.julia-version }}` // while the strategy matrix only contains a key `${{ matrix.version }}`. // In that case, we want the action to fail, rather than trying to download julia from an URL that's missing parts and 404ing. // We _could_ fall back to the default but that means that builds silently do things differently than they're meant to, which // is worse than failing the build. - if (!versionInput) { + if (!versionInput) { // if `versionInput` is an empty string throw new Error('Version input must not be null'); } - if (!originalArchInput) { + if (!originalArchInput) { // if `originalArchInput` is an empty string throw new Error(`Arch input must not be null`); } - const arch = archSynonyms[originalArchInput]; + let processedArchInput; + if (originalArchInput == "default") { + // If the user sets the `arch` input to `default`, then we use the + // architecture of the machine that we are running on. + processedArchInput = os.arch(); + core.debug(`The "arch" input is "default", so we will use the machine arch: ${processedArchInput}`); + } + else { + processedArchInput = originalArchInput; + } + // Note: we convert the key `processedArchInput` to lower case + // before we index into the `archSynonyms` dict. + const arch = archSynonyms[processedArchInput.toLowerCase()]; + core.debug(`Mapped the "arch" from ${processedArchInput} to ${arch}`); const versionInfo = yield installer.getJuliaVersionInfo(); const availableReleases = yield installer.getJuliaVersions(versionInfo); const version = installer.getJuliaVersion(availableReleases, versionInput, includePrereleases); diff --git a/src/setup-julia.ts b/src/setup-julia.ts index bc64feda..2e072ee3 100644 --- a/src/setup-julia.ts +++ b/src/setup-julia.ts @@ -3,17 +3,19 @@ import * as tc from '@actions/tool-cache' import * as fs from 'fs' import * as https from 'https' +import * as os from 'os' import * as path from 'path' import * as installer from './installer' +// Note: before we index into this dict, we always first do `.toLowerCase()` on +// the key. +// +// Therefore, this dict does not need to account for differences in case. const archSynonyms = { 'x86': 'x86', - 'X86': 'x86', 'x64': 'x64', - 'X64': 'x64', 'aarch64': 'aarch64', - 'ARM64': 'aarch64', 'arm64': 'aarch64' } @@ -37,24 +39,37 @@ async function run() { }) } - // Inputs - const versionInput = core.getInput('version') - const includePrereleases = core.getInput('include-all-prereleases') == 'true' - const originalArchInput = core.getInput('arch') + // Inputs. + // Note that we intentionally strip leading and lagging whitespace by using `.trim()` + const versionInput = core.getInput('version').trim() + const includePrereleases = core.getInput('include-all-prereleases').trim() == 'true' + const originalArchInput = core.getInput('arch').trim() // It can easily happen that, for example, a workflow file contains an input `version: ${{ matrix.julia-version }}` // while the strategy matrix only contains a key `${{ matrix.version }}`. // In that case, we want the action to fail, rather than trying to download julia from an URL that's missing parts and 404ing. // We _could_ fall back to the default but that means that builds silently do things differently than they're meant to, which // is worse than failing the build. - if (!versionInput) { + if (!versionInput) { // if `versionInput` is an empty string throw new Error('Version input must not be null') } - if (!originalArchInput) { + if (!originalArchInput) { // if `originalArchInput` is an empty string throw new Error(`Arch input must not be null`) } - const arch = archSynonyms[originalArchInput] + let processedArchInput: string; + if (originalArchInput == "default") { + // If the user sets the `arch` input to `default`, then we use the + // architecture of the machine that we are running on. + processedArchInput = os.arch(); + core.debug(`The "arch" input is "default", so we will use the machine arch: ${processedArchInput}`) + } else { + processedArchInput = originalArchInput; + } + // Note: we convert the key `processedArchInput` to lower case + // before we index into the `archSynonyms` dict. + const arch = archSynonyms[processedArchInput.toLowerCase()] + core.debug(`Mapped the "arch" from ${processedArchInput} to ${arch}`) const versionInfo = await installer.getJuliaVersionInfo() const availableReleases = await installer.getJuliaVersions(versionInfo)