feat: support downloading the latest version automatically (#70)

This commit is contained in:
y-yagi
2022-10-12 01:11:00 +09:00
committed by GitHub
parent 5bbd04f5b6
commit ebf970dfe2
8 changed files with 90 additions and 12 deletions

View File

@@ -8,7 +8,7 @@ async function run(): Promise<void> {
const version = core.getInput('version')
// Download the specific version of the tool, e.g. as a tarball/zipball
const download = getDownloadUrl(version)
const download = await getDownloadUrl(version)
const pathToTarball = await tc.downloadTool(download)
// Extract the tarball/zipball onto host runner

View File

@@ -1,4 +1,9 @@
import os from 'os'
import * as httpm from '@actions/http-client'
interface GitHubTag {
tag_name: string
}
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
// return value in [amd64, arm64, arm]
@@ -18,9 +23,26 @@ const mapOS = (platform: string): string => {
return mappings[platform] || platform
}
export const getDownloadUrl = (version: string): string => {
export const getDownloadUrl = async (version: string): Promise<string> => {
const platform = mapOS(os.platform())
const arch = mapArch(os.arch())
const filename = `supabase_${version}_${platform}_${arch}`
return `https://github.com/supabase/cli/releases/download/v${version}/${filename}.tar.gz`
const resolvedVersion = await resolveVersion(version)
const filename = `supabase_${resolvedVersion}_${platform}_${arch}`
return `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}.tar.gz`
}
const resolveVersion = async (version: string): Promise<string> => {
if (version !== 'latest') {
return version
}
const http: httpm.HttpClient = new httpm.HttpClient('setup-cli')
const url = 'https://api.github.com/repos/supabase/cli/releases/latest'
const tag = (await http.getJson<GitHubTag>(url)).result?.tag_name
if (!tag) {
throw new Error('Cannot fetch tag info')
}
return tag.substring(1)
}