fix: dont error when invalid asset for miscTestBuilds

This commit is contained in:
xHyroM 2022-07-12 19:53:24 +02:00
parent 4e76ddea17
commit 633e7abe1e
6 changed files with 26 additions and 10 deletions

4
dist/index.js vendored
View File

@ -1,7 +1,7 @@
import { getInput, info, setFailed, setOutput, warning } from '@actions/core'; import { getInput, info, setFailed, setOutput, warning } from '@actions/core';
import getGithubRelease from './utils/getGithubRelease.js'; import getGithubRelease from './utils/getGithubRelease.js';
import install from './utils/install.js'; import install from './utils/install.js';
const exit = (error, miscTestBuilds) => { export const exit = (error, miscTestBuilds) => {
if (miscTestBuilds) { if (miscTestBuilds) {
warning(error); warning(error);
} }
@ -21,7 +21,7 @@ const main = async () => {
if ((release === null || release === void 0 ? void 0 : release.message) === 'Not Found') if ((release === null || release === void 0 ? void 0 : release.message) === 'Not Found')
return exit('Invalid bun version.', miscTestBuilds); return exit('Invalid bun version.', miscTestBuilds);
info(`Going to install release ${release.version}`); info(`Going to install release ${release.version}`);
await install(release); await install(release, miscTestBuilds);
setOutput('bun-version', release.tag_name); setOutput('bun-version', release.tag_name);
} }
catch (e) { catch (e) {

View File

@ -1,4 +1,5 @@
export default (assets) => { import { exit } from '../index.js';
export default (assets, miscTestBuilds) => {
let arch; let arch;
switch (process.arch) { switch (process.arch) {
case 'arm64': case 'arm64':
@ -12,6 +13,12 @@ export default (assets) => {
} }
if (!['linux', 'darwin'].some(platform => process.platform === platform)) if (!['linux', 'darwin'].some(platform => process.platform === platform))
throw new Error(`Unsupported platform ${process.platform}.`); throw new Error(`Unsupported platform ${process.platform}.`);
const assetName = `bun-${process.platform}-${arch}.zip`;
const asset = assets.find(asset => asset.name === assetName);
if (!asset) {
exit(`Invalid asset ${assetName}`, miscTestBuilds);
process.exit();
}
return { return {
name: `bun-${process.platform}-${arch}`, name: `bun-${process.platform}-${arch}`,
asset: assets.find(asset => asset.name === `bun-${process.platform}-${arch}.zip`), asset: assets.find(asset => asset.name === `bun-${process.platform}-${arch}.zip`),

View File

@ -4,8 +4,8 @@ import { addPath, info } from '@actions/core';
import getAsset from './getAsset.js'; import getAsset from './getAsset.js';
import { join } from 'path'; import { join } from 'path';
import { homedir } from 'os'; import { homedir } from 'os';
export default async (release) => { export default async (release, miscTestBuilds) => {
const asset = getAsset(release.assets); const asset = getAsset(release.assets, miscTestBuilds);
const path = join(homedir(), '.bun', 'bin', asset.name); const path = join(homedir(), '.bun', 'bin', asset.name);
const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`); const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`);
if (cache) { if (cache) {

View File

@ -2,7 +2,7 @@ import { getInput, info, setFailed, setOutput, warning } from '@actions/core';
import getGithubRelease from './utils/getGithubRelease.js'; import getGithubRelease from './utils/getGithubRelease.js';
import install from './utils/install.js'; import install from './utils/install.js';
const exit = (error: string, miscTestBuilds?: boolean) => { export const exit = (error: string, miscTestBuilds?: boolean) => {
if (miscTestBuilds) { if (miscTestBuilds) {
warning(error); warning(error);
} else { } else {
@ -24,7 +24,7 @@ const main = async() => {
info(`Going to install release ${release.version}`); info(`Going to install release ${release.version}`);
await install(release); await install(release, miscTestBuilds);
setOutput('bun-version', release.tag_name); setOutput('bun-version', release.tag_name);
} catch(e) { } catch(e) {

View File

@ -1,6 +1,7 @@
import { exit } from '../index.js';
import { Asset } from './getGithubRelease.js'; import { Asset } from './getGithubRelease.js';
export default (assets: Asset[]) => { export default (assets: Asset[], miscTestBuilds: boolean) => {
let arch; let arch;
switch (process.arch) { switch (process.arch) {
case 'arm64': case 'arm64':
@ -16,6 +17,14 @@ export default (assets: Asset[]) => {
if (!['linux', 'darwin'].some(platform => process.platform === platform)) if (!['linux', 'darwin'].some(platform => process.platform === platform))
throw new Error(`Unsupported platform ${process.platform}.`); throw new Error(`Unsupported platform ${process.platform}.`);
const assetName = `bun-${process.platform}-${arch}.zip`;
const asset = assets.find(asset => asset.name === assetName);
if (!asset) {
exit(`Invalid asset ${assetName}`, miscTestBuilds);
process.exit();
}
return { return {
name: `bun-${process.platform}-${arch}`, name: `bun-${process.platform}-${arch}`,
asset: assets.find(asset => asset.name === `bun-${process.platform}-${arch}.zip`), asset: assets.find(asset => asset.name === `bun-${process.platform}-${arch}.zip`),

View File

@ -6,8 +6,8 @@ import getAsset from './getAsset.js';
import { join } from 'path'; import { join } from 'path';
import { homedir } from 'os'; import { homedir } from 'os';
export default async(release: Release) => { export default async(release: Release, miscTestBuilds: boolean) => {
const asset = getAsset(release.assets); const asset = getAsset(release.assets, miscTestBuilds);
const path = join(homedir(), '.bun', 'bin', asset.name); const path = join(homedir(), '.bun', 'bin', asset.name);
const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`); const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`);
if (cache) { if (cache) {