setup-bun

repository·main·Indexed 20 days ago

https://github.com/oven-sh/setup-bun

A GitHub Action for automating the downloading, installation, and configuration of the Bun runtime within GitHub Actions workflows. It supports version specification via inputs, version files, or package.json, custom package registry configuration for private registries, and provides outputs such as the installed Bun version, revision, and executable path.

Tokens
2.7K
Snippets
11
Records
14
Agent score
71%

What's inside setup-bun

  1. Install Bun in GitHub Actions

    main

    Use the oven-sh/setup-bun@v2 action to download, install, and set up Bun in your GitHub Actions workflows.

    By default, if no version is specified, the action follows this resolution order:

    1. Checks package.json for the packageManager field (e.g., "packageManager": "bun@1.0.25").
    2. If packageManager is missing, checks package.json for engines.bun.
    3. If neither is found or package.json is missing, it defaults to latest.
    - uses: oven-sh/setup-bun@v2
  2. Configure custom package registries

    main

    You can configure multiple package registries (both default and scoped) using the registries input. This allows Bun to authenticate with private or internal registries during bun install.

    Important: When using authentication tokens or credentials, you must ensure the corresponding environment variables are set in the workflow steps that perform the installation (e.g., bun install).

    - uses: oven-sh/setup-bun@v2
      with:
        registries: |
          https://registry.npmjs.org/
          @myorg:https://npm.pkg.github.com/|$GITHUB_TOKEN
          @internal:https://username:$INTERNAL_PASSWORD@registry.internal.com/
    
    - name: Install dependencies
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        INTERNAL_PASSWORD: ${{ secrets.INTERNAL_PASSWORD }}
      run: bun install
  3. Override the Bun download URL

    main

    If you need to point the action to a specific location for the Bun release (e.g., a mirror or a specific architecture zip), use the bun-download-url input.

    - uses: oven-sh/setup-bun@v2
      with:
        bun-download-url: "https://github.com/oven-sh/bun/releases/latest/download/bun-linux-x64.zip"
  4. Specify a Bun version

    main

    You can explicitly define which version of Bun to install using the bun-version input. Supported values include specific versions (e.g., 1.0.0), ranges (e.g., 1.0.x), or special tags like latest and canary.

    - uses: oven-sh/setup-bun@v2
      with:
        bun-version: latest
  5. Install Bun version from a file

    main

    To use a version specified in a specific file, use the bun-version-file input. This is useful for keeping Bun versions in sync with other versioning files like .bun-version or .tool-versions.

    - uses: oven-sh/setup-bun@v2
      with:
        bun-version-file: ".bun-version"
  6. Reference: setup-bun outputs

    main

    The following outputs are available after the action runs:

    NameDescriptionExample
    bun-versionThe output from bun --version.1.0.0
    bun-revisionThe output from bun --revision.1.0.0+822a00c4
    bun-pathThe path to the Bun executable./path/to/bun
    bun-download-urlThe URL from which Bun was downloaded.https://bun.sh/download/latest/linux/x64?avx2=true&profile=false
    cache-hitIf the Bun executable was read from cache.true
  7. Reference: Registry configuration formats

    main

    When providing the registries input, use the following formats to define your registry access:

    TypeFormat
    Default registryhttps://registry.example.com/
    Default registry with tokenhttps://registry.example.com/|$TOKEN
    Scoped registry@scope:https://registry.example.com/
    Scoped registry with token@scope:https://registry.example.com/|$TOKEN
    Scoped registry with URL credentials@scope:https://username:$PASSWORD@registry.example.com/
  8. Reference: setup-bun inputs

    main

    The following inputs are available for the oven-sh/setup-bun@v2 action:

    NameDescriptionDefault
    bun-versionThe version of Bun to download and install.Version from package.json, or latest
    bun-version-fileThe version of Bun to download and install from file.undefined
    bun-download-urlURL to download .zip file for Bun release
    registry-urlRegistry URL where some private package is stored.undefined
    scopeScope for private packages.undefined
    no-cacheDisable caching of the downloaded executable.false
    tokenPersonal access token (PAT) used to fetch tags from the oven-sh/bun repository.${{ github.token }}
  9. Parse registry configuration strings

    main

    The parseRegistries function converts a newline-delimited string of registry configurations into an array of Registry objects. Each object contains the url, the scope (which is an empty string if no scope is provided), and an optional token.

    import { parseRegistries } from './src/registry';
    
    const input = `
    https://registry.npmjs.org/|my-token
    @myorg:https://registry.myorg.com/
    `;
    
    const registries = parseRegistries(input);
    // Result:
    // [
    //   { url: 'https://registry.npmjs.org/', scope: '', token: 'my-token' },
    //   { url: 'https://registry.myorg.com/', scope: '@myorg' }
    // ]
  10. Reference: setup-bun Output values

    main

    The setup-bun action provides the following outputs which can be used in subsequent steps of your workflow:

    OutputTypeDescription
    versionstringThe installed Bun version (e.g., 1.0.0).
    revisionstringThe full Bun revision string.
    bunPathstringThe absolute path to the installed bun executable.
    urlstringThe URL used to download the Bun version.
    cacheHitbooleanWhether the installation was restored from cache.
    type Output = {
      version: string;
      revision: string;
      bunPath: string;
      url: string;
      cacheHit: boolean;
    };
  11. Configure setup-bun GitHub Action inputs

    main

    When using the setup-bun GitHub Action, you can provide several inputs to control the Bun installation. Note that certain inputs like customUrl or noCache will disable caching behavior.

    - uses: oven-sh/setup-bun@v2
      with:
        version: '1.0.0'
        os: 'ubuntu-22.04'
        arch: 'x64'
        avx2: true
        profile: true
        registries: '[{ "url": "https://my-registry.com/", "token": "MY_TOKEN" }]'
        noCache: false
        token: 'GH_TOKEN'
        customUrl: 'https://custom.url/bun.zip'
  12. Access setup-bun outputs

    main

    After the action completes, it provides several outputs that you can use in subsequent steps of your GitHub Actions workflow:

    • bun-version: The version of Bun that was installed.
    • bun-revision: The specific revision of Bun used.
    • bun-path: The file system path where the Bun binary was installed.
    • bun-download-url: The URL from which the Bun binary was downloaded.
    • cache-hit: A boolean indicating if the installation was retrieved from the cache.
    - uses: oven-sh/setup-bun@v2
      id: setup-bun
    
    - name: Use Bun
      run: | 
        echo "Version: ${{ steps.setup-bun.outputs.bun-version }}"
        echo "Path: ${{ steps.setup-bun.outputs.bun-path }}"