fix: authenticate action requests to github api (#78)

* fix: only test on latest

Should help with GitHub API rate limiting

* Update .github/workflows/test.yml

* fix: add github token to workflow

* fix: authenticate with github api

* chore: remove token env

* chore: update dist files

* Revert "chore: remove token env"

This reverts commit 913c7a8e6f.

* chore: use gh token env var

* chore: update user agent string

* chore: organize imports

Co-authored-by: Han Qiao <qiao@supabase.io>
This commit is contained in:
Bobbie Soedirgo
2022-10-19 16:36:59 +08:00
committed by GitHub
parent babc75a12d
commit b5dccf414b
5 changed files with 22 additions and 30 deletions

View File

@@ -1,5 +1,6 @@
import os from 'os'
import * as httpm from '@actions/http-client'
import {HttpClient} from '@actions/http-client'
import {BearerCredentialHandler} from '@actions/http-client/lib/auth'
interface GitHubTag {
tag_name: string
@@ -32,12 +33,18 @@ export const getDownloadUrl = async (version: string): Promise<string> => {
return `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}.tar.gz`
}
// Authenticate with GH_TOKEN to avoid GitHub API rate limits
const token = process.env['GH_TOKEN']
const http = new HttpClient(
'supabase/setup-cli',
token ? [new BearerCredentialHandler(token)] : undefined
)
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) {