This repository was archived by the owner on Feb 3, 2026. It is now read-only.
Goddamn it I thought of something #385
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build NextJS Site | |
| on: | |
| push: | |
| branches: ["main"] | |
| paths-ignore: | |
| - '**/*.md' | |
| - 'docs/**' | |
| pull_request: | |
| branches: ["main", "develop"] | |
| paths-ignore: | |
| - '**/*.md' | |
| - 'docs/**' | |
| # Set minimal permissions (security best practice) | |
| permissions: {} | |
| # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
| # Improved to cancel in-progress PR builds but preserve main builds | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | |
| jobs: | |
| # Detect file changes to optimize what jobs run | |
| changes: | |
| runs-on: ubuntu-latest | |
| # Grant permissions to create check runs (needed for action outputs) | |
| permissions: | |
| checks: read | |
| contents: read | |
| pull-requests: read | |
| outputs: | |
| code: ${{ steps.filter.outputs.code }} | |
| styles: ${{ steps.filter.outputs.styles }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dorny/paths-filter@v3 | |
| id: filter | |
| with: | |
| filters: | | |
| code: | |
| - '**/*.{js,jsx,ts,tsx}' | |
| - 'package.json' | |
| - 'package-lock.json' | |
| - 'yarn.lock' | |
| styles: | |
| - '**/*.{css,scss}' | |
| - 'tailwind.config.{js,ts}' | |
| # Build job | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: [changes] | |
| if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'pull_request' }} | |
| timeout-minutes: 15 | |
| # Grant specific permissions needed for build job | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Detect package manager | |
| id: detect-package-manager | |
| run: | | |
| if [ -f "${{ github.workspace }}/yarn.lock" ]; then | |
| echo "manager=yarn" >> $GITHUB_OUTPUT | |
| echo "command=install" >> $GITHUB_OUTPUT | |
| echo "runner=yarn" >> $GITHUB_OUTPUT | |
| exit 0 | |
| elif [ -f "${{ github.workspace }}/package.json" ]; then | |
| echo "manager=npm" >> $GITHUB_OUTPUT | |
| echo "command=ci" >> $GITHUB_OUTPUT | |
| echo "runner=npx --no-install" >> $GITHUB_OUTPUT | |
| exit 0 | |
| else | |
| echo "Unable to determine package manager" | |
| exit 1 | |
| fi | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: ${{ steps.detect-package-manager.outputs.manager }} | |
| # Optimized caching strategy | |
| - name: Cache node_modules | |
| uses: actions/cache@v4 | |
| id: node-modules-cache | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-${{ steps.detect-package-manager.outputs.manager }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-v2 | |
| - name: Restore Next.js build cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| .next/cache | |
| # Generate a new cache whenever packages or source files change. | |
| key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} | |
| # If source files changed but packages didn't, rebuild from a prior cache. | |
| restore-keys: | | |
| ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- | |
| - name: Install dependencies | |
| if: steps.node-modules-cache.outputs.cache-hit != 'true' | |
| run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} --no-audit --force | |
| - name: Add Amplify outputs file | |
| run: touch amplify_outputs.json | |
| - name: Populate Amplify outputs file | |
| run: echo "{}" > amplify_outputs.json | |
| - name: Build with Next.js | |
| run: ${{ steps.detect-package-manager.outputs.runner }} next build | |
| env: | |
| NODE_OPTIONS: --max-old-space-size=4096 --no-deprecation | |
| # Test job | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: [changes] | |
| if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'pull_request' }} | |
| # Grant specific permissions needed for test job | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Detect package manager | |
| id: detect-package-manager | |
| run: | | |
| if [ -f "${{ github.workspace }}/yarn.lock" ]; then | |
| echo "manager=yarn" >> $GITHUB_OUTPUT | |
| echo "command=install" >> $GITHUB_OUTPUT | |
| echo "runner=yarn" >> $GITHUB_OUTPUT | |
| exit 0 | |
| elif [ -f "${{ github.workspace }}/package.json" ]; then | |
| echo "manager=npm" >> $GITHUB_OUTPUT | |
| echo "command=ci" >> $GITHUB_OUTPUT | |
| echo "runner=npx --no-install" >> $GITHUB_OUTPUT | |
| exit 0 | |
| else | |
| echo "Unable to determine package manager" | |
| exit 1 | |
| fi | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: ${{ steps.detect-package-manager.outputs.manager }} | |
| - name: Cache node_modules | |
| uses: actions/cache@v4 | |
| id: node-modules-cache | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-${{ steps.detect-package-manager.outputs.manager }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-v2 | |
| - name: Install dependencies | |
| if: steps.node-modules-cache.outputs.cache-hit != 'true' | |
| run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} --no-audit --force | |
| - name: Add Amplify outputs file | |
| run: touch amplify_outputs.json | |
| - name: Populate Amplify outputs file | |
| run: echo "{}" > amplify_outputs.json | |
| - name: Run unit tests (excluding E2E tests) | |
| run: ${{ steps.detect-package-manager.outputs.manager }} test -- --testPathIgnorePatterns="e2e" | |
| - name: Display E2E test instructions | |
| run: | | |
| echo "========== E2E TESTS SHOULD BE RUN MANUALLY ==========" | |
| echo "As requested, E2E tests are excluded from CI and should be run manually by developers" | |
| echo "To run E2E tests locally, use: npx playwright test" | |
| echo "======================================================" |