Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the user provides default as the value of the arch input, use the runner machine's architecture #263

Merged
merged 6 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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