Skip to content

Commit 05f3873

Browse files
committed
feat: support finding binary using file path
TICKET: VL-4112
1 parent c038e23 commit 05f3873

File tree

5 files changed

+126
-34
lines changed

5 files changed

+126
-34
lines changed

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# install-github-release-binary
22

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

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

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

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

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

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

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

3332
```yaml
3433
- name: Install flux-capacitor
35-
uses: EricCrosson/install-github-release-binary@v2
34+
uses: BitGo/install-github-release-binary@v2
3635
with:
37-
targets: EricCrosson/flux-capacitor@v1
36+
targets: BitGo/flux-capacitor@v1
3837
```
3938
4039
> [!NOTE]
4140
> I recommend adding an explicit step name, otherwise the step will only reference
42-
> `EricCrosson/install-github-release-binary@v2`, not your targets.
41+
> `BitGo/install-github-release-binary@v2`, not your targets.
4342

4443
Install multiple binaries:
4544

4645
```yaml
4746
- name: Install future tools
48-
uses: EricCrosson/install-github-release-binary@v2
47+
uses: BitGo/install-github-release-binary@v2
4948
with:
5049
targets: |
51-
EricCrosson/flux-capacitor@v1
52-
EricCrosson/steam-locomotive@v7.5.3
53-
EricCrosson/hoverboard@11.7.3:sha256-8a4600be96d2ec013209042458ce97a9652fcc46c1c855d0217aa42e330fc06e
50+
BitGo/flux-capacitor@v1
51+
BitGo/steam-locomotive@v7.5.3
52+
BitGo/hoverboard@11.7.3:sha256-8a4600be96d2ec013209042458ce97a9652fcc46c1c855d0217aa42e330fc06e
5453
```
5554

5655
Install a binary from a release with multiple binaries available:
5756

5857
```yaml
5958
- name: Install flux-capacitor
60-
uses: EricCrosson/install-github-release-binary@v2
59+
uses: BitGo/install-github-release-binary@v2
6160
with:
6261
targets: |
63-
EricCrosson/future-tools/flux-capacitor@v1
62+
BitGo/future-tools/flux-capacitor@v1
63+
```
64+
65+
Install a specific binary with checksum validation:
66+
67+
```yaml
68+
- name: Install argocd CLI
69+
uses: BitGo/install-github-release-binary@v2
70+
with:
71+
targets: |
72+
argoproj/argo-cd/argocd-linux-amd64@v3.1.4:sha256-7def0aa3cc9ebcd6acdddc27244e7ea4de448d872a9ab0cf6cab4b1e653841a6
6473
```
6574

6675
## Inputs
@@ -82,11 +91,11 @@ Optionally, include:
8291

8392
Examples:
8493

85-
- `EricCrosson/flux-capacitor@v1`
86-
- `EricCrosson/flux-capacitor@v1.2`
87-
- `EricCrosson/flux-capacitor@v1.2.3`
88-
- `EricCrosson/flux-capacitor@v1.2.3:sha256-ad91159c656d427ad8fe5ded2946f29f3a612c6b7a4af6129e9aa85256b7299e`
89-
- `EricCrosson/future-tools/flux-capacitor@v1`
94+
- `BitGo/flux-capacitor@v1`
95+
- `BitGo/flux-capacitor@v1.2`
96+
- `BitGo/flux-capacitor@v1.2.3`
97+
- `BitGo/flux-capacitor@v1.2.3:sha256-ad91159c656d427ad8fe5ded2946f29f3a612c6b7a4af6129e9aa85256b7299e`
98+
- `BitGo/future-tools/flux-capacitor@v1`
9099

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

dist/index.js

