Skip to content

Commit 5956f5e

Browse files
If the user provides default as the value of the arch input, use the runner machine's architecture (#263)
* If the user provides `default` as the value of the `arch` input, use the runner machine's architecture * `npm run build` * Convert the key `processedArchInput` to lower case before indexing into the `archSynonyms` dict * `npm run build` --------- Co-authored-by: Ian Butterworth <[email protected]>
1 parent a9e17d5 commit 5956f5e

File tree

3 files changed

+53
-22
lines changed

3 files changed

+53
-22
lines changed

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Setup Julia environment'
22
description: 'Setup a Julia environment and add it to the PATH'
33
author: 'Sascha Mann'
4-
inputs:
4+
inputs:
55
version:
66
description: 'The Julia version to download (if necessary) and use. Example: 1.0.4'
77
default: '1'
@@ -12,7 +12,7 @@ inputs:
1212
arch:
1313
description: 'Architecture of the Julia binaries. Defaults to the architecture of the runner executing the job.'
1414
required: false
15-
default: '${{ runner.arch }}'
15+
default: 'default'
1616
show-versioninfo:
1717
description: 'Display InteractiveUtils.versioninfo() after installing'
1818
required: false

lib/setup-julia.js

+26-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-julia.ts

+25-10
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import * as tc from '@actions/tool-cache'
33

44
import * as fs from 'fs'
55
import * as https from 'https'
6+
import * as os from 'os'
67
import * as path from 'path'
78

89
import * as installer from './installer'
910

11+
// Note: before we index into this dict, we always first do `.toLowerCase()` on
12+
// the key.
13+
//
14+
// Therefore, this dict does not need to account for differences in case.
1015
const archSynonyms = {
1116
'x86': 'x86',
12-
'X86': 'x86',
1317
'x64': 'x64',
14-
'X64': 'x64',
1518
'aarch64': 'aarch64',
16-
'ARM64': 'aarch64',
1719
'arm64': 'aarch64'
1820
}
1921

@@ -37,24 +39,37 @@ async function run() {
3739
})
3840
}
3941

40-
// Inputs
41-
const versionInput = core.getInput('version')
42-
const includePrereleases = core.getInput('include-all-prereleases') == 'true'
43-
const originalArchInput = core.getInput('arch')
42+
// Inputs.
43+
// Note that we intentionally strip leading and lagging whitespace by using `.trim()`
44+
const versionInput = core.getInput('version').trim()
45+
const includePrereleases = core.getInput('include-all-prereleases').trim() == 'true'
46+
const originalArchInput = core.getInput('arch').trim()
4447

4548
// It can easily happen that, for example, a workflow file contains an input `version: ${{ matrix.julia-version }}`
4649
// while the strategy matrix only contains a key `${{ matrix.version }}`.
4750
// In that case, we want the action to fail, rather than trying to download julia from an URL that's missing parts and 404ing.
4851
// We _could_ fall back to the default but that means that builds silently do things differently than they're meant to, which
4952
// is worse than failing the build.
50-
if (!versionInput) {
53+
if (!versionInput) { // if `versionInput` is an empty string
5154
throw new Error('Version input must not be null')
5255
}
53-
if (!originalArchInput) {
56+
if (!originalArchInput) { // if `originalArchInput` is an empty string
5457
throw new Error(`Arch input must not be null`)
5558
}
5659

57-
const arch = archSynonyms[originalArchInput]
60+
let processedArchInput: string;
61+
if (originalArchInput == "default") {
62+
// If the user sets the `arch` input to `default`, then we use the
63+
// architecture of the machine that we are running on.
64+
processedArchInput = os.arch();
65+
core.debug(`The "arch" input is "default", so we will use the machine arch: ${processedArchInput}`)
66+
} else {
67+
processedArchInput = originalArchInput;
68+
}
69+
// Note: we convert the key `processedArchInput` to lower case
70+
// before we index into the `archSynonyms` dict.
71+
const arch = archSynonyms[processedArchInput.toLowerCase()]
72+
core.debug(`Mapped the "arch" from ${processedArchInput} to ${arch}`)
5873

5974
const versionInfo = await installer.getJuliaVersionInfo()
6075
const availableReleases = await installer.getJuliaVersions(versionInfo)

0 commit comments

Comments
 (0)