Skip to content

Commit

Permalink
feat: Add binary-name input
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Sep 21, 2023
1 parent a356059 commit 89ad108
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .idea/auto_sync.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Installs a global `cargo` dependency if it isn't already installed.
- **version**: Version to install, defaults to latest
- **release**: Boolean, set to true to install a release version instead of debug
- **force-version**: Boolean, set to true to force the given version if a different version is installed
- **binary-name**: If the binary name is different from the package name, specify it here (used for version checks)
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ inputs:
name:
required: true
description: Package name
binary-name:
description: Binary name if different from package name
version:
description: Version to install. Defaults to latest
release:
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ const {spawnSync} = require('node:child_process');

try {
const name = getInput('name', {required: true});
const binaryName = getInput('binary-name') || name;
const version = getInput('version');
const release = getBooleanInput('release');
const forceVersion = getBooleanInput('force-version');

const alreadyInstalled = getInstalledVersion(name);
const alreadyInstalled = getInstalledVersion(name, binaryName);

if (alreadyInstalled && (!forceVersion || (version && alreadyInstalled === version))) {
info(`Already installed ${name}@${alreadyInstalled}`);
Expand Down Expand Up @@ -42,14 +43,14 @@ try {
setFailed(e);
}

function getInstalledVersion(pkg) {
function getInstalledVersion(pkg, binaryName) {
let app;
const args = ['--version'];
if (pkg.match(/^cargo-[\w-_]+$/)) {
app = 'cargo';
args.unshift(pkg.slice('cargo-'.length));
} else {
app = pkg;
app = binaryName;
}

const res = spawnSync(app, args, {
Expand Down

0 comments on commit 89ad108

Please sign in to comment.