|
| 1 | +name: 'Setup Bun with bunenv' |
| 2 | +description: 'Set up a specific Bun version using bunenv for isolated environments' |
| 3 | +author: 'Jacob Coffee' |
| 4 | + |
| 5 | +branding: |
| 6 | + icon: 'package' |
| 7 | + color: 'orange' |
| 8 | + |
| 9 | +inputs: |
| 10 | + bun-version: |
| 11 | + description: 'Bun version to install (e.g., "latest", "1.3.3")' |
| 12 | + required: false |
| 13 | + default: 'latest' |
| 14 | + |
| 15 | + variant: |
| 16 | + description: 'Bun variant to install ("", "baseline", "musl", "profile")' |
| 17 | + required: false |
| 18 | + default: '' |
| 19 | + |
| 20 | + github-token: |
| 21 | + description: 'GitHub token for API requests to avoid rate limits' |
| 22 | + required: false |
| 23 | + default: ${{ github.token }} |
| 24 | + |
| 25 | + cache: |
| 26 | + description: 'Enable caching of bunenv and Bun installations' |
| 27 | + required: false |
| 28 | + default: 'true' |
| 29 | + |
| 30 | + python-version: |
| 31 | + description: 'Python version to use for installing bunenv' |
| 32 | + required: false |
| 33 | + default: '3.12' |
| 34 | + |
| 35 | +outputs: |
| 36 | + bun-version: |
| 37 | + description: 'The actual Bun version that was installed' |
| 38 | + value: ${{ steps.setup-bunenv.outputs.bun-version }} |
| 39 | + |
| 40 | + bunenv-path: |
| 41 | + description: 'Path to the bunenv environment directory' |
| 42 | + value: ${{ steps.setup-bunenv.outputs.bunenv-path }} |
| 43 | + |
| 44 | +runs: |
| 45 | + using: 'composite' |
| 46 | + steps: |
| 47 | + - name: Set up Python |
| 48 | + uses: actions/setup-python@v5 |
| 49 | + with: |
| 50 | + python-version: ${{ inputs.python-version }} |
| 51 | + |
| 52 | + - name: Get bunenv cache key |
| 53 | + if: inputs.cache == 'true' |
| 54 | + id: cache-key |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + echo "key=bunenv-${{ runner.os }}-${{ runner.arch }}-${{ inputs.bun-version }}-${{ inputs.variant }}" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Cache bunenv installation |
| 60 | + if: inputs.cache == 'true' |
| 61 | + uses: actions/cache@v4 |
| 62 | + with: |
| 63 | + path: ~/.bunenv-cache |
| 64 | + key: ${{ steps.cache-key.outputs.key }} |
| 65 | + restore-keys: | |
| 66 | + bunenv-${{ runner.os }}-${{ runner.arch }}-${{ inputs.bun-version }}- |
| 67 | + bunenv-${{ runner.os }}-${{ runner.arch }}- |
| 68 | +
|
| 69 | + - name: Install bunenv |
| 70 | + shell: bash |
| 71 | + run: | |
| 72 | + echo "::group::Installing bunenv" |
| 73 | + pip install bunenv |
| 74 | + echo "::endgroup::" |
| 75 | +
|
| 76 | + - name: Setup Bun environment |
| 77 | + id: setup-bunenv |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + echo "::group::Creating Bun environment" |
| 81 | +
|
| 82 | + # Set environment path |
| 83 | + BUNENV_PATH="${HOME}/.bunenv-cache/bunenv-${{ inputs.bun-version }}" |
| 84 | + echo "bunenv-path=${BUNENV_PATH}" >> $GITHUB_OUTPUT |
| 85 | +
|
| 86 | + # Create environment if it doesn't exist |
| 87 | + if [ ! -d "${BUNENV_PATH}" ]; then |
| 88 | + echo "Creating new bunenv environment at ${BUNENV_PATH}" |
| 89 | +
|
| 90 | + # Build bunenv command |
| 91 | + BUNENV_CMD="bunenv ${BUNENV_PATH} --bun=${{ inputs.bun-version }}" |
| 92 | +
|
| 93 | + # Add variant if specified |
| 94 | + if [ -n "${{ inputs.variant }}" ]; then |
| 95 | + BUNENV_CMD="${BUNENV_CMD} --variant=${{ inputs.variant }}" |
| 96 | + fi |
| 97 | +
|
| 98 | + # Add GitHub token if specified |
| 99 | + if [ -n "${{ inputs.github-token }}" ]; then |
| 100 | + BUNENV_CMD="${BUNENV_CMD} --github-token=${{ inputs.github-token }}" |
| 101 | + fi |
| 102 | +
|
| 103 | + # Run bunenv |
| 104 | + ${BUNENV_CMD} |
| 105 | + else |
| 106 | + echo "Using cached bunenv environment at ${BUNENV_PATH}" |
| 107 | + fi |
| 108 | +
|
| 109 | + echo "::endgroup::" |
| 110 | +
|
| 111 | + - name: Activate Bun environment |
| 112 | + shell: bash |
| 113 | + run: | |
| 114 | + echo "::group::Activating Bun environment" |
| 115 | +
|
| 116 | + BUNENV_PATH="${HOME}/.bunenv-cache/bunenv-${{ inputs.bun-version }}" |
| 117 | +
|
| 118 | + # Add Bun to PATH |
| 119 | + if [ "$RUNNER_OS" = "Windows" ]; then |
| 120 | + echo "${BUNENV_PATH}/Scripts" >> $GITHUB_PATH |
| 121 | + else |
| 122 | + echo "${BUNENV_PATH}/bin" >> $GITHUB_PATH |
| 123 | + fi |
| 124 | +
|
| 125 | + # Set environment variables |
| 126 | + echo "BUN_VIRTUAL_ENV=${BUNENV_PATH}" >> $GITHUB_ENV |
| 127 | + echo "BUN_INSTALL=${BUNENV_PATH}" >> $GITHUB_ENV |
| 128 | +
|
| 129 | + echo "::endgroup::" |
| 130 | +
|
| 131 | + - name: Verify Bun installation |
| 132 | + id: verify-bun |
| 133 | + shell: bash |
| 134 | + run: | |
| 135 | + echo "::group::Verifying Bun installation" |
| 136 | +
|
| 137 | + # Verify bun is in PATH |
| 138 | + which bun || (echo "::error::Bun not found in PATH" && exit 1) |
| 139 | +
|
| 140 | + # Get and output version |
| 141 | + BUN_VERSION=$(bun --version) |
| 142 | + echo "Installed Bun version: ${BUN_VERSION}" |
| 143 | + echo "bun-version=${BUN_VERSION}" >> $GITHUB_OUTPUT |
| 144 | +
|
| 145 | + # Test bun works |
| 146 | + bun --help > /dev/null || (echo "::error::Bun is not working correctly" && exit 1) |
| 147 | +
|
| 148 | + echo "::endgroup::" |
0 commit comments