Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# install-github-release-binary

[![Build Status]](https://github.com/EricCrosson/install-github-release-binary/actions/workflows/release.yml)
[![Build Status]](https://github.com/BitGo/install-github-release-binary/actions/workflows/release.yml)

[build status]: https://github.com/EricCrosson/install-github-release-binary/actions/workflows/release.yml/badge.svg?event=push
[build status]: https://github.com/BitGo/install-github-release-binary/actions/workflows/release.yml/badge.svg?event=push

**install-github-release-binary** is an opinionated GitHub Action for adding a binary from a GitHub Release to your CI `$PATH`.

Expand All @@ -18,7 +18,6 @@ This action only supports installing from releases where the release:

- is tagged with the full `{major}.{minor}.{patch}` semantic version
- contains raw binary assets (archives not supported)
- assets are labeled with the binary name and [target triple] in the format `<binary name>-<target triple>`

You can create compatible releases with [semantic-release], using a workflow like [semantic-release-action/rust].

Expand All @@ -32,35 +31,45 @@ Use this action in a step:

```yaml
- name: Install flux-capacitor
uses: EricCrosson/install-github-release-binary@v2
uses: BitGo/install-github-release-binary@v2
with:
targets: EricCrosson/flux-capacitor@v1
targets: BitGo/flux-capacitor@v1
```

> [!NOTE]
> I recommend adding an explicit step name, otherwise the step will only reference
> `EricCrosson/install-github-release-binary@v2`, not your targets.
> `BitGo/install-github-release-binary@v2`, not your targets.

Install multiple binaries:

```yaml
- name: Install future tools
uses: EricCrosson/install-github-release-binary@v2
uses: BitGo/install-github-release-binary@v2
with:
targets: |
EricCrosson/flux-capacitor@v1
EricCrosson/steam-locomotive@v7.5.3
EricCrosson/hoverboard@11.7.3:sha256-8a4600be96d2ec013209042458ce97a9652fcc46c1c855d0217aa42e330fc06e
BitGo/flux-capacitor@v1
BitGo/steam-locomotive@v7.5.3
BitGo/hoverboard@11.7.3:sha256-8a4600be96d2ec013209042458ce97a9652fcc46c1c855d0217aa42e330fc06e
```

Install a binary from a release with multiple binaries available:

```yaml
- name: Install flux-capacitor
uses: EricCrosson/install-github-release-binary@v2
uses: BitGo/install-github-release-binary@v2
with:
targets: |
EricCrosson/future-tools/flux-capacitor@v1
BitGo/future-tools/flux-capacitor@v1
```

Install a specific binary with checksum validation:

```yaml
- name: Install argocd CLI
uses: BitGo/install-github-release-binary@v2
with:
targets: |
argoproj/argo-cd/argocd-linux-amd64@v3.1.4:sha256-7def0aa3cc9ebcd6acdddc27244e7ea4de448d872a9ab0cf6cab4b1e653841a6
```

## Inputs
Expand All @@ -82,11 +91,11 @@ Optionally, include:

Examples:

- `EricCrosson/flux-capacitor@v1`
- `EricCrosson/flux-capacitor@v1.2`
- `EricCrosson/flux-capacitor@v1.2.3`
- `EricCrosson/flux-capacitor@v1.2.3:sha256-ad91159c656d427ad8fe5ded2946f29f3a612c6b7a4af6129e9aa85256b7299e`
- `EricCrosson/future-tools/flux-capacitor@v1`
- `BitGo/flux-capacitor@v1`
- `BitGo/flux-capacitor@v1.2`
- `BitGo/flux-capacitor@v1.2.3`
- `BitGo/flux-capacitor@v1.2.3:sha256-ad91159c656d427ad8fe5ded2946f29f3a612c6b7a4af6129e9aa85256b7299e`
- `BitGo/future-tools/flux-capacitor@v1`

[semantic version number]: https://semver.org/

Expand Down
9 changes: 7 additions & 2 deletions dist/index.js

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

16 changes: 13 additions & 3 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,22 @@ export async function fetchReleaseAssetMetadataFromTag(
// When the binary name is provided, look for matching binary and target triple.
if (isSome(binaryName)) {
const targetLabel = `${binaryName.value}-${targetTriple}`;
const asset = releaseMetadata.data.assets.find(

// First try to find asset by label (original behavior)
let asset = releaseMetadata.data.assets.find(
(asset) => asset.label === targetLabel,
);

// If not found by label, try to find asset by exact name match
if (asset === undefined) {
asset = releaseMetadata.data.assets.find(
(asset) => asset.name === binaryName.value,
);
}

if (asset === undefined) {
throw new Error(
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label ${targetLabel}`,
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label ${targetLabel} or name ${binaryName.value}`,
);
}
return {
Expand All @@ -160,7 +170,7 @@ export async function fetchReleaseAssetMetadataFromTag(

// When the binary name is not provided, support two use cases:
// 1. There is only one binary uploaded to this release, a named binary.
// 2. There is an asset label matching the target triple (with no binary name).
// 2. There is an asset label or name matching the target triple (with no binary name).
// In both cases, we assume that's the binary the user meant.
// If there is ambiguity, exit with an error.
const matchingTargetTriples = releaseMetadata.data.assets.filter(
Expand Down