Skip to content

Commit b5dccf4

Browse files
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 913c7a8. * chore: use gh token env var * chore: update user agent string * chore: organize imports Co-authored-by: Han Qiao <[email protected]>
1 parent babc75a commit b5dccf4

File tree

5 files changed

+22
-30
lines changed

5 files changed

+22
-30
lines changed

.github/workflows/start.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ defaults:
1313
run:
1414
shell: bash
1515

16+
env:
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
1619
jobs:
1720
e2e: # make sure the action works on a clean machine without building
1821
runs-on: ubuntu-latest
1922
strategy:
2023
matrix:
2124
version:
2225
- 1.0.0
23-
- 1.5.4
2426
- latest
2527
steps:
2628
- uses: actions/checkout@v3

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ defaults:
99
run:
1010
shell: bash
1111

12+
env:
13+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
1215
jobs:
1316
build: # make sure build/ci work properly
1417
runs-on: ubuntu-latest
@@ -21,7 +24,7 @@ jobs:
2124
strategy:
2225
matrix:
2326
os: [macos-latest, windows-latest, ubuntu-latest]
24-
version: [1.0.0, 1.5.4, latest]
27+
version: [1.0.0, latest]
2528
steps:
2629
- uses: actions/checkout@v3
2730
- uses: ./

dist/index.js

Lines changed: 5 additions & 25 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.

src/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os from 'os'
2-
import * as httpm from '@actions/http-client'
2+
import {HttpClient} from '@actions/http-client'
3+
import {BearerCredentialHandler} from '@actions/http-client/lib/auth'
34

45
interface GitHubTag {
56
tag_name: string
@@ -32,12 +33,18 @@ export const getDownloadUrl = async (version: string): Promise<string> => {
3233
return `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}.tar.gz`
3334
}
3435

36+
// Authenticate with GH_TOKEN to avoid GitHub API rate limits
37+
const token = process.env['GH_TOKEN']
38+
const http = new HttpClient(
39+
'supabase/setup-cli',
40+
token ? [new BearerCredentialHandler(token)] : undefined
41+
)
42+
3543
const resolveVersion = async (version: string): Promise<string> => {
3644
if (version !== 'latest') {
3745
return version
3846
}
3947

40-
const http: httpm.HttpClient = new httpm.HttpClient('setup-cli')
4148
const url = 'https://api.github.com/repos/supabase/cli/releases/latest'
4249
const tag = (await http.getJson<GitHubTag>(url)).result?.tag_name
4350
if (!tag) {

0 commit comments

Comments
 (0)