This commit is contained in:
18
README.md
18
README.md
@@ -150,7 +150,9 @@ Options:
|
||||
|
||||
## GitHub Token Verification
|
||||
|
||||
The project includes a utility to verify the validity of your GitHub token:
|
||||
The project includes a utility to verify the validity of your GitHub token.
|
||||
|
||||
### CLI Utility
|
||||
|
||||
```bash
|
||||
check-github-token <token>
|
||||
@@ -158,6 +160,20 @@ check-github-token <token>
|
||||
|
||||
If no token is provided as an argument, it will attempt to read from the `GITHUB_TOKEN` environment variable.
|
||||
|
||||
### GitHub Action
|
||||
|
||||
You can also use the `check-token` subaction in your workflows:
|
||||
|
||||
```yaml
|
||||
- name: Verify Token
|
||||
uses: koszewscy/setup-github-release/check-token@v1
|
||||
with:
|
||||
repository: 'actions/checkout' # Optional, defaults to actions/checkout
|
||||
token: ${{ secrets.MY_TOKEN }}
|
||||
```
|
||||
|
||||
If the `token` input is not provided, it will read from the `GITHUB_TOKEN` environment variable.
|
||||
|
||||
## Asset Selection Procedure
|
||||
|
||||
The list of assets from the latest release is filtered based on the following rules:
|
||||
|
||||
14
check-token/action.yml
Normal file
14
check-token/action.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
name: 'check-token'
|
||||
description: 'Verify the validity of a GitHub token'
|
||||
author: 'Slawomir Koszewski with GitHub Copilot assistance'
|
||||
inputs:
|
||||
repository:
|
||||
description: 'The GitHub repository to check (e.g., owner/repo)'
|
||||
required: false
|
||||
default: 'actions/checkout'
|
||||
token:
|
||||
description: 'The GitHub token to verify'
|
||||
required: false
|
||||
runs:
|
||||
using: 'node24'
|
||||
main: '../dist/check-token-action.js'
|
||||
69
dist/check-token-action.js
vendored
Normal file
69
dist/check-token-action.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -11,7 +11,8 @@
|
||||
"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: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",
|
||||
"build:check-token-action": "esbuild src/check-token-action.ts --bundle --platform=node --target=node24 --outfile=dist/check-token-action.js --minify",
|
||||
"build": "npm run build:action && npm run build:cli && npm run build:check-token && npm run build:check-token-action",
|
||||
"format": "prettier --write '**/*.ts'",
|
||||
"format-check": "prettier --check '**/*.ts'",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
|
||||
24
src/check-token-action.ts
Normal file
24
src/check-token-action.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import * as core from '@actions/core';
|
||||
import { fetchLatestRelease } from './core/downloader';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const repository = core.getInput('repository') || 'actions/checkout';
|
||||
const token = core.getInput('token') || process.env.GITHUB_TOKEN;
|
||||
|
||||
if (!token) {
|
||||
core.setFailed('No GitHub token provided as an input or found in GITHUB_TOKEN environment variable.');
|
||||
return;
|
||||
}
|
||||
|
||||
core.info(`Verifying GitHub token using repository ${repository}...`);
|
||||
// Attempt to list latest release of the specified repository as a test
|
||||
await fetchLatestRelease(repository, token);
|
||||
|
||||
core.info('Success: The provided GitHub token is valid and has sufficient permissions to access the repository.');
|
||||
} catch (error: any) {
|
||||
core.setFailed(`GitHub token verification failed. Reason: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user