Skip to content

Commit 92a7194

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

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

@@ -63,6 +62,16 @@ Install a binary from a release with multiple binaries available:
6362
EricCrosson/future-tools/flux-capacitor@v1
6463
```
6564

65+
Install a specific binary with checksum validation:
66+
67+
```yaml
68+
- name: Install argocd CLI
69+
uses: EricCrosson/install-github-release-binary@v2
70+
with:
71+
targets: |
72+
argoproj/argo-cd/argocd-linux-amd64@v3.1.4:sha256-7def0aa3cc9ebcd6acdddc27244e7ea4de448d872a9ab0cf6cab4b1e653841a6
73+
```
74+
6675
## Inputs
6776

6877
| Input Parameter | Required | Description |

src/fetch.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,25 @@ 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
}
165+
155166
return {
156167
binaryName: binaryName,
157168
url: asset.url,
@@ -160,16 +171,17 @@ export async function fetchReleaseAssetMetadataFromTag(
160171

161172
// When the binary name is not provided, support two use cases:
162173
// 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).
174+
// 2. There is an asset label or name matching the target triple (with no binary name).
164175
// In both cases, we assume that's the binary the user meant.
165176
// If there is ambiguity, exit with an error.
166177
const matchingTargetTriples = releaseMetadata.data.assets.filter(
167178
(asset) =>
168-
typeof asset.label === "string" && asset.label.endsWith(targetTriple),
179+
(typeof asset.label === "string" && asset.label.endsWith(targetTriple)) ||
180+
(typeof asset.name === "string" && asset.name.endsWith(targetTriple)),
169181
);
170182
if (matchingTargetTriples.length === 0) {
171183
throw new Error(
172-
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label ending in ${targetTriple}`,
184+
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label or name ending in ${targetTriple}`,
173185
);
174186
}
175187
if (matchingTargetTriples.length > 1) {
@@ -180,7 +192,16 @@ To resolve, specify the desired binary with the target format ${slug.owner}/${sl
180192
);
181193
}
182194
const asset = matchingTargetTriples.shift()!;
183-
const targetName = stripTargetTriple(asset.label!);
195+
196+
// Determine binaryName based on whether we matched by label or name
197+
let targetName;
198+
if (typeof asset.label === "string" && asset.label.endsWith(targetTriple)) {
199+
targetName = stripTargetTriple(asset.label);
200+
} else {
201+
// If matched by name, use the full asset name as binary name
202+
targetName = some(asset.name as BinaryName);
203+
}
204+
184205
return {
185206
binaryName: targetName,
186207
url: asset.url,

0 commit comments

Comments
 (0)