Skip to content

Commit

Permalink
If the user provides default as the value of the arch input, use …
Browse files Browse the repository at this point in the history
…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 <i.r.butterworth@gmail.com>
  • Loading branch information
DilumAluthge and IanButterworth committed Jul 21, 2024
1 parent a9e17d5 commit 5956f5e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
36 changes: 26 additions & 10 deletions lib/setup-julia.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 25 additions & 10 deletions src/setup-julia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -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)
Expand Down

0 comments on commit 5956f5e

Please sign in to comment.