|
1 | | -name: Deploy Next.js site to Pages |
| 1 | +name: Deploy |
2 | 2 |
|
3 | 3 | on: |
4 | | - # Runs on pushes targeting the main branch |
5 | 4 | push: |
6 | 5 | branches: |
7 | 6 | - main |
8 | 7 |
|
9 | | - # Allows you to run this workflow manually from the Actions tab |
10 | | - workflow_dispatch: |
11 | | - |
12 | | -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
13 | | -permissions: |
14 | | - contents: read |
15 | | - pages: write |
16 | | - id-token: write |
17 | | - |
18 | | -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
19 | | -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
20 | | -concurrency: |
21 | | - group: "pages" |
22 | | - cancel-in-progress: false |
23 | | - |
24 | 8 | jobs: |
25 | 9 | build: |
| 10 | + name: Build |
26 | 11 | runs-on: ubuntu-latest |
27 | | - steps: |
28 | | - - name: Checkout |
29 | | - uses: actions/checkout@v4 |
30 | 12 |
|
31 | | - - uses: pnpm/action-setup@v4 |
32 | | - name: Install pnpm |
33 | | - with: |
34 | | - version: 10 |
35 | | - run_install: false |
| 13 | + steps: |
| 14 | + - name: Checkout repo |
| 15 | + uses: actions/checkout@v3 |
36 | 16 |
|
37 | | - - name: Install Node.js |
38 | | - uses: actions/setup-node@v4 |
39 | | - with: |
40 | | - node-version: 22 |
41 | | - cache: "pnpm" |
| 17 | + - name: Setup Node |
| 18 | + uses: actions/setup-node@v3 |
42 | 19 |
|
43 | 20 | - name: Install dependencies |
44 | | - run: pnpm install |
| 21 | + uses: bahmutov/npm-install@v1 |
45 | 22 |
|
46 | | - - name: Setup Pages |
47 | | - id: setup_pages |
48 | | - uses: actions/configure-pages@v5 |
| 23 | + - name: Build project |
| 24 | + run: npm run build |
49 | 25 |
|
50 | | - - name: Restore cache |
51 | | - uses: actions/cache@v4 |
52 | | - with: |
53 | | - path: | |
54 | | - .next/cache |
55 | | - # Generate a new cache whenever packages or source files change. |
56 | | - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} |
57 | | - # If source files changed but packages didn't, rebuild from a prior cache. |
58 | | - restore-keys: | |
59 | | - ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}- |
60 | | -
|
61 | | - - name: Build with Next.js |
62 | | - run: pnpm run build |
63 | | - env: |
64 | | - PAGES_BASE_PATH: ${{ steps.setup_pages.outputs.base_path }} |
65 | | - |
66 | | - - name: Upload artifact |
67 | | - uses: actions/upload-pages-artifact@v3 |
| 26 | + - name: Upload production-ready build files |
| 27 | + uses: actions/upload-artifact@v4 |
68 | 28 | with: |
| 29 | + name: production-files |
69 | 30 | path: ./out |
70 | 31 |
|
71 | 32 | deploy: |
72 | | - environment: |
73 | | - name: github-pages |
74 | | - url: ${{ steps.deployment.outputs.page_url }} |
75 | | - runs-on: ubuntu-latest |
| 33 | + name: Deploy |
76 | 34 | needs: build |
| 35 | + runs-on: ubuntu-latest |
| 36 | + if: github.ref == 'refs/heads/main' |
| 37 | + |
77 | 38 | steps: |
| 39 | + - name: Download artifact |
| 40 | + uses: actions/download-artifact@v4 |
| 41 | + with: |
| 42 | + name: production-files |
| 43 | + path: ./out |
| 44 | + |
78 | 45 | - name: Deploy to GitHub Pages |
79 | | - id: deployment |
80 | | - uses: actions/deploy-pages@v4 |
| 46 | + uses: peaceiris/actions-gh-pages@v3 |
| 47 | + with: |
| 48 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + publish_dir: ./out |
0 commit comments