Skip to content

Commit

Permalink
Support ARM (#44)
Browse files Browse the repository at this point in the history
* Support ARM

* Remove log statement
  • Loading branch information
kyleconroy authored Sep 6, 2023
1 parent b22e99c commit 5f6aee7
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 62 deletions.
74 changes: 45 additions & 29 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

82 changes: 50 additions & 32 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,69 @@
import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'

function downloadUrl(version: string): string {
let plat = ''
let arch = ''

switch (process.platform) {
case 'win32': {
plat = 'windows'
break
}
case 'darwin': {
plat = 'darwin'
break
}
case 'linux': {
plat = 'linux'
break
}
default: {
core.setFailed(`Unsupported platform: ${process.platform}`)
return ''
}
}

switch (process.arch) {
case 'x64': {
arch = 'amd64'
break
}
case 'arm64': {
arch = 'arm64'
break
}
default: {
core.setFailed(`Unsupported architecture: ${process.arch}`)
return ''
}
}

return `https://downloads.sqlc.dev/sqlc_${version}_${plat}_${arch}.zip`
}

async function run(): Promise<void> {
try {
const version = core.getInput('sqlc-version')
if (!version) {
core.setFailed(`sqlc-version not set`)
return
}
const toolDir = tc.find('sqlc', version, 'x64')
const toolDir = tc.find('sqlc', version, process.arch)
if (toolDir !== '') {
core.addPath(toolDir)
return
}

switch (process.platform) {
case 'win32': {
const toolUrl = `https://downloads.sqlc.dev/sqlc_${version}_windows_amd64.zip`
const downloadPath = await tc.downloadTool(toolUrl)
const extPath = await tc.extractZip(downloadPath)
const cachedPath = await tc.cacheDir(extPath, 'sqlc', version)
core.addPath(cachedPath)
break
}

case 'darwin': {
const toolUrl = `https://downloads.sqlc.dev/sqlc_${version}_darwin_amd64.zip`
const downloadPath = await tc.downloadTool(toolUrl)
const extPath = await tc.extractZip(downloadPath)
const cachedPath = await tc.cacheDir(extPath, 'sqlc', version)
core.addPath(cachedPath)
break
}

case 'linux': {
const toolUrl = `https://downloads.sqlc.dev/sqlc_${version}_linux_amd64.zip`
const downloadPath = await tc.downloadTool(toolUrl)
const extPath = await tc.extractZip(downloadPath)
const cachedPath = await tc.cacheDir(extPath, 'sqlc', version)
core.addPath(cachedPath)
break
}

default: {
core.setFailed(`Unsupported platform: ${process.platform}`)
}
const toolUrl = downloadUrl(version)
if (toolUrl === '') {
return
}

const downloadPath = await tc.downloadTool(toolUrl)
const extPath = await tc.extractZip(downloadPath)
const cachedPath = await tc.cacheDir(extPath, 'sqlc', version)
core.addPath(cachedPath)
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
Expand Down

0 comments on commit 5f6aee7

Please sign in to comment.