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