Skip to content

Commit 7c0c6b2

Browse files
authored
Merge pull request #7 from JacobCoffee/feat/add-bunenv-github-action
2 parents c511967 + 4271243 commit 7c0c6b2

File tree

3 files changed

+203
-2
lines changed

3 files changed

+203
-2
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,42 @@ jobs:
170170
- name: Run ty
171171
uses: JacobCoffee/ty-action@v0.0.1
172172

173+
# Test the bunenv GitHub Action
174+
action-test:
175+
name: Test bunenv action on ${{ matrix.os }}
176+
runs-on: ${{ matrix.os }}
177+
strategy:
178+
fail-fast: false
179+
matrix:
180+
os: [ubuntu-latest, macos-latest, windows-latest]
181+
bun-version: ['latest', '1.3.3']
182+
183+
steps:
184+
- uses: actions/checkout@v4
185+
186+
- name: Test bunenv action
187+
uses: ./
188+
with:
189+
bun-version: ${{ matrix.bun-version }}
190+
github-token: ${{ secrets.GITHUB_TOKEN }}
191+
192+
- name: Verify Bun installation
193+
run: |
194+
bun --version
195+
bun --help
196+
shell: bash
197+
198+
- name: Test Bun functionality
199+
run: |
200+
echo '{"name": "test", "version": "1.0.0"}' > package.json
201+
bun install
202+
bun --version
203+
shell: bash
204+
173205
build:
174206
name: Build package
175207
runs-on: ubuntu-latest
176-
needs: [test, smoke-test, integration-test, lint, type-check]
208+
needs: [test, smoke-test, integration-test, lint, type-check, action-test]
177209

178210
steps:
179211
- uses: actions/checkout@v4

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,29 @@ source .bunenv/bin/activate
112112

113113
### CI/CD Integration
114114

115+
#### GitHub Actions (Recommended)
116+
117+
Use the official bunenv GitHub Action for the simplest setup:
118+
119+
```yaml
120+
# Use the bunenv action (easiest!)
121+
- name: Setup Bun
122+
uses: JacobCoffee/bunenv@v1
123+
with:
124+
bun-version: '1.3.3'
125+
126+
- name: Build and test
127+
run: |
128+
bun install
129+
bun test
130+
```
131+
132+
See [ACTION.md](ACTION.md) for complete documentation and advanced usage.
133+
134+
#### Manual Setup
135+
115136
```yaml
116-
# GitHub Actions example
137+
# Manual installation
117138
- name: Setup Bun environment
118139
run: |
119140
pip install bunenv

action.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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

Comments
 (0)