Update action binary

This commit is contained in:
Qiao Han
2022-08-03 22:43:59 +08:00
parent 4359afaaf1
commit 78c4398270
10 changed files with 4866 additions and 352 deletions

View File

@@ -1,16 +1,22 @@
import * as core from '@actions/core'
import {wait} from './wait'
import * as tc from '@actions/tool-cache'
import * as path from 'path'
import {getDownloadObject} from './utils'
async function run(): Promise<void> {
try {
const ms: string = core.getInput('milliseconds')
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true
// Get version of tool to be installed
const version = core.getInput('version')
core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())
// Download the specific version of the tool, e.g. as a tarball/zipball
const download = getDownloadObject(version)
const pathToTarball = await tc.downloadTool(download.url)
core.setOutput('time', new Date().toTimeString())
// Extract the tarball/zipball onto host runner
const pathToCLI = await tc.extractTar(pathToTarball)
// Expose the tool by adding it to the PATH
core.addPath(path.join(pathToCLI, download.binPath))
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}

34
src/utils.ts Normal file
View File

@@ -0,0 +1,34 @@
import os from 'os'
import * as path from 'path'
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
// return value in [amd64, arm64, arm]
const mapArch = (arch: string): string => {
const mappings: Record<string, string> = {
x64: 'amd64'
}
return mappings[arch] || arch
}
// os in [darwin, linux, win32...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osplatform)
// return value in [darwin, linux, windows]
const mapOS = (platform: string): string => {
const mappings: Record<string, string> = {
win32: 'windows'
}
return mappings[platform] || platform
}
export const getDownloadObject = (
version: string
): {url: string; binPath: string} => {
const platform = mapOS(os.platform())
const arch = mapArch(os.arch())
const filename = `supabase_${version}_${platform}_${arch}`
const binPath = platform === 'windows' ? 'bin' : path.join(filename, 'bin')
const url = `https://github.com/supabase/cli/releases/download/v${version}/${filename}.tar.gz`
return {
url,
binPath
}
}

View File

@@ -1,9 +0,0 @@
export async function wait(milliseconds: number): Promise<string> {
return new Promise(resolve => {
if (isNaN(milliseconds)) {
throw new Error('milliseconds not a number')
}
setTimeout(() => resolve('done!'), milliseconds)
})
}