mirror of
https://github.com/supabase/setup-cli.git
synced 2025-12-08 16:16:25 +00:00
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:
4
.github/workflows/start.yml
vendored
4
.github/workflows/start.yml
vendored
@@ -13,6 +13,9 @@ 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
|
||||
@@ -20,7 +23,6 @@ jobs:
|
||||
matrix:
|
||||
version:
|
||||
- 1.0.0
|
||||
- 1.5.4
|
||||
- latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@@ -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
|
||||
@@ -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: ./
|
||||
|
||||
30
dist/index.js
generated
vendored
30
dist/index.js
generated
vendored
@@ -71,29 +71,6 @@ run();
|
||||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
@@ -109,7 +86,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getDownloadUrl = void 0;
|
||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||
const httpm = __importStar(__nccwpck_require__(6255));
|
||||
const http_client_1 = __nccwpck_require__(6255);
|
||||
const auth_1 = __nccwpck_require__(5526);
|
||||
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
|
||||
// return value in [amd64, arm64, arm]
|
||||
const mapArch = (arch) => {
|
||||
@@ -134,12 +112,14 @@ const getDownloadUrl = (version) => __awaiter(void 0, void 0, void 0, function*
|
||||
return `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}.tar.gz`;
|
||||
});
|
||||
exports.getDownloadUrl = getDownloadUrl;
|
||||
// Authenticate with GH_TOKEN to avoid GitHub API rate limits
|
||||
const token = process.env['GH_TOKEN'];
|
||||
const http = new http_client_1.HttpClient('supabase/setup-cli', token ? [new auth_1.BearerCredentialHandler(token)] : undefined);
|
||||
const resolveVersion = (version) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a;
|
||||
if (version !== 'latest') {
|
||||
return version;
|
||||
}
|
||||
const http = new httpm.HttpClient('setup-cli');
|
||||
const url = 'https://api.github.com/repos/supabase/cli/releases/latest';
|
||||
const tag = (_a = (yield http.getJson(url)).result) === null || _a === void 0 ? void 0 : _a.tag_name;
|
||||
if (!tag) {
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
11
src/utils.ts
11
src/utils.ts
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user