mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-02-23 18:50:10 +08:00
feat: custom download url, custom repository
This commit is contained in:
parent
27a94d6f80
commit
e6a8865f72
54
.github/workflows/test.yml
vendored
54
.github/workflows/test.yml
vendored
@ -15,8 +15,6 @@ jobs:
|
|||||||
os: [ubuntu-latest, macos-latest]
|
os: [ubuntu-latest, macos-latest]
|
||||||
bun-version:
|
bun-version:
|
||||||
["latest", "0.1.4"]
|
["latest", "0.1.4"]
|
||||||
misc-test-builds:
|
|
||||||
[false]
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -26,20 +24,17 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
bun-version: ${{ matrix.bun-version }}
|
bun-version: ${{ matrix.bun-version }}
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
misc-test-builds: ${{ matrix.misc-test-builds }}
|
|
||||||
|
|
||||||
- name: Try bun
|
- name: Try bun
|
||||||
run: |
|
run: |
|
||||||
bun --version
|
bun --version
|
||||||
test-canary:
|
test-version-canary:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-latest]
|
||||||
bun-version:
|
bun-version:
|
||||||
["canary"]
|
["canary"]
|
||||||
misc-test-builds:
|
|
||||||
[false]
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -49,7 +44,52 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
bun-version: ${{ matrix.bun-version }}
|
bun-version: ${{ matrix.bun-version }}
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
misc-test-builds: ${{ matrix.misc-test-builds }}
|
|
||||||
|
- name: Try bun
|
||||||
|
run: |
|
||||||
|
bun --version
|
||||||
|
test-custom-download-url:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
bun-version:
|
||||||
|
["latest"]
|
||||||
|
custom-download-url:
|
||||||
|
["https://github.com/oven-sh/bun/suites/7555351912/artifacts/311939881"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Bun - Test Builds * ${{ matrix.misc-test-builds }}
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
bun-version: ${{ matrix.bun-version }}
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
custom-download-url: ${{ matrix.custom-download-url }}
|
||||||
|
|
||||||
|
- name: Try bun
|
||||||
|
run: |
|
||||||
|
bun --version
|
||||||
|
test-custom-repository:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
bun-version:
|
||||||
|
["latest"]
|
||||||
|
repository:
|
||||||
|
["https://github.com/oven-sh/misc-test-builds"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Bun - Test Builds * ${{ matrix.misc-test-builds }}
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
bun-version: ${{ matrix.bun-version }}
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
repository: ${{ matrix.repository }}
|
||||||
|
|
||||||
- name: Try bun
|
- name: Try bun
|
||||||
run: |
|
run: |
|
||||||
|
18
README.md
18
README.md
@ -31,3 +31,21 @@ Set up your GitHub Actions workflow with a specific version of Bun.
|
|||||||
bun-version: canary
|
bun-version: canary
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Custom repository
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: xhyrom/setup-bun@v0.1.6
|
||||||
|
with:
|
||||||
|
repository: https://github.com/oven-sh/misc-test-builds
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom download url
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: xhyrom/setup-bun@v0.1.6
|
||||||
|
with:
|
||||||
|
custom-download-url: https://github.com/oven-sh/bun/suites/7555351912/artifacts/311939881
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
```
|
11
action.yml
11
action.yml
@ -10,11 +10,20 @@ inputs:
|
|||||||
bun-version:
|
bun-version:
|
||||||
description: "The Bun version to install."
|
description: "The Bun version to install."
|
||||||
default: "latest"
|
default: "latest"
|
||||||
|
required: false
|
||||||
github-token:
|
github-token:
|
||||||
description: "The github token secret can be passed in using {{ secrets.GITHUB_TOKEN }}"
|
description: "The github token secret can be passed in using {{ secrets.GITHUB_TOKEN }}"
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
|
required: false
|
||||||
misc-test-builds:
|
misc-test-builds:
|
||||||
description: "Install builds from https://github.com/oven-sh/misc-test-builds (not recommended!)"
|
description: "Deprecated, use repository input instead. Install builds from https://github.com/oven-sh/misc-test-builds (not recommended!)"
|
||||||
|
required: false
|
||||||
|
repository:
|
||||||
|
description: "Repository from which the bun is downloaded. Defaults to https://github.com/oven-sh/bun"
|
||||||
|
default: "https://github.com/oven-sh/bun"
|
||||||
|
required: false
|
||||||
|
custom-download-url:
|
||||||
|
description: "Full url to download bun, for example if you want to download an artifact."
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -14,10 +14,12 @@ const main = async () => {
|
|||||||
try {
|
try {
|
||||||
const version = getInput('bun-version');
|
const version = getInput('bun-version');
|
||||||
const token = getInput('github-token');
|
const token = getInput('github-token');
|
||||||
const miscTestBuilds = (getInput('misc-test-builds') === 'true');
|
const repository = getInput('repository');
|
||||||
|
const miscTestBuilds = (getInput('misc-test-builds') === 'true') || (repository.includes('oven-sh/misc-test-builds'));
|
||||||
|
const customDownloadUrl = getInput('custom-download-url') || null;
|
||||||
if (!version)
|
if (!version)
|
||||||
return exit('Invalid bun version.');
|
return exit('Invalid bun version.');
|
||||||
const release = await getGithubRelease(version, token, miscTestBuilds);
|
const release = await getGithubRelease(version, token, repository, customDownloadUrl, miscTestBuilds);
|
||||||
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}`);
|
||||||
|
6
dist/utils/getAsset.js
vendored
6
dist/utils/getAsset.js
vendored
@ -1,5 +1,5 @@
|
|||||||
import { exit } from '../index.js';
|
import { exit } from '../index.js';
|
||||||
export default (assets) => {
|
export const getArchitecture = () => {
|
||||||
let arch;
|
let arch;
|
||||||
switch (process.arch) {
|
switch (process.arch) {
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
@ -13,6 +13,10 @@ 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}.`);
|
||||||
|
return arch;
|
||||||
|
};
|
||||||
|
export default (assets) => {
|
||||||
|
const arch = getArchitecture();
|
||||||
const assetName = `bun-${process.platform}-${arch}.zip`;
|
const assetName = `bun-${process.platform}-${arch}.zip`;
|
||||||
const asset = assets.find(asset => asset.name === assetName);
|
const asset = assets.find(asset => asset.name === assetName);
|
||||||
if (!asset)
|
if (!asset)
|
||||||
|
23
dist/utils/getGithubRelease.js
vendored
23
dist/utils/getGithubRelease.js
vendored
@ -1,11 +1,28 @@
|
|||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
export default async (version, token, miscTestBuilds) => {
|
import { getArchitecture } from './getAsset';
|
||||||
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : 'oven-sh/bun';
|
export default async (version, token, fullRepository, customDownloadUrl, miscTestBuilds) => {
|
||||||
|
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : fullRepository.split('/').slice(3).join('/');
|
||||||
let url;
|
let url;
|
||||||
if (version === 'latest' || miscTestBuilds)
|
if (customDownloadUrl)
|
||||||
|
url = customDownloadUrl;
|
||||||
|
else if (version === 'latest' || miscTestBuilds)
|
||||||
url = `https://api.github.com/repos/${repository}/releases/latest`;
|
url = `https://api.github.com/repos/${repository}/releases/latest`;
|
||||||
else
|
else
|
||||||
url = `https://api.github.com/repos/${repository}/releases/tags/${version.includes('canary') ? version : `bun-v${version}`}`;
|
url = `https://api.github.com/repos/${repository}/releases/tags/${version.includes('canary') ? version : `bun-v${version}`}`;
|
||||||
|
if (customDownloadUrl) {
|
||||||
|
return {
|
||||||
|
name: 'custom',
|
||||||
|
version: version + Math.random().toString(36).slice(-8),
|
||||||
|
html_url: customDownloadUrl,
|
||||||
|
tag_name: 'custom',
|
||||||
|
assets: [
|
||||||
|
{
|
||||||
|
name: `bun-${process.platform}-${getArchitecture()}`,
|
||||||
|
browser_download_url: customDownloadUrl
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
const release = await (await fetch(url, {
|
const release = await (await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -15,11 +15,13 @@ const main = async() => {
|
|||||||
try {
|
try {
|
||||||
const version = getInput('bun-version');
|
const version = getInput('bun-version');
|
||||||
const token = getInput('github-token');
|
const token = getInput('github-token');
|
||||||
const miscTestBuilds = (getInput('misc-test-builds') === 'true');
|
const repository = getInput('repository');
|
||||||
|
const miscTestBuilds = (getInput('misc-test-builds') === 'true') || (repository.includes('oven-sh/misc-test-builds'));
|
||||||
|
const customDownloadUrl = getInput('custom-download-url') || null;
|
||||||
|
|
||||||
if (!version) return exit('Invalid bun version.');
|
if (!version) return exit('Invalid bun version.');
|
||||||
|
|
||||||
const release = await getGithubRelease(version, token, miscTestBuilds);
|
const release = await getGithubRelease(version, token, repository, customDownloadUrl, miscTestBuilds);
|
||||||
if (release?.message === 'Not Found') return exit('Invalid bun version.', miscTestBuilds);
|
if (release?.message === 'Not Found') return exit('Invalid bun version.', miscTestBuilds);
|
||||||
|
|
||||||
info(`Going to install release ${release.version}`);
|
info(`Going to install release ${release.version}`);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { exit } from '../index.js';
|
import { exit } from '../index.js';
|
||||||
import { Asset } from './getGithubRelease.js';
|
import { Asset } from './getGithubRelease.js';
|
||||||
|
|
||||||
export default (assets: Asset[]) => {
|
export const getArchitecture = () => {
|
||||||
let arch;
|
let arch;
|
||||||
switch (process.arch) {
|
switch (process.arch) {
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
@ -17,6 +17,11 @@ 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}.`);
|
||||||
|
|
||||||
|
return arch;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default (assets: Asset[]) => {
|
||||||
|
const arch = getArchitecture();
|
||||||
const assetName = `bun-${process.platform}-${arch}.zip`;
|
const assetName = `bun-${process.platform}-${arch}.zip`;
|
||||||
const asset = assets.find(asset => asset.name === assetName);
|
const asset = assets.find(asset => asset.name === assetName);
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
|
import { getArchitecture } from './getAsset';
|
||||||
|
|
||||||
export interface Asset {
|
export interface Asset {
|
||||||
name: string;
|
name: string;
|
||||||
@ -14,12 +15,28 @@ export interface Release {
|
|||||||
version: string;
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async(version: string, token: string, miscTestBuilds: boolean): Promise<Release> => {
|
export default async(version: string, token: string, fullRepository: string, customDownloadUrl: string | null, miscTestBuilds: boolean): Promise<Release> => {
|
||||||
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : 'oven-sh/bun'
|
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : fullRepository.split('/').slice(3).join('/');
|
||||||
|
|
||||||
let url;
|
let url;
|
||||||
if (version === 'latest' || miscTestBuilds) url = `https://api.github.com/repos/${repository}/releases/latest`;
|
if (customDownloadUrl) url = customDownloadUrl;
|
||||||
|
else if (version === 'latest' || miscTestBuilds) url = `https://api.github.com/repos/${repository}/releases/latest`;
|
||||||
else url = `https://api.github.com/repos/${repository}/releases/tags/${version.includes('canary') ? version : `bun-v${version}`}`;
|
else url = `https://api.github.com/repos/${repository}/releases/tags/${version.includes('canary') ? version : `bun-v${version}`}`;
|
||||||
|
|
||||||
|
if (customDownloadUrl) {
|
||||||
|
return {
|
||||||
|
name: 'custom',
|
||||||
|
version: version + Math.random().toString(36).slice(-8),
|
||||||
|
html_url: customDownloadUrl,
|
||||||
|
tag_name: 'custom',
|
||||||
|
assets: [
|
||||||
|
{
|
||||||
|
name: `bun-${process.platform}-${getArchitecture()}`,
|
||||||
|
browser_download_url: customDownloadUrl
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
const release: any = await (await fetch(url, {
|
const release: any = await (await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user