name: Build and Test

on:
    push:
    pull_request:

jobs:
    build:
        name: Build and test code
        runs-on: ubuntu-latest

        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Setup bun
              uses: oven-sh/setup-bun@v1
              with:
                  bun-version: latest

            - name: Install packages
              run: bun install

            - name: Build code
              run: bun run build

            - name: Test
              run: bun run test

            - name: Publish Preview
              if: github.event_name == 'pull_request'
              run: bunx pkg-pr-new publish
