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

Add support for aarch64 #369

Merged
merged 21 commits into from Apr 17, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a6fe908
Add architecture input
xRuiAlves Mar 13, 2023
b1547ee
Add architecture input to download base url
xRuiAlves Mar 13, 2023
8092183
Refactor zip binary extraction to reflect architecture
xRuiAlves Mar 13, 2023
76c5776
Fix linting issues
xRuiAlves Mar 13, 2023
54a1de7
Update generated dist
xRuiAlves Mar 13, 2023
6ad9f82
Add architecture validation to main run function
xRuiAlves Mar 13, 2023
e50ee29
Fix unused parameter in 'isValidArchitecture' function
xRuiAlves Mar 13, 2023
d26ebc9
Update generated dist
xRuiAlves Mar 13, 2023
3e7e9e8
Rename 'arc' to 'archive'
xRuiAlves Mar 13, 2023
0ed2533
Add 'architecture' input variable documentation to README
xRuiAlves Mar 13, 2023
82d6d62
Add 'architecture' input specification to README example with custom …
xRuiAlves Mar 13, 2023
097ab58
Update test workflow with architectures
xRuiAlves Mar 13, 2023
75e363e
Add architecture input to action yml definition
xRuiAlves Mar 13, 2023
bb1def8
Revert "Add 'architecture' input variable documentation to README"
xRuiAlves Mar 13, 2023
9b87586
Revert "Add architecture input to action yml definition"
xRuiAlves Mar 13, 2023
932bcae
Revert "Update test workflow with architectures"
xRuiAlves Mar 13, 2023
3889adb
Revert "Add 'architecture' input specification to README example with…
xRuiAlves Mar 13, 2023
77d4c3c
Compute architecture from process.arch
xRuiAlves Mar 13, 2023
f97bad3
Revert "Update generated dist"
xRuiAlves Mar 13, 2023
60f923f
Revert "Update generated dist"
xRuiAlves Mar 13, 2023
e64d66d
Fix linting issues
xRuiAlves Mar 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/main.ts
Expand Up @@ -4,11 +4,20 @@ import * as os from 'os'
import * as path from 'path'
import * as tc from '@actions/tool-cache'

let csVersion = core.getInput('version')
if (!csVersion) csVersion = '2.1.0-M7-39-gb8f3d7532'
const csVersion = core.getInput('version') || '2.1.0-M7-39-gb8f3d7532'

const coursierVersionSpec = csVersion

function getCoursierArchitecture(): string {
if (process.arch === 'x64') {
return 'x86_64'
} else if (process.arch === 'arm' || process.arch === 'arm64') {
return 'aarch64'
} else {
throw new Error(`Coursier does not have support for the ${process.arch} architecture`)
}
}

async function execOutput(cmd: string, ...args: string[]): Promise<string> {
let output = ''
const options = {
Expand All @@ -23,28 +32,29 @@ async function execOutput(cmd: string, ...args: string[]): Promise<string> {
}

async function downloadCoursier(): Promise<string> {
const baseUrl = `https://github.com/coursier/coursier/releases/download/v${csVersion}/cs-x86_64`
const architecture = getCoursierArchitecture()
const baseUrl = `https://github.com/coursier/coursier/releases/download/v${csVersion}/cs-${architecture}`
let csBinary = ''
switch (process.platform) {
case 'linux': {
const guid = await tc.downloadTool(`${baseUrl}-pc-linux.gz`)
const arc = `${guid}.gz`
await cli.exec('mv', [guid, arc])
csBinary = arc
const archive = `${guid}.gz`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed these arc variables to archive - With the introduction of the new architecture variable, arc could be ambiguous, and the renaming enhances clarity on this.

await cli.exec('mv', [guid, archive])
csBinary = archive
break
}
case 'darwin': {
const guid = await tc.downloadTool(`${baseUrl}-apple-darwin.gz`)
const arc = `${guid}.gz`
await cli.exec('mv', [guid, arc])
csBinary = arc
const archive = `${guid}.gz`
await cli.exec('mv', [guid, archive])
csBinary = archive
break
}
case 'win32': {
const guid = await tc.downloadTool(`${baseUrl}-pc-win32.zip`)
const arc = `${guid}.zip`
await cli.exec('mv', [guid, arc])
csBinary = arc
const archive = `${guid}.zip`
await cli.exec('mv', [guid, archive])
csBinary = archive
break
}
default:
Expand All @@ -57,8 +67,8 @@ async function downloadCoursier(): Promise<string> {
}
if (csBinary.endsWith('.zip')) {
const destDir = csBinary.slice(0, csBinary.length - '.zip'.length)
await cli.exec('unzip', ['-j', csBinary, 'cs-x86_64-pc-win32.exe', '-d', destDir])
csBinary = `${destDir}\\cs-x86_64-pc-win32.exe`
await cli.exec('unzip', ['-j', csBinary, `cs-${architecture}-pc-win32.exe`, '-d', destDir])
csBinary = `${destDir}\\cs-${architecture}-pc-win32.exe`
}
await cli.exec('chmod', ['+x', csBinary])
return csBinary
Expand Down