Compare commits
2 Commits
120b16b56e
...
2bb60fc0ed
| Author | SHA1 | Date | |
|---|---|---|---|
| 2bb60fc0ed | |||
| fc727877e6 |
10
README.md
10
README.md
@@ -148,6 +148,16 @@ Options:
|
|||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## GitHub Token Verification
|
||||||
|
|
||||||
|
The project includes a utility to verify the validity of your GitHub token:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
check-github-token <token>
|
||||||
|
```
|
||||||
|
|
||||||
|
If no token is provided as an argument, it will attempt to read from the `GITHUB_TOKEN` environment variable.
|
||||||
|
|
||||||
## Asset Selection Procedure
|
## Asset Selection Procedure
|
||||||
|
|
||||||
The list of assets from the latest release is filtered based on the following rules:
|
The list of assets from the latest release is filtered based on the following rules:
|
||||||
|
|||||||
2
dist/check-token.js
vendored
Normal file
2
dist/check-token.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
"use strict";var n=require("util");async function i(t,e){let s=`https://api.github.com/repos/${t}/releases/latest`,r={Accept:"application/vnd.github.v3+json","User-Agent":"setup-github-release-action"};e&&(r.Authorization=`token ${e}`);let o=await fetch(s,{headers:r});if(!o.ok){let a=await o.text();throw new Error(`Failed to fetch latest release for ${t}: ${o.statusText}. ${a}`)}return await o.json()}async function c(){let{positionals:t}=(0,n.parseArgs)({allowPositionals:!0}),e=t[0]||process.env.GITHUB_TOKEN;e||(console.error("Error: No GitHub token provided as an argument or found in GITHUB_TOKEN environment variable."),process.exit(1));try{console.log("Verifying GitHub token..."),await i("actions/checkout",e),console.log("\x1B[32mSuccess: The provided GitHub token is valid and has sufficient permissions to access public repositories.\x1B[0m")}catch(s){console.error("\x1B[31mError: GitHub token verification failed.\x1B[0m"),console.error(`Reason: ${s.message}`),process.exit(1)}}c();
|
||||||
@@ -4,12 +4,14 @@
|
|||||||
"description": "A GitHub Action and CLI tool to download and install binaries from GitHub releases",
|
"description": "A GitHub Action and CLI tool to download and install binaries from GitHub releases",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"install-github-release": "dist/cli.js"
|
"install-github-release": "dist/cli.js",
|
||||||
|
"check-github-token": "dist/check-token.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:action": "esbuild src/index.ts --bundle --platform=node --target=node24 --outfile=dist/index.js --minify",
|
"build:action": "esbuild src/index.ts --bundle --platform=node --target=node24 --outfile=dist/index.js --minify",
|
||||||
"build:cli": "esbuild src/cli.ts --bundle --platform=node --target=node24 --outfile=dist/cli.js --minify --banner:js=\"#!/usr/bin/env node\"",
|
"build:cli": "esbuild src/cli.ts --bundle --platform=node --target=node24 --outfile=dist/cli.js --minify --banner:js=\"#!/usr/bin/env node\"",
|
||||||
"build": "npm run build:action && npm run build:cli",
|
"build:check-token": "esbuild src/check-token.ts --bundle --platform=node --target=node24 --outfile=dist/check-token.js --minify --banner:js=\"#!/usr/bin/env node\"",
|
||||||
|
"build": "npm run build:action && npm run build:cli && npm run build:check-token",
|
||||||
"format": "prettier --write '**/*.ts'",
|
"format": "prettier --write '**/*.ts'",
|
||||||
"format-check": "prettier --check '**/*.ts'",
|
"format-check": "prettier --check '**/*.ts'",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
|
|||||||
29
src/check-token.ts
Normal file
29
src/check-token.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { parseArgs } from 'util';
|
||||||
|
import { fetchLatestRelease } from './core/downloader';
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
const { positionals } = parseArgs({
|
||||||
|
allowPositionals: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const token = positionals[0] || process.env.GITHUB_TOKEN;
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
console.error('Error: No GitHub token provided as an argument or found in GITHUB_TOKEN environment variable.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('Verifying GitHub token...');
|
||||||
|
// Attempt to list latest release of actions/checkout as a test
|
||||||
|
await fetchLatestRelease('actions/checkout', token);
|
||||||
|
|
||||||
|
console.log('\x1b[32mSuccess: The provided GitHub token is valid and has sufficient permissions to access public repositories.\x1b[0m');
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('\x1b[31mError: GitHub token verification failed.\x1b[0m');
|
||||||
|
console.error(`Reason: ${error.message}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
@@ -132,7 +132,7 @@ Options:
|
|||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
fs.chmodSync(destPath, '755');
|
fs.chmodSync(destPath, '755');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user