Lines changed: 31 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fetch.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,22 @@ export async function fetchReleaseAssetMetadataFromTag(
144144
// When the binary name is provided, look for matching binary and target triple.
145145
if (isSome(binaryName)) {
146146
const targetLabel = `${binaryName.value}-${targetTriple}`;
147-
const asset = releaseMetadata.data.assets.find(
147+
148+
// First try to find asset by label (original behavior)
149+
let asset = releaseMetadata.data.assets.find(
148150
(asset) => asset.label === targetLabel,
149151
);
152+
153+
// If not found by label, try to find asset by exact name match
154+
if (asset === undefined) {
155+
asset = releaseMetadata.data.assets.find(
156+
(asset) => asset.name === binaryName.value,
157+
);
158+
}
159+
150160
if (asset === undefined) {
151161
throw new Error(
152-
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label ${targetLabel}`,
162+
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label ${targetLabel} or name ${binaryName.value}`,
153163
);
154164
}
155165
return {
@@ -160,7 +170,7 @@ export async function fetchReleaseAssetMetadataFromTag(
160170

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

src/platform.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ const ALL_TARGET_TRIPLES: readonly TargetTriple[] = [
88
"x86_64-unknown-linux-musl",
99
] as unknown as readonly TargetTriple[];
1010

11+
// Go-style mappings for the supported target triples
12+
// Format: {os}-{arch} or {os}_{arch}
13+
const GO_STYLE_TRIPLES: Record<string, string[]> = {
14+
// Maps Go-style platform identifiers to their corresponding architecture
15+
"darwin-arm64": ["aarch64-apple-darwin"],
16+
"darwin_arm64": ["aarch64-apple-darwin"],
17+
"linux-arm64": ["aarch64-unknown-linux-musl"],
18+
"linux_arm64": ["aarch64-unknown-linux-musl"],
19+
"darwin-amd64": ["x86_64-apple-darwin"],
20+
"darwin_amd64": ["x86_64-apple-darwin"],
21+
"linux-amd64": ["x86_64-unknown-linux-musl"],
22+
"linux_amd64": ["x86_64-unknown-linux-musl"],
23+
};
24+
1125
function architectureLabel(arch: string): string {
1226
switch (arch) {
1327
case "arm64":
@@ -54,16 +68,30 @@ export function getTargetTriple(
5468
}
5569

5670
/**
57-
* String the string of its target triple suffix
71+
* Strip the string of its target triple suffix
5872
*/
5973
export function stripTargetTriple(value: string): Option<string> {
60-
// Can't strip away the target tuple if nothing else remains
74+
// Can't strip away the target triple if nothing else remains
6175
if (ALL_TARGET_TRIPLES.find((targetTriple) => targetTriple === value)) {
6276
return none();
6377
}
64-
const stripped = ALL_TARGET_TRIPLES.reduce(
65-
(value, targetTriple) => value.replace(new RegExp(`-${targetTriple}$`), ""),
66-
value,
67-
);
68-
return some(stripped);
78+
79+
// First try to strip standard target triples
80+
for (const targetTriple of ALL_TARGET_TRIPLES) {
81+
const pattern = new RegExp(`-${targetTriple}$`);
82+
if (value.match(pattern)) {
83+
return some(value.replace(pattern, ""));
84+
}
85+
}
86+
87+
// Then check for Go-style triples
88+
for (const goTriple of Object.keys(GO_STYLE_TRIPLES)) {
89+
const pattern = new RegExp(`-(${goTriple})$`);
90+
if (value.match(pattern)) {
91+
return some(value.replace(pattern, ""));
92+
}
93+
}
94+
95+
// If no triple was found, return the original value
96+
return some(value);
6997
}

test/test-strip-target-triple.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,24 @@ test(
3535
"should strip a target triple into none",
3636
check("x86_64-unknown-linux-musl", none()),
3737
);
38+
39+
// Tests for Go-style binary name stripping
40+
test(
41+
"should strip linux-amd64",
42+
check("argocd-linux-amd64", some("argocd")),
43+
);
44+
45+
test(
46+
"should strip linux_amd64",
47+
check("argocd-linux_amd64", some("argocd")),
48+
);
49+
50+
test(
51+
"should strip darwin-arm64",
52+
check("argocd-darwin-arm64", some("argocd")),
53+
);
54+
55+
test(
56+
"should strip darwin_arm64",
57+
check("argocd-darwin_arm64", some("argocd")),
58+
);

0 commit comments

Comments
 (0)