Skip to content

Commit 865a380

Browse files
committed
Add repo-token input that defaults to the workflow auto-generated token
1 parent 902859c commit 865a380

File tree

8 files changed

+886
-1440
lines changed

8 files changed

+886
-1440
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Checkout CLI's [config documentation](https://github.com/scaleway/scaleway-cli/b
3939

4040
### Others
4141

42+
- `repo-token`: default to the workflow token (i.e. `GITHUB_TOKEN`), needed to check the latest version of the tool available
4243
- `version`: default to latest, must be exact version. Fetched from exported config if available
4344
- `access-key`
4445
- `secret-key`

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ branding:
44
icon: terminal
55
color: purple
66
inputs:
7+
repo-token:
8+
description: 'The GitHub token, used to check for latest CLI version'
9+
required: false
10+
default: ${{ github.token }}
711
version:
812
description: 'CLI version, will default to latest or exported version'
913
required: false

dist/index.js

Lines changed: 866 additions & 1435 deletions
Large diffs are not rendered by default.

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ const setPermissions = async (filePath: string) => {
7070
}
7171
}
7272

73-
export const install = async (requestedVersion: string) => {
73+
export const install = async (requestedVersion: string, repoToken: string) => {
7474
let version = requestedVersion
7575

7676
if (requestedVersion === VERSION_LATEST) {
77-
version = await getLatest()
77+
version = await getLatest(repoToken)
7878
}
7979

8080
let toolPath = tc.find('scw', version)

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const exportConfig = (args: Args) => {
1212
}
1313

1414
export const importConfig = (): Args => ({
15+
repoToken: '',
1516
defaultOrganizationID: process.env.SCW_DEFAULT_ORGANIZATION_ID ?? '',
1617
defaultProjectID: process.env.SCW_DEFAULT_PROJECT_ID ?? '',
1718
secretKey: process.env.SCW_SECRET_KEY ?? '',

src/input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as tc from '@actions/tool-cache'
33
import { VERSION_LATEST } from './version.js'
44

55
export type Args = {
6+
repoToken: string
67
version: string
78
accessKey: string
89
secretKey: string

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { CLIError, run } from './run.js'
77
import { VERSION_LATEST } from './version.js'
88

99
const getArgs = (defaultArgs: Args): Args => ({
10+
repoToken: core.getInput('repo-token') || defaultArgs.repoToken,
1011
version: core.getInput('version') || defaultArgs.version || VERSION_LATEST,
1112
accessKey: core.getInput('access-key') || defaultArgs.accessKey,
1213
secretKey: core.getInput('secret-key') || defaultArgs.secretKey,
@@ -29,7 +30,7 @@ export const main = async () => {
2930
return
3031
}
3132

32-
const cliPath = await install(args.version)
33+
const cliPath = await install(args.version, args.repoToken)
3334

3435
if (args.args) {
3536
fillEnv(args)

src/version.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ type LatestPayload = {
1010

1111
const latestUrl =
1212
'https://api.github.com/repos/scaleway/scaleway-cli/releases/latest'
13-
export const getLatest = async () => {
13+
export const getLatest = async (repoToken: string) => {
14+
const headers: Record<string, string> = {
15+
Accept: 'application/vnd.github+json',
16+
}
17+
if (repoToken.trim() !== '') {
18+
headers.Authorization = `Bearer ${repoToken}`
19+
}
20+
1421
const httpClient = new HttpClient(USER_AGENT)
15-
const resp = await httpClient.getJson<LatestPayload>(latestUrl)
22+
const resp = await httpClient.getJson<LatestPayload>(latestUrl, headers)
1623

1724
if (resp.statusCode !== 200) {
1825
throw new Error(

0 commit comments

Comments
 (0)