|
1 | | -# Sample workflow for building and deploying a Next.js site to GitHub Pages |
2 | | -# |
3 | | -# To get started with Next.js see: https://nextjs.org/docs/getting-started |
4 | | -# |
5 | 1 | name: Deploy Next.js site to Pages |
6 | 2 |
|
7 | 3 | on: |
8 | | - # Runs on pushes targeting the default branch |
9 | 4 | push: |
10 | 5 | branches: ["main"] |
11 | | - |
12 | | - # Allows you to run this workflow manually from the Actions tab |
13 | 6 | workflow_dispatch: |
14 | 7 |
|
15 | | -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
16 | 8 | permissions: |
17 | 9 | contents: read |
18 | 10 | pages: write |
19 | 11 | id-token: write |
20 | 12 |
|
21 | | -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
22 | | -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
23 | 13 | concurrency: |
24 | 14 | group: "pages" |
25 | 15 | cancel-in-progress: false |
26 | 16 |
|
27 | 17 | jobs: |
28 | | - # Build job |
29 | 18 | build: |
30 | 19 | runs-on: ubuntu-latest |
31 | 20 | env: |
32 | 21 | NEXT_TELEMETRY_DISABLED: 1 |
33 | 22 | steps: |
34 | 23 | - name: Checkout |
35 | 24 | uses: actions/checkout@v4 |
36 | | - - name: Detect package manager |
37 | | - id: detect-package-manager |
38 | | - run: | |
39 | | - if [ -f "${{ github.workspace }}/yarn.lock" ]; then |
40 | | - echo "manager=yarn" >> $GITHUB_OUTPUT |
41 | | - echo "command=install" >> $GITHUB_OUTPUT |
42 | | - echo "runner=yarn" >> $GITHUB_OUTPUT |
43 | | - exit 0 |
44 | | - elif [ -f "${{ github.workspace }}/package.json" ]; then |
45 | | - echo "manager=npm" >> $GITHUB_OUTPUT |
46 | | - echo "command=ci" >> $GITHUB_OUTPUT |
47 | | - echo "runner=npx --no-install" >> $GITHUB_OUTPUT |
48 | | - exit 0 |
49 | | - else |
50 | | - echo "Unable to determine package manager" |
51 | | - exit 1 |
52 | | - fi |
| 25 | + |
| 26 | + # Setup pnpm (v10) and Node.js |
| 27 | + - name: Setup pnpm |
| 28 | + uses: pnpm/action-setup@v4 |
| 29 | + with: |
| 30 | + version: 10 |
53 | 31 | - name: Setup Node |
54 | 32 | uses: actions/setup-node@v4 |
55 | 33 | with: |
56 | 34 | node-version: "20" |
57 | | - cache: ${{ steps.detect-package-manager.outputs.manager }} |
| 35 | + cache: "pnpm" |
| 36 | + |
58 | 37 | - name: Setup Pages |
59 | 38 | uses: actions/configure-pages@v5 |
60 | | - |
61 | | - - name: Restore cache |
| 39 | + |
| 40 | + # Cache Next.js build cache (separate from pnpm cache above) |
| 41 | + - name: Restore Next.js cache |
62 | 42 | uses: actions/cache@v4 |
63 | 43 | with: |
64 | 44 | path: | |
65 | 45 | .next/cache |
66 | | - # Generate a new cache whenever packages or source files change. |
67 | | - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} |
68 | | - # If source files changed but packages didn't, rebuild from a prior cache. |
| 46 | + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.[jt]s', '**/*.[jt]sx', '**/*.mdx') }} |
69 | 47 | restore-keys: | |
70 | | - ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- |
| 48 | + ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}- |
| 49 | +
|
71 | 50 | - name: Install dependencies |
72 | | - run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} |
| 51 | + run: pnpm install --frozen-lockfile |
| 52 | + |
73 | 53 | - name: Build with Next.js |
74 | | - run: ${{ steps.detect-package-manager.outputs.runner }} next build |
| 54 | + run: | |
| 55 | + pnpm run build |
| 56 | + pnpm exec next export |
| 57 | +
|
75 | 58 | - name: Upload artifact |
76 | 59 | uses: actions/upload-pages-artifact@v3 |
77 | 60 | with: |
78 | 61 | path: ./out |
79 | 62 |
|
80 | | - # Deployment job |
81 | 63 | deploy: |
82 | 64 | environment: |
83 | 65 | name: github-pages |
|
0 commit comments