Skip to content

Commit 729170a

Browse files
committed
add gh action
1 parent fe9600f commit 729170a

File tree

1 file changed

+68
-15
lines changed

1 file changed

+68
-15
lines changed

.github/workflows/deploy.yml

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,91 @@
1-
name: Deploy to GitHub Pages
1+
name: Deploy Next.js site to Pages
22

33
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
65
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
99
workflow_dispatch:
1010

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
1212
permissions:
1313
contents: read
1414
pages: write
1515
id-token: write
1616

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+
1723
jobs:
24+
# Build job
1825
build:
1926
runs-on: ubuntu-latest
2027
steps:
21-
- name: Checkout your repository using git
28+
- name: Checkout
2229
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)
2930

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
3083
deploy:
31-
needs: build
32-
runs-on: ubuntu-latest
3384
environment:
3485
name: github-pages
3586
url: ${{ steps.deployment.outputs.page_url }}
87+
runs-on: ubuntu-latest
88+
needs: build
3689
steps:
3790
- name: Deploy to GitHub Pages
3891
id: deployment

0 commit comments

Comments
 (0)