Skip to content

Commit 1f44683

Browse files
committed
feat: support finding binary using file path
TICKET: VL-4112
1 parent a760676 commit 1f44683

File tree

2 files changed

+84
-23
lines changed

2 files changed

+84
-23
lines changed

dist/index.js

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

src/fetch.ts

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { Octokit } from "./octokit";
22
import { isEqual, isSome, none, Option, some } from "./option";
33
import { stripTargetTriple } from "./platform";
4-
import type { TargetDuple } from "./types";
54

65
import {
76
isExactSemanticVersion,
87
ExactSemanticVersion,
98
RepositorySlug,
109
SemanticVersion,
1110
Sha1Hash,
11+
TargetDuple,
1212
TargetTriple,
1313
BinaryName,
1414
} from "./types";
@@ -148,15 +148,27 @@ export async function fetchReleaseAssetMetadataFromTag(
148148
const targetLabelTraditional = `${binaryName.value}-${targetTriple}`;
149149
const targetLabelDuple = `${binaryName.value}-${targetDuple}`;
150150

151-
const asset = releaseMetadata.data.assets.find(
152-
(asset) =>
153-
typeof asset.label === "string" &&
154-
(asset.label === targetLabelTraditional || asset.label === targetLabelDuple),
155-
);
151+
const asset = releaseMetadata.data.assets.find((asset) => {
152+
// Check for label match
153+
if (typeof asset.label === "string") {
154+
if (asset.label === targetLabelTraditional || asset.label === targetLabelDuple) {
155+
return true;
156+
}
157+
}
158+
159+
// Check for name match
160+
if (typeof asset.name === "string") {
161+
if (asset.name === targetLabelTraditional || asset.name === targetLabelDuple) {
162+
return true;
163+
}
164+
}
165+
166+
return false;
167+
});
156168

157169
if (asset === undefined) {
158170
throw new Error(
159-
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label ${targetLabelTraditional} or ${targetLabelDuple}`,
171+
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label or name ${targetLabelTraditional} or ${targetLabelDuple}`,
160172
);
161173
}
162174

@@ -171,14 +183,27 @@ export async function fetchReleaseAssetMetadataFromTag(
171183
// 2. There is an asset label matching the target triple or target duple.
172184
// In both cases, we assume that's the binary the user meant.
173185
// If there is ambiguity, exit with an error.
174-
const matchingAssets = releaseMetadata.data.assets.filter(
175-
(asset) =>
176-
typeof asset.label === "string" &&
177-
(asset.label.endsWith(targetTriple) || asset.label.endsWith(targetDuple)),
178-
);
186+
const matchingAssets = releaseMetadata.data.assets.filter((asset) => {
187+
// Check label match
188+
if (typeof asset.label === "string") {
189+
if (asset.label.endsWith(targetTriple) || asset.label.endsWith(targetDuple)) {
190+
return true;
191+
}
192+
}
193+
194+
// Check name match
195+
if (typeof asset.name === "string") {
196+
if (asset.name.endsWith(targetTriple) || asset.name.endsWith(targetDuple)) {
197+
return true;
198+
}
199+
}
200+
201+
return false;
202+
});
203+
179204
if (matchingAssets.length === 0) {
180205
throw new Error(
181-
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label ending in ${targetTriple} or ${targetDuple}`,
206+
`Expected to find asset in release ${slug.owner}/${slug.repository}@${tag} with label or name ending in ${targetTriple} or ${targetDuple}`,
182207
);
183208
}
184209
if (matchingAssets.length > 1) {
@@ -189,7 +214,17 @@ To resolve, specify the desired binary with the target format ${slug.owner}/${sl
189214
);
190215
}
191216
const asset = matchingAssets.shift()!;
192-
const targetName = stripTargetTriple(asset.label!);
217+
218+
// Determine which field matched to use for stripping the target triple
219+
let matchField: string;
220+
if (typeof asset.label === "string" &&
221+
(asset.label.endsWith(targetTriple) || asset.label.endsWith(targetDuple))) {
222+
matchField = asset.label;
223+
} else {
224+
matchField = asset.name!;
225+
}
226+
227+
const targetName = stripTargetTriple(matchField);
193228
return {
194229
binaryName: targetName,
195230
url: asset.url,

0 commit comments

Comments
 (0)