diff --git a/README.md b/README.md index e9d3eba..aed1a8d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Bricks Shared GitHub Actions -Reusable composite actions for AWS infrastructure automation with database access via EC2 bastion. +Reusable composite actions for AWS infrastructure automation, development environment setup, and CI/CD workflows. ## Usage @@ -541,6 +541,49 @@ jobs: actor-email: ${{ github.event.pusher.email || format('{0}@users.noreply.github.com', github.actor) }} ``` +### 9. setup-bun-with-dependencies + +Sets up Bun runtime, caches dependencies, and installs packages with frozen lockfile. Optimized for CI/CD pipelines with intelligent caching. + +**Features:** +- Installs specified Bun version (or latest) +- Caches Bun install cache and node_modules for faster builds +- Installs dependencies with `--frozen-lockfile` for reproducible builds +- Supports custom working directories for monorepo setups + +**Inputs:** +- `bun-version` (optional): Bun version to install (default: `1.3.0`) +- `working-directory` (optional): Working directory where package.json is located (default: `.`) + +**Example:** +```yaml +- name: Setup Bun and install dependencies + uses: withBricks/github-actions/setup-bun-with-dependencies@v1 + with: + bun-version: 1.3.0 + working-directory: . + +- name: Build project + run: bun run build +``` + +**Monorepo Example:** +```yaml +- name: Setup Bun for backend + uses: withBricks/github-actions/setup-bun-with-dependencies@v1 + with: + bun-version: 1.3.0 + working-directory: apps/backend + +- name: Build backend + working-directory: apps/backend + run: bun run build +``` + +**Requirements:** +- Project must have a `bun.lockb` lockfile +- `package.json` must exist in the working directory + ## Security Considerations ### Password Security diff --git a/examples/bun-build-workflow.yml b/examples/bun-build-workflow.yml new file mode 100644 index 0000000..518327c --- /dev/null +++ b/examples/bun-build-workflow.yml @@ -0,0 +1,55 @@ +# Example workflow for using setup-bun-with-dependencies action +# Copy this to your repository and customize as needed + +name: Build with Bun + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Bun and install dependencies + uses: withBricks/github-actions/setup-bun-with-dependencies@v1 + with: + bun-version: 1.3.0 + + - name: Run tests + run: bun test + + - name: Build project + run: bun run build + + - name: Lint code + run: bun run lint + + # Example for monorepo with multiple packages + build-monorepo: + runs-on: ubuntu-latest + strategy: + matrix: + package: [backend, frontend, shared] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Bun for ${{ matrix.package }} + uses: withBricks/github-actions/setup-bun-with-dependencies@v1 + with: + bun-version: 1.3.0 + working-directory: packages/${{ matrix.package }} + + - name: Build ${{ matrix.package }} + working-directory: packages/${{ matrix.package }} + run: bun run build + + - name: Test ${{ matrix.package }} + working-directory: packages/${{ matrix.package }} + run: bun test diff --git a/setup-bun-with-dependencies/action.yml b/setup-bun-with-dependencies/action.yml new file mode 100644 index 0000000..49eafe3 --- /dev/null +++ b/setup-bun-with-dependencies/action.yml @@ -0,0 +1,38 @@ +name: 'Setup Bun with Dependencies' +description: 'Setup Bun runtime, cache dependencies, and install packages with frozen lockfile' + +inputs: + bun-version: + description: 'Bun version to install' + required: false + default: '1.3.0' + working-directory: + description: 'Working directory where package.json is located' + required: false + default: '.' + +runs: + using: composite + steps: + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: ${{ inputs.bun-version }} + + - name: Cache Bun dependencies + uses: actions/cache@v4 + with: + path: | + ~/.bun/install/cache + ${{ inputs.working-directory }}/node_modules + key: ${{ runner.os }}-bun-${{ inputs.bun-version }}-${{ hashFiles(format('{0}/bun.lockb', inputs.working-directory)) }} + restore-keys: | + ${{ runner.os }}-bun-${{ inputs.bun-version }}- + + - name: Install dependencies + shell: bash + working-directory: ${{ inputs.working-directory }} + run: | + echo "Installing dependencies with frozen lockfile..." + bun install --frozen-lockfile + echo "Dependencies installed successfully"