Skip to content

Commit

Permalink
Support alternative syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Jul 10, 2024
1 parent 96cd8fd commit ca29fdd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 26 deletions.
45 changes: 27 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,47 @@ This action will work for any project that satisfies the following conditions:
- The project attaches assets to the GitHub release that contain a Rust target.
The following targets are looked for:

| Node Platform | Targets |
| ------------- | --------------------------------------------------------- |
| `linux` | `x86_64-unknown-linux-musl` or `x86_64-unknown-linux-gnu` |
| `darwin` | `x86_64-apple-darwin` |
| `win32` | `x86_64-pc-windows-msvc` |
| Arch | Node Platform | Targets |
| ------- | ------------- | ----------------------------------------------------------- |
| `x64` | `linux` | `x86_64-unknown-linux-musl` or `x86_64-unknown-linux-gnu` |
| `x64` | `darwin` | `x86_64-apple-darwin` |
| `x64` | `win32` | `x86_64-pc-windows-msvc` |
| `arm64` | `linux` | `aarch64-unknown-linux-musl` or `aarch64-unknown-linux-gnu` |
| `arm64` | `darwin` | `aarch64-apple-darwin` |

- The asset is a `.tar.gz` or `.zip` archive that contains a binary with the
project name.

## Usage

### Examples

In most cases all you will need is to specify the `owner` and the `name` of the
In most cases all you will need is to specify `repo` and the `owner/name` of the
project in your workflow. For example the following installs the latest version
of [mdBook](https://github.com/rust-lang/mdBook).

```yaml
- uses: extractions/setup-crate@v1
with:
owner: rust-lang
name: mdBook
repo: rust-lang/mdBook
```
If you want a specific version you can specify this by passing the `version`
If you want a specific version you can specify this by suffixing version to the
input. For example the following installs the latest `0.10.x` version of
[just](https://github.com/casey/just).

```yaml
- uses: extractions/setup-crate@v1
with:
owner: casey
name: just
version: 0.10
repo: casey/just@0.10
```

### Inputs

| Name | Required | Description | Type | Default |
| -------------- | -------- | ---------------------------------------- | ------ | --------------------------- |
| `owner` | yes | The GitHub user or organization name | string | |
| `name` | yes | The GitHub repository name | string | |
| `version` | no | A valid NPM-style semver specification | string | * |
| `github-token` | no | The GitHub token for making API requests | string | ${{ secrets.GITHUB_TOKEN }} |
| Name | Required | Description | Type | Default |
| -------------- | -------- | ------------------------------------------------------------------- | ------ | --------------------------- |
| `repo` | no | The GitHub repository name and valid NPM-style semver specification | string | |
| `github-token` | no | The GitHub token for making API requests | string | ${{ secrets.GITHUB_TOKEN }} |

The semver specification is passed directly to NPM's [semver
package](https://www.npmjs.com/package/semver). This GitHub Action will install
Expand All @@ -66,6 +64,17 @@ the latest matching release. Examples include
- `version: '0.1.0'` equivalent to `=0.1.0`.
- `version: '^0.1.0'` equivalent to `>=0.1.0 <0.2.0`.

### Deprecated inputs

The following inputs are still supported for now but will be removed in a future
release.

| Name | Required | Description | Type | Default |
| --------- | -------- | -------------------------------------- | ------ | ------- |
| `owner` | no | The GitHub user or organization name | string | |
| `name` | no | The GitHub repository name | string | |
| `version` | no | A valid NPM-style semver specification | string | * |

## License

Licensed under either of
Expand Down
7 changes: 5 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ branding:
icon: 'settings'
color: 'red'
inputs:
repo:
required: false
description: 'The GitHub repository and version specifier containing the crate'
owner:
required: true
required: false
description: 'The GitHub user or organization'
name:
required: true
required: false
description: 'The GitHub repository name'
version:
required: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

37 changes: 32 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
import * as core from "@actions/core";
import * as setup from "@extractions/setup-crate";
import * as core from '@actions/core';
import * as setup from '@extractions/setup-crate';

async function main() {
try {
const owner = core.getInput("owner", { required: true });
const name = core.getInput("name", { required: true });

const repoSpec = core.getInput("repo");
let owner = core.getInput("owner");
let name = core.getInput("name");
const githubToken = core.getInput("github-token");
const versionSpec = core.getInput("version");
let versionSpec = core.getInput("version");

// Repo and owner+name are mutually exclusive
if (repoSpec) {
if (owner || name) {
core.setFailed("When 'repo' is supplied, 'owner' and 'name' must not be provided");
return;
}
} else {
if (!owner || !name) {
core.setFailed("Both 'owner' and 'name' must be supplied when 'repo' is not provided");
return;
}
}

// Parse the repo spec if it was provided
if (repoSpec) {
const [repo, version] = repoSpec.split("@", 2);
if (version && versionSpec) {
core.setFailed("Both 'version' and 'repo' have a version specified, only one is allowed");
return
}
versionSpec = version || versionSpec;
[owner, name] = repo.split("/", 2);
}

const tool = await setup.checkOrInstallTool(
{ owner, name, versionSpec },
{ auth: githubToken },
Expand Down

0 comments on commit ca29fdd

Please sign in to comment.