Skip to content

Commit ebf970d

Browse files
authored
feat: support downloading the latest version automatically (#70)
1 parent 5bbd04f commit ebf970d

File tree

8 files changed

+90
-12
lines changed

8 files changed

+90
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Since Supabase CLI relies on Docker Engine API, additional setup may be required
4444

4545
The actions supports the following inputs:
4646

47-
- `version`: The version of `supabase` to install, defaulting to `1.0.0`
47+
- `version`: The version of `supabase` to install, defaulting to `1.0.0`. You can also specify `latest` to use the latest version.
4848

4949
## Advanced Usage
5050

__tests__/main.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ import * as path from 'path'
66
import {expect, test} from '@jest/globals'
77

88
test('gets download url to binary', async () => {
9-
const url = getDownloadUrl('0.1.0')
9+
const url = await getDownloadUrl('0.1.0')
1010
expect(url).toContain(
1111
'https://github.com/supabase/cli/releases/download/v0.1.0/'
1212
)
1313
})
1414

15+
test('gets download url to binary with "latest" version', async () => {
16+
const url = await getDownloadUrl('latest')
17+
expect(url).toMatch(
18+
/^https:\/\/github.com\/supabase\/cli\/releases\/download\/v[0-9]+\.[0-9]+\.[0-9]+\/supabase_[0-9]+\.[0-9]+\.[0-9]+/
19+
)
20+
})
21+
1522
// shows how the runner will run a javascript action with env / stdout protocol
1623
test('test runs', () => {
1724
process.env['RUNNER_TEMP'] = os.tmpdir()

dist/index.js

Lines changed: 52 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"license": "MIT",
2727
"dependencies": {
2828
"@actions/core": "^1.10.0",
29+
"@actions/http-client": "^2.0.1",
2930
"@actions/tool-cache": "^2.0.1"
3031
},
3132
"devDependencies": {

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function run(): Promise<void> {
88
const version = core.getInput('version')
99

1010
// Download the specific version of the tool, e.g. as a tarball/zipball
11-
const download = getDownloadUrl(version)
11+
const download = await getDownloadUrl(version)
1212
const pathToTarball = await tc.downloadTool(download)
1313

1414
// Extract the tarball/zipball onto host runner

src/utils.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import os from 'os'
2+
import * as httpm from '@actions/http-client'
3+
4+
interface GitHubTag {
5+
tag_name: string
6+
}
27

38
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
49
// return value in [amd64, arm64, arm]
@@ -18,9 +23,26 @@ const mapOS = (platform: string): string => {
1823
return mappings[platform] || platform
1924
}
2025

21-
export const getDownloadUrl = (version: string): string => {
26+
export const getDownloadUrl = async (version: string): Promise<string> => {
2227
const platform = mapOS(os.platform())
2328
const arch = mapArch(os.arch())
24-
const filename = `supabase_${version}_${platform}_${arch}`
25-
return `https://github.com/supabase/cli/releases/download/v${version}/${filename}.tar.gz`
29+
const resolvedVersion = await resolveVersion(version)
30+
const filename = `supabase_${resolvedVersion}_${platform}_${arch}`
31+
32+
return `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}.tar.gz`
33+
}
34+
35+
const resolveVersion = async (version: string): Promise<string> => {
36+
if (version !== 'latest') {
37+
return version
38+
}
39+
40+
const http: httpm.HttpClient = new httpm.HttpClient('setup-cli')
41+
const url = 'https://api.github.com/repos/supabase/cli/releases/latest'
42+
const tag = (await http.getJson<GitHubTag>(url)).result?.tag_name
43+
if (!tag) {
44+
throw new Error('Cannot fetch tag info')
45+
}
46+
47+
return tag.substring(1)
2648
}

0 commit comments

Comments
 (0)