Skip to content

Commit 7d3f81c

Browse files
committed
feat: use GitHub token for release resolution
Add optional token input and fallback to GITHUB_TOKEN so release lookups are authenticated, reducing rate-limit failures in GitHub Actions. Made-with: Cursor
1 parent 844670f commit 7d3f81c

7 files changed

Lines changed: 52 additions & 40 deletions

File tree

.github/workflows/bruin.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
steps:
1515
- name: Setup repo
1616
uses: actions/checkout@v4
17-
# Installs latest
1817
- uses: bruin-data/bruin-setup-action@main
1918
- run: bruin init default
2019
- run: bruin validate ./bruin-pipeline/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ You can configure `setup-bruin` with these parameters:
2727
| Parameter | Description | Default |
2828
|:---------------|:---------------------------------------------------|:-------------------|
2929
| `version` | The version of the [`bruin`](https://github.com/bruin-data/bruin) to install | [`latest`](https://github.com/bruin-data/bruin/releases) |
30+
| `token` | GitHub token for API requests (avoids rate limits). When omitted, the workflow `GITHUB_TOKEN` is used automatically. | `GITHUB_TOKEN` (in Actions) |
3031

3132
> These parameters are derived from [`action.yml`](./action.yml). <br>
3233
#### Version

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ inputs:
99
description: The version of bruin to set up.
1010
required: false
1111
default: 'latest'
12+
token:
13+
description: >
14+
GitHub token for API requests (e.g. to list releases and resolve download URLs).
15+
Defaults to the workflow GITHUB_TOKEN when not set. Use this to avoid API rate limits.
16+
required: false
17+
default: ''
1218
runs:
1319
using: "node20"
1420
main: "./dist/main.js"

dist/main.js

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

dist/main.js.map

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

src/bruin.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { HttpsProxyAgent } from "https-proxy-agent";
88

99
export async function getBruin(
1010
version: string,
11+
token?: string,
1112
): Promise<string | Error> {
1213
const binaryPath = tc.find("bruin", version, os.arch());
1314
if (binaryPath !== "") {
@@ -16,7 +17,7 @@ export async function getBruin(
1617
}
1718

1819
core.info(`Resolving the download URL for the current platform...`);
19-
const downloadURL = await getDownloadURL(version);
20+
const downloadURL = await getDownloadURL(version, token);
2021

2122
if (isError(downloadURL)) {
2223
return downloadURL;
@@ -72,7 +73,8 @@ export async function getBruin(
7273
// getDownloadURL resolves Bruin's Github download URL for the
7374
// current architecture and platform.
7475
async function getDownloadURL(
75-
version: string
76+
version: string,
77+
token?: string,
7678
): Promise<string | Error> {
7779
let architecture = "";
7880
switch (os.arch()) {
@@ -123,6 +125,7 @@ async function getDownloadURL(
123125
? new HttpsProxyAgent(process.env.http_proxy)
124126
: undefined;
125127
const octokit = new Octokit({
128+
auth: token,
126129
request: {
127130
agent: requestAgent,
128131
},

src/run.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ export async function runSetup(): Promise<null | Error> {
3535
};
3636
}
3737

38+
// Use token input or fall back to GITHUB_TOKEN (provided automatically in Actions)
39+
const token = core.getInput("token") || process.env.GITHUB_TOKEN || undefined;
40+
3841
core.info(`Setting up bruin version "${version}"`);
39-
const installDir = await getBruin(version);
42+
const installDir = await getBruin(version, token);
4043
if (isError(installDir)) {
4144
return installDir;
4245
}

0 commit comments

Comments
 (0)