diff --git a/dist/index.js b/dist/index.js index 4ca99f5..2c4311a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,7 @@ import { getInput, info, setFailed, setOutput, warning } from '@actions/core'; import getGithubRelease from './utils/getGithubRelease.js'; import install from './utils/install.js'; -const exit = (error, miscTestBuilds) => { +export const exit = (error, miscTestBuilds) => { if (miscTestBuilds) { warning(error); } @@ -21,7 +21,7 @@ const main = async () => { if ((release === null || release === void 0 ? void 0 : release.message) === 'Not Found') return exit('Invalid bun version.', miscTestBuilds); info(`Going to install release ${release.version}`); - await install(release); + await install(release, miscTestBuilds); setOutput('bun-version', release.tag_name); } catch (e) { diff --git a/dist/utils/getAsset.js b/dist/utils/getAsset.js index 73872e1..e466142 100644 --- a/dist/utils/getAsset.js +++ b/dist/utils/getAsset.js @@ -1,4 +1,5 @@ -export default (assets) => { +import { exit } from '../index.js'; +export default (assets, miscTestBuilds) => { let arch; switch (process.arch) { case 'arm64': @@ -12,6 +13,12 @@ export default (assets) => { } if (!['linux', 'darwin'].some(platform => process.platform === 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 { name: `bun-${process.platform}-${arch}`, asset: assets.find(asset => asset.name === `bun-${process.platform}-${arch}.zip`), diff --git a/dist/utils/install.js b/dist/utils/install.js index 101f775..6ae7675 100644 --- a/dist/utils/install.js +++ b/dist/utils/install.js @@ -4,8 +4,8 @@ import { addPath, info } from '@actions/core'; import getAsset from './getAsset.js'; import { join } from 'path'; import { homedir } from 'os'; -export default async (release) => { - const asset = getAsset(release.assets); +export default async (release, miscTestBuilds) => { + const asset = getAsset(release.assets, miscTestBuilds); const path = join(homedir(), '.bun', 'bin', asset.name); const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`); if (cache) { diff --git a/src/index.ts b/src/index.ts index 3927f37..ebe9e6f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import { getInput, info, setFailed, setOutput, warning } from '@actions/core'; import getGithubRelease from './utils/getGithubRelease.js'; import install from './utils/install.js'; -const exit = (error: string, miscTestBuilds?: boolean) => { +export const exit = (error: string, miscTestBuilds?: boolean) => { if (miscTestBuilds) { warning(error); } else { @@ -24,7 +24,7 @@ const main = async() => { info(`Going to install release ${release.version}`); - await install(release); + await install(release, miscTestBuilds); setOutput('bun-version', release.tag_name); } catch(e) { diff --git a/src/utils/getAsset.ts b/src/utils/getAsset.ts index 5a2415a..52654a3 100644 --- a/src/utils/getAsset.ts +++ b/src/utils/getAsset.ts @@ -1,6 +1,7 @@ +import { exit } from '../index.js'; import { Asset } from './getGithubRelease.js'; -export default (assets: Asset[]) => { +export default (assets: Asset[], miscTestBuilds: boolean) => { let arch; switch (process.arch) { case 'arm64': @@ -16,6 +17,14 @@ export default (assets: Asset[]) => { if (!['linux', 'darwin'].some(platform => process.platform === 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 { name: `bun-${process.platform}-${arch}`, asset: assets.find(asset => asset.name === `bun-${process.platform}-${arch}.zip`), diff --git a/src/utils/install.ts b/src/utils/install.ts index 54f29ab..09f83dc 100644 --- a/src/utils/install.ts +++ b/src/utils/install.ts @@ -6,8 +6,8 @@ import getAsset from './getAsset.js'; import { join } from 'path'; import { homedir } from 'os'; -export default async(release: Release) => { - const asset = getAsset(release.assets); +export default async(release: Release, miscTestBuilds: boolean) => { + const asset = getAsset(release.assets, miscTestBuilds); const path = join(homedir(), '.bun', 'bin', asset.name); const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`); if (cache) {