Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Selfhosted runners do not come with the GH CLI out of the box. This action is an easy-to-use way to install it.

As of now, only linux amd64 is supported.
Supports arm64, amd64 and 386 architectures

## Usage

Expand All @@ -11,4 +11,5 @@ As of now, only linux amd64 is supported.
uses: dev-hanz-ops/[email protected]
with:
gh-cli-version: 2.32.0 # optional, see action.yml for current default
gh-cli-architcture: amd64 # optional, see action.yml for current default
```
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inputs:
description: 'Version of the GitHub-CLI that should be installed'
required: false
default: '2.14.2'
gh-cli-arch:
description: 'Target architecture: amd64, arm64, 386'
default: amd64
runs:
using: 'node20'
main: 'dist/index.js'
17 changes: 9 additions & 8 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@ import * as path from 'path';
async function run() {
try {
let version = core.getInput('gh-cli-version');
if (version) {
await getGhCli(version);
let architecture = core.getInput('gh-cli-arch');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Architecture might be auto-determined using process.arch:
https://github.com/arimal199-org/install-gh-cli-action/blob/6f54d5c0fa0de0454b90299b8a143de624d0d737/src/run.js#L30

There is no runner executable for 386, so support for that can be dropped. Instead, process.arch can be checked for arm and arm64.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dev-hanz-ops Tested so far on arm64 and amd64 architectures, sadly I don't have access to armv6 runner , to verify if it works there.

console.log(`Hello ${architecture}!`);
if (version && architecture) {
await getGhCli(version,architecture);
}
} catch (error) {
core.setFailed(error.message);
}
}

async function getGhCli(version) {
async function getGhCli(version,architecture) {
let toolPath = tc.find('gh-cli', version);

if (!toolPath) {
toolPath = await downloadGhCli(version);
toolPath = await downloadGhCli(version,architecture);
}

toolPath = path.join(toolPath, 'bin');
core.addPath(toolPath);
}

async function downloadGhCli(version) {
const toolDirectoryName = `gh_${version}_linux_amd64`;
const downloadUrl = `https://github.com/cli/cli/releases/download/v${version}/gh_${version}_linux_amd64.tar.gz`;
async function downloadGhCli(version,architecture) {
const toolDirectoryName = `gh_${version}_linux_${architecture}`;
const downloadUrl = `https://github.com/cli/cli/releases/download/v${version}/gh_${version}_linux_${architecture}.tar.gz`;
console.log(`downloading ${downloadUrl}`);

try {
Expand All @@ -38,5 +40,4 @@ async function downloadGhCli(version) {
throw err;
}
}

run();