Skip to content

Commit e44ee39

Browse files
committed
feat: fix fallback with latest or nightly release
1 parent b9dfc50 commit e44ee39

File tree

7 files changed

+89
-25
lines changed

7 files changed

+89
-25
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
test-release:
4343
strategy:
4444
matrix:
45-
os: [ubuntu-latest, windows-latest, macos-latest, macos-14] # macos-14 is an arm machine.
45+
os: [ubuntu-latest, windows-latest, macos-latest, macos-14, ubuntu-24.04-arm] # macos-14 is an arm machine, #ubuntu-24.04-arm should fall back to building from source.
4646
release: [latest, dev-2024-05, nightly]
4747
runs-on: ${{ matrix.os }}
4848
steps:

dist/cache-save/index.js

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

dist/cache-save/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.js

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

dist/setup/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function getInputs() {
4444
if (release && release.length > 0) {
4545
if (release == "false" || release == "False" || release == "FALSE") {
4646
release = "";
47+
} else if (release == "nightly" || release == "latest") {
48+
branch = "master";
4749
} else {
4850
branch = release;
4951
}

src/index.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@ async function run() {
2424

2525
const odinPath = common.odinPath();
2626
core.addPath(odinPath);
27+
if (inputs.release !== "") {
28+
const releaseResult = await downloadRelease(inputs);
29+
if (releaseResult.ok) {
30+
await finalizeRelease(inputs);
31+
core.setOutput('cache-hit', false);
32+
core.saveState('cache-hit', 'false');
33+
return;
34+
}
2735

28-
if (inputs.release !== "" && await downloadRelease(inputs)) {
29-
await finalizeRelease(inputs);
30-
core.setOutput('cache-hit', false);
31-
core.saveState('cache-hit', 'false');
32-
return;
36+
if (releaseResult.fallback === false) {
37+
core.setOutput('cache-hit', false);
38+
core.saveState('cache-hit', 'false');
39+
return;
40+
}
41+
42+
if (typeof releaseResult.fallback === 'string') {
43+
inputs.branch = releaseResult.fallback;
44+
}
3345
}
3446

3547
if (common.cacheCheck(inputs)) {
@@ -235,22 +247,32 @@ async function pullOdinBuildDependencies(inputs) {
235247
/**
236248
* @param inputs {common.Inputs}
237249
*
238-
* @return Promise<bool> Whether to return or fallback to git based install.
250+
* @return Promise<{ok: bool, fallback: bool|string}>
239251
*/
240252
async function downloadRelease(inputs) {
241253
if (inputs.release == 'nightly') {
242-
return downloadNightlyRelease(inputs);
254+
const nightlyOk = await downloadNightlyRelease(inputs);
255+
return {
256+
ok: nightlyOk,
257+
fallback: false,
258+
};
243259
}
244260

245261
const parts = inputs.repository.split('/');
246262
if (parts.length < 2) {
247263
core.setFailed(`Invalid repository ${inputs.repository}.`);
248-
return true;
264+
return {
265+
ok: false,
266+
fallback: false,
267+
};
249268
}
250269

251270
if (inputs.token == "") {
252271
core.warning('Invalid access token, falling back to git based install.');
253-
return false;
272+
return {
273+
ok: false,
274+
fallback: true,
275+
};
254276
}
255277

256278
const octokit = github.getOctokit(inputs.token);
@@ -290,7 +312,10 @@ async function downloadRelease(inputs) {
290312

291313
if (!asset) {
292314
core.warning('could not find release asset to download, falling back to git based install.');
293-
return false;
315+
return {
316+
ok: false,
317+
fallback: release.tag_name,
318+
};
294319
}
295320

296321
core.debug(asset);
@@ -321,7 +346,11 @@ async function downloadRelease(inputs) {
321346

322347
core.debug(download);
323348

324-
return extractDownload(download.url, Buffer.from(download.data));
349+
const extractOk = await extractDownload(download.url, Buffer.from(download.data));
350+
return {
351+
ok: extractOk,
352+
fallback: false,
353+
};
325354
}
326355

327356
/**

0 commit comments

Comments
 (0)