Compare commits
9 Commits
120b16b56e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 483a1c5f13 | |||
| 90033e0b9e | |||
| f8a559538e | |||
| 09f36edc01 | |||
| 55d6019d0f | |||
| 11a26bd176 | |||
| 32a4011b54 | |||
| 2bb60fc0ed | |||
| fc727877e6 |
@@ -18,6 +18,11 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Check Authentication
|
||||||
|
uses: ./check-token
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GH_TOKEN }}
|
||||||
|
|
||||||
- name: Go ACME Setup
|
- name: Go ACME Setup
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
|||||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -18,6 +18,10 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Let's test the token first.
|
||||||
|
- name: Check Authentication
|
||||||
|
uses: skoszewski/setup-github-release/check-token@v1
|
||||||
|
|
||||||
- name: Go ACME Setup
|
- name: Go ACME Setup
|
||||||
uses: skoszewski/setup-github-release@v1
|
uses: skoszewski/setup-github-release@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
42
README.md
42
README.md
@@ -10,7 +10,7 @@ Add the action to your workflow. Authenticate with `github.token` (default) or a
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install Tool
|
- name: Install Tool
|
||||||
uses: koszewscy/setup-github-release@v1
|
uses: skoszewski/setup-github-release@v1
|
||||||
with:
|
with:
|
||||||
repository: 'owner/repo'
|
repository: 'owner/repo'
|
||||||
```
|
```
|
||||||
@@ -24,7 +24,7 @@ Install the CLI tool on any destination system with Node.js 24 or newer.
|
|||||||
1. Clone the repository:
|
1. Clone the repository:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/koszewscy/setup-github-release
|
git clone https://github.com/skoszewski/setup-github-release
|
||||||
cd setup-github-release
|
cd setup-github-release
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -65,8 +65,8 @@ install-github-release rclone/rclone
|
|||||||
The action will automatically detect your OS (Linux, Windows, macOS) and architecture (x64, ARM64) and look for a matching archive. It will search for a binary named after the repository.
|
The action will automatically detect your OS (Linux, Windows, macOS) and architecture (x64, ARM64) and look for a matching archive. It will search for a binary named after the repository.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install Hugo
|
- name: Install LEGO
|
||||||
uses: koszewscy/setup-github-release@v1
|
uses: skoszewski/setup-github-release@v1
|
||||||
with:
|
with:
|
||||||
repository: 'go-acme/lego'
|
repository: 'go-acme/lego'
|
||||||
```
|
```
|
||||||
@@ -79,7 +79,7 @@ For projects with multiple binary versions, you can use a regex pattern (prefixe
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install Extended Hugo
|
- name: Install Extended Hugo
|
||||||
uses: koszewscy/setup-github-release@v1
|
uses: skoszewski/setup-github-release@v1
|
||||||
with:
|
with:
|
||||||
repository: 'gohugoio/hugo'
|
repository: 'gohugoio/hugo'
|
||||||
file-name: '~hugo_extended_[^a-z]' # Regex to match extended version
|
file-name: '~hugo_extended_[^a-z]' # Regex to match extended version
|
||||||
@@ -91,7 +91,7 @@ If the binary name is different from the repository name, like in the example of
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install GitHub CLI
|
- name: Install GitHub CLI
|
||||||
uses: koszewscy/setup-github-release@v1
|
uses: skoszewski/setup-github-release@v1
|
||||||
with:
|
with:
|
||||||
repository: 'cli/cli'
|
repository: 'cli/cli'
|
||||||
binary-name: 'gh' # Searches for 'gh' (or 'gh.exe') inside the extracted release
|
binary-name: 'gh' # Searches for 'gh' (or 'gh.exe') inside the extracted release
|
||||||
@@ -102,7 +102,7 @@ If the binary name is different from the repository name, like in the example of
|
|||||||
If you are unsure how the binary is named, use the `debug` flag to list all files in the unpacked asset, or download the asset manually to inspect its structure.
|
If you are unsure how the binary is named, use the `debug` flag to list all files in the unpacked asset, or download the asset manually to inspect its structure.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: koszewscy/setup-github-release@v1
|
- uses: skoszewski/setup-github-release@v1
|
||||||
with:
|
with:
|
||||||
repository: 'owner/repo'
|
repository: 'owner/repo'
|
||||||
debug: true
|
debug: true
|
||||||
@@ -148,6 +148,32 @@ 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.
|
||||||
|
|
||||||
|
### CLI Utility
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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: skoszewski/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
|
## 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:
|
||||||
@@ -177,7 +203,7 @@ The list of assets from the latest release is filtered based on the following ru
|
|||||||
8. `{{SYSTEM}}` is replaced with the detected operating system regex:
|
8. `{{SYSTEM}}` is replaced with the detected operating system regex:
|
||||||
|
|
||||||
- For Linux: `linux`.
|
- For Linux: `linux`.
|
||||||
- For MacOS: `(darwin|macos|mac|osx)`.
|
- For MacOS: `(darwin|macos|mac)`.
|
||||||
- For Windows: `(windows|win)`.
|
- For Windows: `(windows|win)`.
|
||||||
|
|
||||||
9. `{{ARCH}}` is replaced with the detected architecture regex:
|
9. `{{ARCH}}` is replaced with the detected architecture regex:
|
||||||
|
|||||||
15
check-token/action.yml
Normal file
15
check-token/action.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
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
|
||||||
|
default: ${{ github.token }}
|
||||||
|
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
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,15 @@
|
|||||||
"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: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": "prettier --write '**/*.ts'",
|
||||||
"format-check": "prettier --check '**/*.ts'",
|
"format-check": "prettier --check '**/*.ts'",
|
||||||
"lint": "eslint src/**/*.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();
|
||||||
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