|
1 |
| -# Workflow for deploying static content to GitHub Pages |
2 |
| -name: Deploy static content to GitHub Pages |
| 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 | +name: Deploy Next.js site to Pages |
3 | 6 |
|
4 | 7 | on:
|
5 |
| - # Trigger workflow on push to the main branch |
| 8 | + # Runs on pushes targeting the default branch |
6 | 9 | push:
|
7 |
| - branches: |
8 |
| - - main |
| 10 | + branches: ["main"] |
9 | 11 |
|
10 |
| - # Allow manual trigger of the workflow through the Actions tab |
| 12 | + # Allows you to run this workflow manually from the Actions tab |
11 | 13 | workflow_dispatch:
|
12 | 14 |
|
| 15 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
13 | 16 | permissions:
|
14 |
| - # Set required permissions for deployment |
15 | 17 | contents: read
|
16 | 18 | pages: write
|
17 | 19 | id-token: write
|
18 | 20 |
|
| 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. |
19 | 23 | concurrency:
|
20 |
| - # Allow only one deployment at a time, cancel in-progress deployments |
21 |
| - group: 'github-pages-deployment' |
22 |
| - cancel-in-progress: true |
| 24 | + group: "pages" |
| 25 | + cancel-in-progress: false |
23 | 26 |
|
24 | 27 | jobs:
|
25 |
| - deploy: |
26 |
| - # Define the target deployment environment |
27 |
| - environment: |
28 |
| - name: github-pages |
29 |
| - url: ${{ steps.deployment.outputs.page_url }} |
| 28 | + # Build job |
| 29 | + build: |
30 | 30 | runs-on: ubuntu-latest
|
31 |
| - |
32 | 31 | steps:
|
33 |
| - # Step 1: Check out the repository |
34 |
| - - name: Check out the code |
| 32 | + - name: Checkout |
35 | 33 | uses: actions/checkout@v4
|
36 |
| - with: |
37 |
| - fetch-depth: 1 |
38 |
| - |
39 |
| - # Step 2: Set up Node.js environment |
40 |
| - - name: Set up Node.js |
| 34 | + - name: Detect package manager |
| 35 | + id: detect-package-manager |
| 36 | + run: | |
| 37 | + if [ -f "${{ github.workspace }}/yarn.lock" ]; then |
| 38 | + echo "manager=yarn" >> $GITHUB_OUTPUT |
| 39 | + echo "command=install" >> $GITHUB_OUTPUT |
| 40 | + echo "runner=yarn" >> $GITHUB_OUTPUT |
| 41 | + exit 0 |
| 42 | + elif [ -f "${{ github.workspace }}/package.json" ]; then |
| 43 | + echo "manager=npm" >> $GITHUB_OUTPUT |
| 44 | + echo "command=ci" >> $GITHUB_OUTPUT |
| 45 | + echo "runner=npx --no-install" >> $GITHUB_OUTPUT |
| 46 | + exit 0 |
| 47 | + else |
| 48 | + echo "Unable to determine package manager" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + - name: Setup Node |
41 | 52 | uses: actions/setup-node@v4
|
42 | 53 | with:
|
43 |
| - node-version: 20 |
44 |
| - cache: npm |
45 |
| - |
46 |
| - # Step 3: Install dependencies |
47 |
| - - name: Install project dependencies |
48 |
| - run: npm ci |
49 |
| - |
50 |
| - # Step 4: Build the project |
51 |
| - - name: Build the project |
52 |
| - run: npm run build |
53 |
| - |
54 |
| - # Step 5: Configure GitHub Pages |
55 |
| - - name: Configure GitHub Pages |
56 |
| - uses: actions/configure-pages@v4 |
57 |
| - |
58 |
| - # Step 6: Upload build artifacts |
59 |
| - - name: Upload build artifacts |
| 54 | + node-version: "20" |
| 55 | + cache: ${{ steps.detect-package-manager.outputs.manager }} |
| 56 | + - name: Setup Pages |
| 57 | + uses: actions/configure-pages@v5 |
| 58 | + with: |
| 59 | + # Automatically inject basePath in your Next.js configuration file and disable |
| 60 | + # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized). |
| 61 | + # |
| 62 | + # You may remove this line if you want to manage the configuration yourself. |
| 63 | + static_site_generator: next |
| 64 | + - name: Restore cache |
| 65 | + uses: actions/cache@v4 |
| 66 | + with: |
| 67 | + path: | |
| 68 | + .next/cache |
| 69 | + # Generate a new cache whenever packages or source files change. |
| 70 | + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} |
| 71 | + # If source files changed but packages didn't, rebuild from a prior cache. |
| 72 | + restore-keys: | |
| 73 | + ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- |
| 74 | + - name: Install dependencies |
| 75 | + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} |
| 76 | + - name: Build with Next.js |
| 77 | + run: ${{ steps.detect-package-manager.outputs.runner }} next build |
| 78 | + - name: Upload artifact |
60 | 79 | uses: actions/upload-pages-artifact@v3
|
61 | 80 | with:
|
62 |
| - path: ./dist |
| 81 | + path: ./out |
63 | 82 |
|
64 |
| - # Step 7: Deploy to GitHub Pages |
| 83 | + # Deployment job |
| 84 | + deploy: |
| 85 | + environment: |
| 86 | + name: github-pages |
| 87 | + url: ${{ steps.deployment.outputs.page_url }} |
| 88 | + runs-on: ubuntu-latest |
| 89 | + needs: build |
| 90 | + steps: |
65 | 91 | - name: Deploy to GitHub Pages
|
66 | 92 | id: deployment
|
67 | 93 | uses: actions/deploy-pages@v4
|
0 commit comments