Skip to content

Commit

Permalink
Add support for aarch64 (#369)
Browse files Browse the repository at this point in the history
* Add architecture input

* Add architecture input to download base url

* Refactor zip binary extraction to reflect architecture

* Fix linting issues

* Update generated dist

* Add architecture validation to main run function

* Fix unused parameter in 'isValidArchitecture' function

* Update generated dist

* Rename 'arc' to 'archive'

Given that we also have a concept of 'architecture' now,
renaming 'arc' to 'archive' for the sake of clarity.

* Add 'architecture' input variable documentation to README

* Add 'architecture' input specification to README example with custom inputs

* Update test workflow with architectures

* Add architecture input to action yml definition

* Revert "Add 'architecture' input variable documentation to README"

This reverts commit 0ed2533.

* Revert "Add architecture input to action yml definition"

This reverts commit 75e363e.

* Revert "Update test workflow with architectures"

This reverts commit 097ab58.

* Revert "Add 'architecture' input specification to README example with custom inputs"

This reverts commit 82d6d62.

* Compute architecture from process.arch

* Revert "Update generated dist"

This reverts commit d26ebc9.

* Revert "Update generated dist"

This reverts commit 54a1de7.

* Fix linting issues
  • Loading branch information
xRuiAlves committed Apr 17, 2023
1 parent bb4dde1 commit b293fe7
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
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`
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

0 comments on commit b293fe7

Please sign in to comment.