|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["master"] |
| 6 | + pull_request: |
| 7 | + branches: ["master"] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ci-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: build |
| 19 | + runs-on: ubuntu-latest |
| 20 | + # Dummy build-time env so steps like `next build` that read env at build |
| 21 | + # succeed in CI (same approach as portfolio-nextjs). Add this repo's |
| 22 | + # build-time vars here with placeholder values. |
| 23 | + env: |
| 24 | + CI: "true" |
| 25 | + NEXT_PUBLIC_GITHUB_TOKEN: dummy-token-for-build |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v6 |
| 28 | + with: |
| 29 | + persist-credentials: false |
| 30 | + |
| 31 | + # Detect the package manager from the lockfile so one workflow serves |
| 32 | + # pnpm / npm / yarn / bun repos. |
| 33 | + - name: Detect package manager |
| 34 | + id: pm |
| 35 | + run: | |
| 36 | + if [ -f bun.lockb ] || [ -f bun.lock ]; then echo "pm=bun" >> "$GITHUB_OUTPUT" |
| 37 | + elif [ -f pnpm-lock.yaml ]; then echo "pm=pnpm" >> "$GITHUB_OUTPUT" |
| 38 | + elif [ -f yarn.lock ]; then echo "pm=yarn" >> "$GITHUB_OUTPUT" |
| 39 | + else echo "pm=npm" >> "$GITHUB_OUTPUT"; fi |
| 40 | +
|
| 41 | + - if: steps.pm.outputs.pm == 'pnpm' |
| 42 | + uses: pnpm/action-setup@v4 |
| 43 | + with: |
| 44 | + version: 9 |
| 45 | + - if: steps.pm.outputs.pm == 'bun' |
| 46 | + uses: oven-sh/setup-bun@v2 |
| 47 | + - if: steps.pm.outputs.pm != 'bun' |
| 48 | + uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: lts/* |
| 51 | + cache: ${{ steps.pm.outputs.pm }} |
| 52 | + |
| 53 | + - name: Install |
| 54 | + run: | |
| 55 | + case "${{ steps.pm.outputs.pm }}" in |
| 56 | + bun) bun install --frozen-lockfile ;; |
| 57 | + pnpm) pnpm install --frozen-lockfile ;; |
| 58 | + yarn) yarn install --frozen-lockfile ;; |
| 59 | + npm) npm ci ;; |
| 60 | + esac |
| 61 | +
|
| 62 | + # Run a script only if package.json defines it, so repos missing lint/ |
| 63 | + # build/test don't fail the job. `run_if` echoes then runs via the pm. |
| 64 | + - name: Run available scripts (lint, ts:check, build, test) |
| 65 | + env: |
| 66 | + PM: ${{ steps.pm.outputs.pm }} |
| 67 | + run: | |
| 68 | + has() { jq -e --arg s "$1" '.scripts[$s] // empty' package.json >/dev/null 2>&1; } |
| 69 | + run() { |
| 70 | + case "$PM" in |
| 71 | + bun) bun run "$1" ;; |
| 72 | + *) "$PM" run "$1" ;; |
| 73 | + esac |
| 74 | + } |
| 75 | + for script in lint ts:check typecheck build test; do |
| 76 | + if has "$script"; then |
| 77 | + echo "::group::$script"; run "$script"; echo "::endgroup::" |
| 78 | + else |
| 79 | + echo "skip: no \"$script\" script" |
| 80 | + fi |
| 81 | + done |
0 commit comments