|
1 | | -name: Deploy to GitHub Pages |
| 1 | +name: Deploy Next.js site to Pages |
2 | 2 |
|
3 | 3 | on: |
4 | | - # Trigger the workflow every time you push to the `main` branch |
5 | | - # Using a different branch name? Replace `main` with your branch’s name |
| 4 | + # Runs on pushes targeting the default branch |
6 | 5 | push: |
7 | | - branches: [main] |
8 | | - # Allows you to run this workflow manually from the Actions tab on GitHub. |
| 6 | + branches: ["main"] |
| 7 | + |
| 8 | + # Allows you to run this workflow manually from the Actions tab |
9 | 9 | workflow_dispatch: |
10 | 10 |
|
11 | | -# Allow this job to clone the repo and create a page deployment |
| 11 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
12 | 12 | permissions: |
13 | 13 | contents: read |
14 | 14 | pages: write |
15 | 15 | id-token: write |
16 | 16 |
|
| 17 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 18 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 19 | +concurrency: |
| 20 | + group: "pages" |
| 21 | + cancel-in-progress: false |
| 22 | + |
17 | 23 | jobs: |
| 24 | + # Build job |
18 | 25 | build: |
19 | 26 | runs-on: ubuntu-latest |
20 | 27 | steps: |
21 | | - - name: Checkout your repository using git |
| 28 | + - name: Checkout |
22 | 29 | uses: actions/checkout@v4 |
23 | | - - name: Install, build, and upload your site output |
24 | | - uses: withastro/action@v2 |
25 | | - # with: |
26 | | - # path: . # The root location of your Astro project inside the repository. (optional) |
27 | | - # node-version: 20 # The specific version of Node that should be used to build your site. Defaults to 18. (optional) |
28 | | - # package-manager: pnpm@latest # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional) |
29 | 30 |
|
| 31 | + - name: Detect package manager |
| 32 | + id: detect-package-manager |
| 33 | + run: | |
| 34 | + if [ -f "${{ github.workspace }}/yarn.lock" ]; then |
| 35 | + echo "manager=yarn" >> $GITHUB_OUTPUT |
| 36 | + echo "command=install" >> $GITHUB_OUTPUT |
| 37 | + echo "runner=yarn" >> $GITHUB_OUTPUT |
| 38 | + exit 0 |
| 39 | + elif [ -f "${{ github.workspace }}/package.json" ]; then |
| 40 | + echo "manager=npm" >> $GITHUB_OUTPUT |
| 41 | + echo "command=ci" >> $GITHUB_OUTPUT |
| 42 | + echo "runner=npx --no-install" >> $GITHUB_OUTPUT |
| 43 | + exit 0 |
| 44 | + else |
| 45 | + echo "Unable to determine package manager" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Setup Node |
| 50 | + uses: actions/setup-node@v4 |
| 51 | + with: |
| 52 | + node-version: "lts/*" |
| 53 | + cache: ${{ steps.detect-package-manager.outputs.manager }} |
| 54 | + |
| 55 | + - name: Setup Pages |
| 56 | + uses: actions/configure-pages@v4 |
| 57 | + |
| 58 | + - name: Restore cache |
| 59 | + uses: actions/cache@v4 |
| 60 | + with: |
| 61 | + path: | |
| 62 | + .next/cache |
| 63 | + # Generate a new cache whenever packages or source files change. |
| 64 | + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} |
| 65 | + # If source files changed but packages didn't, rebuild from a prior cache. |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- |
| 68 | +
|
| 69 | + - name: Install dependencies |
| 70 | + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} |
| 71 | + |
| 72 | + - name: Build with Next.js |
| 73 | + env: |
| 74 | + NEXT_PUBLIC_PROXY_URL: "https://classcharts-proxy.veloi.workers.dev" |
| 75 | + run: ${{ steps.detect-package-manager.outputs.runner }} next build |
| 76 | + |
| 77 | + - name: Upload artifact |
| 78 | + uses: actions/upload-pages-artifact@v3 |
| 79 | + with: |
| 80 | + path: ./out |
| 81 | + |
| 82 | + # Deployment job |
30 | 83 | deploy: |
31 | | - needs: build |
32 | | - runs-on: ubuntu-latest |
33 | 84 | environment: |
34 | 85 | name: github-pages |
35 | 86 | url: ${{ steps.deployment.outputs.page_url }} |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: build |
36 | 89 | steps: |
37 | 90 | - name: Deploy to GitHub Pages |
38 | 91 | id: deployment |
|
0 commit comments