Skip to content

Commit

Permalink
fix: authenticate action requests to github api (#78)
Browse files Browse the repository at this point in the history
* 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 <qiao@supabase.io>
  • Loading branch information
soedirgo and sweatybridge authored Oct 19, 2022
1 parent babc75a commit b5dccf4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ defaults:
run:
shell: bash

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
e2e: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
strategy:
matrix:
version:
- 1.0.0
- 1.5.4
- latest
steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ defaults:
run:
shell: bash

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
Expand All @@ -21,7 +24,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
version: [1.0.0, 1.5.4, latest]
version: [1.0.0, latest]
steps:
- uses: actions/checkout@v3
- uses: ./
Expand Down
30 changes: 5 additions & 25 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b5dccf4

Please sign in to comment.