Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ec953ee6d | ||
|
|
21ca0e24af | ||
|
|
673843c5ea | ||
|
|
38a9038faf | ||
|
|
1e0686b2cc | ||
|
|
a11484a419 | ||
|
|
fe160cf381 | ||
|
|
dbb8e61d45 | ||
|
|
a99ac77932 | ||
|
|
fe4b2b1cd6 | ||
|
|
10e847eceb | ||
|
|
b3fb4f3421 | ||
|
|
f5a14b237f | ||
|
|
e2c23afd2e | ||
|
|
befdce7132 | ||
|
|
3c39374369 | ||
|
|
3e21e45aa4 | ||
|
|
3b03c8d63a | ||
|
|
bc3424761e | ||
|
|
962df21a50 | ||
|
|
c3404c3d6b | ||
|
|
f391a17228 | ||
|
|
24c8fd036a | ||
|
|
89f6825456 | ||
|
|
079e10bfd6 | ||
|
|
3532147424 | ||
|
|
e6a8865f72 | ||
|
|
27a94d6f80 | ||
|
|
b0a04f5fb3 | ||
|
|
ddba6331f8 | ||
|
|
99221c1ae0 | ||
|
|
13923243f4 | ||
|
|
a9318b00d5 | ||
|
|
bf40fde936 | ||
|
|
92c5bc2cef | ||
|
|
37397a08ec | ||
|
|
a0f9c413e5 | ||
|
|
d744239ce1 | ||
|
|
bfac95679f | ||
|
|
640630d09e | ||
|
|
70b6cfe9d1 | ||
|
|
933334b350 |
73
.github/workflows/test.yml
vendored
73
.github/workflows/test.yml
vendored
@@ -14,22 +14,83 @@ jobs:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
bun-version:
|
||||
["latest", "0.1.3", "latest"]
|
||||
misc-test-builds:
|
||||
[false, true]
|
||||
["latest", "0.1.4"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Bun - Test Builds * ${{ matrix.misc-test-builds }}
|
||||
if: matrix.os != 'macos-latest' && matrix.misc-test-builds != true
|
||||
uses: ./
|
||||
with:
|
||||
bun-version: ${{ matrix.bun-version }}
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
misc-test-builds: ${{ matrix.misc-test-builds }}
|
||||
|
||||
- name: Try bun
|
||||
if: matrix.os != 'macos-latest' && matrix.misc-test-builds != true
|
||||
run: |
|
||||
bun --version
|
||||
test-version-canary:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
bun-version:
|
||||
["canary"]
|
||||
|
||||
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 }}
|
||||
|
||||
- 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://api.github.com/repos/oven-sh/bun/actions/artifacts/311939881/zip"]
|
||||
|
||||
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
|
||||
run: |
|
||||
bun --version
|
||||
34
README.md
34
README.md
@@ -8,24 +8,44 @@ Set up your GitHub Actions workflow with a specific version of Bun.
|
||||
### Latest stable
|
||||
|
||||
```yaml
|
||||
- uses: xhyrom/setup-bun@v0.1.3
|
||||
- uses: xhyrom/setup-bun@v0.1.7
|
||||
with:
|
||||
bun-version: latest
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
### Specific version
|
||||
|
||||
```yaml
|
||||
- uses: xhyrom/setup-bun@v0.1.3
|
||||
- uses: xhyrom/setup-bun@v0.1.7
|
||||
with:
|
||||
bun-version: "0.1.3"
|
||||
bun-version: "0.1.5"
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
### Test builds
|
||||
### Canary builds
|
||||
|
||||
```yaml
|
||||
- uses: xhyrom/setup-bun@v0.1.3
|
||||
- uses: xhyrom/setup-bun@v0.1.7
|
||||
with:
|
||||
bun-version: latest
|
||||
misc-test-builds: true
|
||||
bun-version: canary
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
### Custom repository
|
||||
|
||||
```yaml
|
||||
- uses: xhyrom/setup-bun@v0.1.7
|
||||
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.7
|
||||
with:
|
||||
custom-download-url: https://api.github.com/repos/oven-sh/bun/actions/artifacts/311939881/zip # must be github api
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
14
action.yml
14
action.yml
@@ -10,10 +10,20 @@ inputs:
|
||||
bun-version:
|
||||
description: "The Bun version to install."
|
||||
default: "latest"
|
||||
required: false
|
||||
github-token:
|
||||
description: "The github token secret can be passed in using {{ secrets.GITHUB_TOKEN }}"
|
||||
default: ${{ github.token }}
|
||||
required: false
|
||||
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
|
||||
|
||||
outputs:
|
||||
@@ -22,4 +32,4 @@ outputs:
|
||||
|
||||
runs:
|
||||
using: "node12"
|
||||
main: "dist/index.js"
|
||||
main: "dist/index.js"
|
||||
|
||||
8
dist/index.js
vendored
8
dist/index.js
vendored
@@ -14,14 +14,16 @@ const main = async () => {
|
||||
try {
|
||||
const version = getInput('bun-version');
|
||||
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.');
|
||||
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')
|
||||
return exit('Invalid bun version.', miscTestBuilds);
|
||||
info(`Going to install release ${release.version}`);
|
||||
await install(release);
|
||||
await install(release, token, customDownloadUrl !== null);
|
||||
setOutput('bun-version', release.tag_name);
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
6
dist/utils/getAsset.js
vendored
6
dist/utils/getAsset.js
vendored
@@ -1,5 +1,5 @@
|
||||
import { exit } from '../index.js';
|
||||
export default (assets) => {
|
||||
export const getArchitecture = () => {
|
||||
let arch;
|
||||
switch (process.arch) {
|
||||
case 'arm64':
|
||||
@@ -13,6 +13,10 @@ export default (assets) => {
|
||||
}
|
||||
if (!['linux', 'darwin'].some(platform => process.platform === platform))
|
||||
throw new Error(`Unsupported platform ${process.platform}.`);
|
||||
return arch;
|
||||
};
|
||||
export default (assets) => {
|
||||
const arch = getArchitecture();
|
||||
const assetName = `bun-${process.platform}-${arch}.zip`;
|
||||
const asset = assets.find(asset => asset.name === assetName);
|
||||
if (!asset)
|
||||
|
||||
28
dist/utils/getGithubRelease.js
vendored
28
dist/utils/getGithubRelease.js
vendored
@@ -1,16 +1,34 @@
|
||||
import { nanoid } from 'nanoid';
|
||||
import fetch from 'node-fetch';
|
||||
export default async (version, token, miscTestBuilds) => {
|
||||
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : 'oven-sh/bun';
|
||||
import { getArchitecture } from './getAsset.js';
|
||||
export default async (version, token, fullRepository, customDownloadUrl, miscTestBuilds) => {
|
||||
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : fullRepository.split('/').slice(3).join('/');
|
||||
let url;
|
||||
if (version === 'latest' || miscTestBuilds)
|
||||
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/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}-${nanoid(10)}`,
|
||||
html_url: customDownloadUrl,
|
||||
tag_name: 'custom',
|
||||
assets: [
|
||||
{
|
||||
name: `bun-${process.platform}-${getArchitecture()}.zip`,
|
||||
browser_download_url: customDownloadUrl
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
const release = await (await fetch(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': 'setup-bun-github-action',
|
||||
'Authorization': token
|
||||
'Authorization': `token ${token}`
|
||||
}
|
||||
})).json();
|
||||
return {
|
||||
|
||||
22
dist/utils/install.js
vendored
22
dist/utils/install.js
vendored
@@ -4,7 +4,7 @@ import { addPath, info } from '@actions/core';
|
||||
import getAsset from './getAsset.js';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
export default async (release) => {
|
||||
export default async (release, token, customUrl) => {
|
||||
const asset = getAsset(release.assets);
|
||||
const path = join(homedir(), '.bun', 'bin', asset.name);
|
||||
const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`);
|
||||
@@ -14,12 +14,22 @@ export default async (release) => {
|
||||
return;
|
||||
}
|
||||
info(`Downloading Bun from ${asset.asset.browser_download_url}.`);
|
||||
const zipPath = await downloadTool(asset.asset.browser_download_url);
|
||||
const extracted = await extractZip(zipPath, join(homedir(), '.bun', 'bin'));
|
||||
const zipPath = await downloadTool(asset.asset.browser_download_url, null, new URL(asset.asset.browser_download_url).host.includes('github.com') ? `token ${token}` : '', {
|
||||
'Authorization': new URL(asset.asset.browser_download_url).host.includes('github.com') ? `token ${token}` : ''
|
||||
});
|
||||
let extracted;
|
||||
if (customUrl && asset.asset.browser_download_url.includes('artifacts')) {
|
||||
extracted = await extractZip(zipPath, join(homedir(), 'onlyforunzip'));
|
||||
extracted = await extractZip(join(homedir(), 'onlyforunzip', asset.asset.name), join(homedir(), '.bun', 'bin'));
|
||||
}
|
||||
else
|
||||
extracted = await extractZip(zipPath, join(homedir(), '.bun', 'bin'));
|
||||
const newCache = await cacheDir(extracted, 'bun', release.version);
|
||||
await saveCache([
|
||||
join(extracted, asset.name)
|
||||
], `bun-${process.platform}-${asset.name}-${release.version}`);
|
||||
if (!customUrl) {
|
||||
await saveCache([
|
||||
join(extracted, asset.name)
|
||||
], `bun-${process.platform}-${asset.name}-${release.version}`);
|
||||
}
|
||||
info(`Cached Bun to ${newCache}.`);
|
||||
addPath(newCache);
|
||||
const bunPath = join(homedir(), '.bun', 'bin', asset.name);
|
||||
|
||||
1
node_modules/.bin/nanoid
generated
vendored
Symbolic link
1
node_modules/.bin/nanoid
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../nanoid/bin/nanoid.js
|
||||
20
node_modules/nanoid/LICENSE
generated
vendored
Normal file
20
node_modules/nanoid/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
39
node_modules/nanoid/README.md
generated
vendored
Normal file
39
node_modules/nanoid/README.md
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# Nano ID
|
||||
|
||||
<img src="https://ai.github.io/nanoid/logo.svg" align="right"
|
||||
alt="Nano ID logo by Anton Lovchikov" width="180" height="94">
|
||||
|
||||
**English** | [Русский](./README.ru.md) | [简体中文](./README.zh-CN.md) | [Bahasa Indonesia](./README.id-ID.md)
|
||||
|
||||
A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
|
||||
|
||||
> “An amazing level of senseless perfectionism,
|
||||
> which is simply impossible not to respect.”
|
||||
|
||||
* **Small.** 130 bytes (minified and gzipped). No dependencies.
|
||||
[Size Limit] controls the size.
|
||||
* **Fast.** It is 2 times faster than UUID.
|
||||
* **Safe.** It uses hardware random generator. Can be used in clusters.
|
||||
* **Short IDs.** It uses a larger alphabet than UUID (`A-Za-z0-9_-`).
|
||||
So ID size was reduced from 36 to 21 symbols.
|
||||
* **Portable.** Nano ID was ported
|
||||
to [20 programming languages](#other-programming-languages).
|
||||
|
||||
```js
|
||||
import { nanoid } from 'nanoid'
|
||||
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"
|
||||
```
|
||||
|
||||
Supports modern browsers, IE [with Babel], Node.js and React Native.
|
||||
|
||||
[online tool]: https://gitpod.io/#https://github.com/ai/nanoid/
|
||||
[with Babel]: https://developer.epages.com/blog/coding/how-to-transpile-node-modules-with-babel-and-webpack-in-a-monorepo/
|
||||
[Size Limit]: https://github.com/ai/size-limit
|
||||
|
||||
<a href="https://evilmartians.com/?utm_source=nanoid">
|
||||
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
|
||||
alt="Sponsored by Evil Martians" width="236" height="54">
|
||||
</a>
|
||||
|
||||
## Docs
|
||||
Read **[full docs](https://github.com/ai/nanoid#readme)** on GitHub.
|
||||
33
node_modules/nanoid/async/index.browser.js
generated
vendored
Normal file
33
node_modules/nanoid/async/index.browser.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
export let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
||||
export let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
||||
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
||||
return async (size = defaultSize) => {
|
||||
let id = ''
|
||||
while (true) {
|
||||
let bytes = crypto.getRandomValues(new Uint8Array(step))
|
||||
let i = step
|
||||
while (i--) {
|
||||
id += alphabet[bytes[i] & mask] || ''
|
||||
if (id.length === size) return id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export let nanoid = async (size = 21) => {
|
||||
let id = ''
|
||||
let bytes = crypto.getRandomValues(new Uint8Array(size))
|
||||
while (size--) {
|
||||
let byte = bytes[size] & 63
|
||||
if (byte < 36) {
|
||||
id += byte.toString(36)
|
||||
} else if (byte < 62) {
|
||||
id += (byte - 26).toString(36).toUpperCase()
|
||||
} else if (byte < 63) {
|
||||
id += '_'
|
||||
} else {
|
||||
id += '-'
|
||||
}
|
||||
}
|
||||
return id
|
||||
}
|
||||
56
node_modules/nanoid/async/index.d.ts
generated
vendored
Normal file
56
node_modules/nanoid/async/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Generate secure URL-friendly unique ID. The non-blocking version.
|
||||
*
|
||||
* By default, the ID will have 21 symbols to have a collision probability
|
||||
* similar to UUID v4.
|
||||
*
|
||||
* ```js
|
||||
* import { nanoid } from 'nanoid/async'
|
||||
* nanoid().then(id => {
|
||||
* model.id = id
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @param size Size of the ID. The default size is 21.
|
||||
* @returns A promise with a random string.
|
||||
*/
|
||||
export function nanoid(size?: number): Promise<string>
|
||||
|
||||
/**
|
||||
* A low-level function.
|
||||
* Generate secure unique ID with custom alphabet. The non-blocking version.
|
||||
*
|
||||
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||
* will not be secure.
|
||||
*
|
||||
* @param alphabet Alphabet used to generate the ID.
|
||||
* @param defaultSize Size of the ID. The default size is 21.
|
||||
* @returns A function that returns a promise with a random string.
|
||||
*
|
||||
* ```js
|
||||
* import { customAlphabet } from 'nanoid/async'
|
||||
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
||||
* nanoid().then(id => {
|
||||
* model.id = id //=> "8ё56а"
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export function customAlphabet(
|
||||
alphabet: string,
|
||||
defaultSize?: number
|
||||
): (size?: number) => Promise<string>
|
||||
|
||||
/**
|
||||
* Generate an array of random bytes collected from hardware noise.
|
||||
*
|
||||
* ```js
|
||||
* import { random } from 'nanoid/async'
|
||||
* random(5).then(bytes => {
|
||||
* bytes //=> [10, 67, 212, 67, 89]
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @param bytes Size of the array.
|
||||
* @returns A promise with a random bytes array.
|
||||
*/
|
||||
export function random(bytes: number): Promise<Uint8Array>
|
||||
34
node_modules/nanoid/async/index.js
generated
vendored
Normal file
34
node_modules/nanoid/async/index.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { randomFill } from 'crypto'
|
||||
import { urlAlphabet } from '../url-alphabet/index.js'
|
||||
export let random = bytes =>
|
||||
new Promise((resolve, reject) => {
|
||||
randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(buf)
|
||||
}
|
||||
})
|
||||
})
|
||||
export let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||
let tick = (id, size = defaultSize) =>
|
||||
random(step).then(bytes => {
|
||||
let i = step
|
||||
while (i--) {
|
||||
id += alphabet[bytes[i] & mask] || ''
|
||||
if (id.length === size) return id
|
||||
}
|
||||
return tick(id, size)
|
||||
})
|
||||
return size => tick('', size)
|
||||
}
|
||||
export let nanoid = (size = 21) =>
|
||||
random(size).then(bytes => {
|
||||
let id = ''
|
||||
while (size--) {
|
||||
id += urlAlphabet[bytes[size] & 63]
|
||||
}
|
||||
return id
|
||||
})
|
||||
25
node_modules/nanoid/async/index.native.js
generated
vendored
Normal file
25
node_modules/nanoid/async/index.native.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { getRandomBytesAsync } from 'expo-random'
|
||||
import { urlAlphabet } from '../url-alphabet/index.js'
|
||||
export let random = getRandomBytesAsync
|
||||
export let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||
let tick = (id, size = defaultSize) =>
|
||||
random(step).then(bytes => {
|
||||
let i = step
|
||||
while (i--) {
|
||||
id += alphabet[bytes[i] & mask] || ''
|
||||
if (id.length === size) return id
|
||||
}
|
||||
return tick(id, size)
|
||||
})
|
||||
return size => tick('', size)
|
||||
}
|
||||
export let nanoid = (size = 21) =>
|
||||
random(size).then(bytes => {
|
||||
let id = ''
|
||||
while (size--) {
|
||||
id += urlAlphabet[bytes[size] & 63]
|
||||
}
|
||||
return id
|
||||
})
|
||||
46
node_modules/nanoid/bin/nanoid.js
generated
vendored
Executable file
46
node_modules/nanoid/bin/nanoid.js
generated
vendored
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env node
|
||||
import { nanoid, customAlphabet } from '../index.js'
|
||||
function print(msg) {
|
||||
process.stdout.write(msg + '\n')
|
||||
}
|
||||
function error(msg) {
|
||||
process.stderr.write(msg + '\n')
|
||||
process.exit(1)
|
||||
}
|
||||
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
||||
print(`
|
||||
Usage
|
||||
$ nanoid [options]
|
||||
Options
|
||||
-s, --size Generated ID size
|
||||
-a, --alphabet Alphabet to use
|
||||
-h, --help Show this help
|
||||
Examples
|
||||
$ nanoid --s 15
|
||||
S9sBF77U6sDB8Yg
|
||||
$ nanoid --size 10 --alphabet abc
|
||||
bcabababca`)
|
||||
process.exit()
|
||||
}
|
||||
let alphabet, size
|
||||
for (let i = 2; i < process.argv.length; i++) {
|
||||
let arg = process.argv[i]
|
||||
if (arg === '--size' || arg === '-s') {
|
||||
size = Number(process.argv[i + 1])
|
||||
i += 1
|
||||
if (Number.isNaN(size) || size <= 0) {
|
||||
error('Size must be positive integer')
|
||||
}
|
||||
} else if (arg === '--alphabet' || arg === '-a') {
|
||||
alphabet = process.argv[i + 1]
|
||||
i += 1
|
||||
} else {
|
||||
error('Unknown argument ' + arg)
|
||||
}
|
||||
}
|
||||
if (alphabet) {
|
||||
let customNanoid = customAlphabet(alphabet, size)
|
||||
print(customNanoid())
|
||||
} else {
|
||||
print(nanoid(size))
|
||||
}
|
||||
33
node_modules/nanoid/index.browser.js
generated
vendored
Normal file
33
node_modules/nanoid/index.browser.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
export { urlAlphabet } from './url-alphabet/index.js'
|
||||
export let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
||||
export let customRandom = (alphabet, defaultSize, getRandom) => {
|
||||
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
||||
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
||||
return (size = defaultSize) => {
|
||||
let id = ''
|
||||
while (true) {
|
||||
let bytes = getRandom(step)
|
||||
let j = step
|
||||
while (j--) {
|
||||
id += alphabet[bytes[j] & mask] || ''
|
||||
if (id.length === size) return id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export let customAlphabet = (alphabet, size = 21) =>
|
||||
customRandom(alphabet, size, random)
|
||||
export let nanoid = (size = 21) =>
|
||||
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
||||
byte &= 63
|
||||
if (byte < 36) {
|
||||
id += byte.toString(36)
|
||||
} else if (byte < 62) {
|
||||
id += (byte - 26).toString(36).toUpperCase()
|
||||
} else if (byte > 62) {
|
||||
id += '-'
|
||||
} else {
|
||||
id += '_'
|
||||
}
|
||||
return id
|
||||
}, '')
|
||||
91
node_modules/nanoid/index.d.ts
generated
vendored
Normal file
91
node_modules/nanoid/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Generate secure URL-friendly unique ID.
|
||||
*
|
||||
* By default, the ID will have 21 symbols to have a collision probability
|
||||
* similar to UUID v4.
|
||||
*
|
||||
* ```js
|
||||
* import { nanoid } from 'nanoid'
|
||||
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
|
||||
* ```
|
||||
*
|
||||
* @param size Size of the ID. The default size is 21.
|
||||
* @returns A random string.
|
||||
*/
|
||||
export function nanoid(size?: number): string
|
||||
|
||||
/**
|
||||
* Generate secure unique ID with custom alphabet.
|
||||
*
|
||||
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||
* will not be secure.
|
||||
*
|
||||
* @param alphabet Alphabet used to generate the ID.
|
||||
* @param defaultSize Size of the ID. The default size is 21.
|
||||
* @returns A random string generator.
|
||||
*
|
||||
* ```js
|
||||
* const { customAlphabet } = require('nanoid')
|
||||
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
||||
* nanoid() //=> "8ё56а"
|
||||
* ```
|
||||
*/
|
||||
export function customAlphabet(
|
||||
alphabet: string,
|
||||
defaultSize?: number
|
||||
): (size?: number) => string
|
||||
|
||||
/**
|
||||
* Generate unique ID with custom random generator and alphabet.
|
||||
*
|
||||
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||
* will not be secure.
|
||||
*
|
||||
* ```js
|
||||
* import { customRandom } from 'nanoid/format'
|
||||
*
|
||||
* const nanoid = customRandom('abcdef', 5, size => {
|
||||
* const random = []
|
||||
* for (let i = 0; i < size; i++) {
|
||||
* random.push(randomByte())
|
||||
* }
|
||||
* return random
|
||||
* })
|
||||
*
|
||||
* nanoid() //=> "fbaef"
|
||||
* ```
|
||||
*
|
||||
* @param alphabet Alphabet used to generate a random string.
|
||||
* @param size Size of the random string.
|
||||
* @param random A random bytes generator.
|
||||
* @returns A random string generator.
|
||||
*/
|
||||
export function customRandom(
|
||||
alphabet: string,
|
||||
size: number,
|
||||
random: (bytes: number) => Uint8Array
|
||||
): () => string
|
||||
|
||||
/**
|
||||
* URL safe symbols.
|
||||
*
|
||||
* ```js
|
||||
* import { urlAlphabet } from 'nanoid'
|
||||
* const nanoid = customAlphabet(urlAlphabet, 10)
|
||||
* nanoid() //=> "Uakgb_J5m9"
|
||||
* ```
|
||||
*/
|
||||
export const urlAlphabet: string
|
||||
|
||||
/**
|
||||
* Generate an array of random bytes collected from hardware noise.
|
||||
*
|
||||
* ```js
|
||||
* import { customRandom, random } from 'nanoid'
|
||||
* const nanoid = customRandom("abcdef", 5, random)
|
||||
* ```
|
||||
*
|
||||
* @param bytes Size of the array.
|
||||
* @returns An array of random bytes.
|
||||
*/
|
||||
export function random(bytes: number): Uint8Array
|
||||
45
node_modules/nanoid/index.js
generated
vendored
Normal file
45
node_modules/nanoid/index.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import { randomFillSync } from 'crypto'
|
||||
import { urlAlphabet } from './url-alphabet/index.js'
|
||||
export { urlAlphabet }
|
||||
const POOL_SIZE_MULTIPLIER = 128
|
||||
let pool, poolOffset
|
||||
let fillPool = bytes => {
|
||||
if (!pool || pool.length < bytes) {
|
||||
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
|
||||
randomFillSync(pool)
|
||||
poolOffset = 0
|
||||
} else if (poolOffset + bytes > pool.length) {
|
||||
randomFillSync(pool)
|
||||
poolOffset = 0
|
||||
}
|
||||
poolOffset += bytes
|
||||
}
|
||||
export let random = bytes => {
|
||||
fillPool((bytes -= 0))
|
||||
return pool.subarray(poolOffset - bytes, poolOffset)
|
||||
}
|
||||
export let customRandom = (alphabet, defaultSize, getRandom) => {
|
||||
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||
return (size = defaultSize) => {
|
||||
let id = ''
|
||||
while (true) {
|
||||
let bytes = getRandom(step)
|
||||
let i = step
|
||||
while (i--) {
|
||||
id += alphabet[bytes[i] & mask] || ''
|
||||
if (id.length === size) return id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export let customAlphabet = (alphabet, size = 21) =>
|
||||
customRandom(alphabet, size, random)
|
||||
export let nanoid = (size = 21) => {
|
||||
fillPool((size -= 0))
|
||||
let id = ''
|
||||
for (let i = poolOffset - size; i < poolOffset; i++) {
|
||||
id += urlAlphabet[pool[i] & 63]
|
||||
}
|
||||
return id
|
||||
}
|
||||
1
node_modules/nanoid/nanoid.js
generated
vendored
Normal file
1
node_modules/nanoid/nanoid.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export let nanoid=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce(((t,e)=>t+=(e&=63)<36?e.toString(36):e<62?(e-26).toString(36).toUpperCase():e>62?"-":"_"),"");
|
||||
33
node_modules/nanoid/non-secure/index.d.ts
generated
vendored
Normal file
33
node_modules/nanoid/non-secure/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Generate URL-friendly unique ID. This method uses the non-secure
|
||||
* predictable random generator with bigger collision probability.
|
||||
*
|
||||
* ```js
|
||||
* import { nanoid } from 'nanoid/non-secure'
|
||||
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
|
||||
* ```
|
||||
*
|
||||
* @param size Size of the ID. The default size is 21.
|
||||
* @returns A random string.
|
||||
*/
|
||||
export function nanoid(size?: number): string
|
||||
|
||||
/**
|
||||
* Generate a unique ID based on a custom alphabet.
|
||||
* This method uses the non-secure predictable random generator
|
||||
* with bigger collision probability.
|
||||
*
|
||||
* @param alphabet Alphabet used to generate the ID.
|
||||
* @param defaultSize Size of the ID. The default size is 21.
|
||||
* @returns A random string generator.
|
||||
*
|
||||
* ```js
|
||||
* import { customAlphabet } from 'nanoid/non-secure'
|
||||
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
||||
* model.id = //=> "8ё56а"
|
||||
* ```
|
||||
*/
|
||||
export function customAlphabet(
|
||||
alphabet: string,
|
||||
defaultSize?: number
|
||||
): (size?: number) => string
|
||||
20
node_modules/nanoid/non-secure/index.js
generated
vendored
Normal file
20
node_modules/nanoid/non-secure/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
let urlAlphabet =
|
||||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||
export let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
return (size = defaultSize) => {
|
||||
let id = ''
|
||||
let i = size
|
||||
while (i--) {
|
||||
id += alphabet[(Math.random() * alphabet.length) | 0]
|
||||
}
|
||||
return id
|
||||
}
|
||||
}
|
||||
export let nanoid = (size = 21) => {
|
||||
let id = ''
|
||||
let i = size
|
||||
while (i--) {
|
||||
id += urlAlphabet[(Math.random() * 64) | 0]
|
||||
}
|
||||
return id
|
||||
}
|
||||
41
node_modules/nanoid/package.json
generated
vendored
Normal file
41
node_modules/nanoid/package.json
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "nanoid",
|
||||
"version": "4.0.0",
|
||||
"description": "A tiny (116 bytes), secure URL-friendly unique string ID generator",
|
||||
"keywords": [
|
||||
"uuid",
|
||||
"random",
|
||||
"id",
|
||||
"url"
|
||||
],
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": "^14 || ^16 || >=18"
|
||||
},
|
||||
"author": "Andrey Sitnik <andrey@sitnik.ru>",
|
||||
"license": "MIT",
|
||||
"repository": "ai/nanoid",
|
||||
"exports": {
|
||||
".": {
|
||||
"browser": "./index.browser.js",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./async": {
|
||||
"browser": "./async/index.browser.js",
|
||||
"default": "./async/index.js"
|
||||
},
|
||||
"./non-secure": "./non-secure/index.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"browser": {
|
||||
"./index.js": "./index.browser.js",
|
||||
"./async/index.js": "./async/index.browser.js",
|
||||
"./async/index.cjs": "./async/index.browser.cjs"
|
||||
},
|
||||
"react-native": {
|
||||
"./async/index.js": "./async/index.native.js"
|
||||
},
|
||||
"bin": "./bin/nanoid.js",
|
||||
"sideEffects": false,
|
||||
"types": "./index.d.ts"
|
||||
}
|
||||
2
node_modules/nanoid/url-alphabet/index.js
generated
vendored
Normal file
2
node_modules/nanoid/url-alphabet/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export const urlAlphabet =
|
||||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.7",
|
||||
"name": "setup-bun",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
@@ -28,10 +28,11 @@
|
||||
"@actions/cache": "^3.0.0",
|
||||
"@actions/core": "^1.9.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"nanoid": "^4.0.0",
|
||||
"node-fetch": "^3.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bun-types": "^0.0.83",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,16 +15,18 @@ const main = async() => {
|
||||
try {
|
||||
const version = getInput('bun-version');
|
||||
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.');
|
||||
|
||||
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);
|
||||
|
||||
info(`Going to install release ${release.version}`);
|
||||
|
||||
await install(release);
|
||||
await install(release, token, customDownloadUrl !== null);
|
||||
|
||||
setOutput('bun-version', release.tag_name);
|
||||
} catch(e) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { exit } from '../index.js';
|
||||
import { Asset } from './getGithubRelease.js';
|
||||
|
||||
export default (assets: Asset[]) => {
|
||||
export const getArchitecture = () => {
|
||||
let arch;
|
||||
switch (process.arch) {
|
||||
case 'arm64':
|
||||
@@ -15,8 +15,13 @@ export default (assets: Asset[]) => {
|
||||
}
|
||||
|
||||
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 asset = assets.find(asset => asset.name === assetName);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getInput } from '@actions/core';
|
||||
import { nanoid } from 'nanoid';
|
||||
import fetch from 'node-fetch';
|
||||
import { getArchitecture } from './getAsset.js';
|
||||
|
||||
export interface Asset {
|
||||
name: string;
|
||||
@@ -15,17 +16,34 @@ export interface Release {
|
||||
version: string;
|
||||
}
|
||||
|
||||
export default async(version: string, token: string, miscTestBuilds: boolean): Promise<Release> => {
|
||||
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : 'oven-sh/bun'
|
||||
export default async(version: string, token: string, fullRepository: string, customDownloadUrl: string | null, miscTestBuilds: boolean): Promise<Release> => {
|
||||
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : fullRepository.split('/').slice(3).join('/');
|
||||
|
||||
let url;
|
||||
if (version === 'latest' || miscTestBuilds) url = `https://api.github.com/repos/${repository}/releases/latest`;
|
||||
else url = `https://api.github.com/repos/${repository}/releases/tags/bun-v${version}`;
|
||||
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}`}`;
|
||||
|
||||
if (customDownloadUrl) {
|
||||
return {
|
||||
name: 'custom',
|
||||
version: `${version}-${nanoid(10)}`,
|
||||
html_url: customDownloadUrl,
|
||||
tag_name: 'custom',
|
||||
assets: [
|
||||
{
|
||||
name: `bun-${process.platform}-${getArchitecture()}.zip`,
|
||||
browser_download_url: customDownloadUrl
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
const release: any = await (await fetch(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': 'setup-bun-github-action',
|
||||
'Authorization': token
|
||||
'Authorization': `token ${token}`
|
||||
}
|
||||
})).json();
|
||||
|
||||
@@ -33,4 +51,4 @@ export default async(version: string, token: string, miscTestBuilds: boolean): P
|
||||
...release,
|
||||
version: miscTestBuilds ? `timestamp-v${new Date(release.name).getTime().toString()}` : release.tag_name.replace('bun-v', '')
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import getAsset from './getAsset.js';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
|
||||
export default async(release: Release) => {
|
||||
export default async(release: Release, token: string, customUrl: boolean) => {
|
||||
const asset = getAsset(release.assets);
|
||||
const path = join(homedir(), '.bun', 'bin', asset.name);
|
||||
const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`);
|
||||
@@ -18,17 +18,32 @@ export default async(release: Release) => {
|
||||
|
||||
info(`Downloading Bun from ${asset.asset.browser_download_url}.`);
|
||||
|
||||
const zipPath = await downloadTool(asset.asset.browser_download_url);
|
||||
const extracted = await extractZip(zipPath, join(homedir(), '.bun', 'bin'));
|
||||
const zipPath = await downloadTool(
|
||||
asset.asset.browser_download_url,
|
||||
null,
|
||||
new URL(asset.asset.browser_download_url).host.includes('github.com') ? `token ${token}` : '',
|
||||
{
|
||||
'Authorization': new URL(asset.asset.browser_download_url).host.includes('github.com') ? `token ${token}` : ''
|
||||
}
|
||||
);
|
||||
|
||||
let extracted;
|
||||
if (customUrl && asset.asset.browser_download_url.includes('artifacts')) {
|
||||
extracted = await extractZip(zipPath, join(homedir(), 'onlyforunzip'));
|
||||
extracted = await extractZip(join(homedir(), 'onlyforunzip', asset.asset.name), join(homedir(), '.bun', 'bin'));
|
||||
} else extracted = await extractZip(zipPath, join(homedir(), '.bun', 'bin'));
|
||||
|
||||
const newCache = await cacheDir(
|
||||
extracted,
|
||||
'bun',
|
||||
release.version
|
||||
);
|
||||
await saveCache([
|
||||
join(extracted, asset.name)
|
||||
], `bun-${process.platform}-${asset.name}-${release.version}`);
|
||||
|
||||
if (!customUrl) {
|
||||
await saveCache([
|
||||
join(extracted, asset.name)
|
||||
], `bun-${process.platform}-${asset.name}-${release.version}`);
|
||||
}
|
||||
|
||||
info(`Cached Bun to ${newCache}.`);
|
||||
addPath(newCache);
|
||||
|
||||
Reference in New Issue
Block a user