Repository navigation
132 lines (116 loc) · 3.97 KB
/
Copy pathdeploy.yml
File metadata and controls
132 lines (116 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Deploy to GitHub Pages
on:
push:
分支: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect package manager and project dir
id: detect
run: |
if [ -f "package.json" ]; then
ROOT="."
elif [ -f "frontend/package.json" ]; then
ROOT="frontend"
elif [ -f "app/package.json" ]; then
ROOT="app"
elif [ -f "web/package.json" ]; then
ROOT="web"
else
ROOT=$(find . -maxdepth 3 -name package.json -not -path "*/node_modules/*" | head -n1 | xargs -r dirname)
[ -z "$ROOT" ] && ROOT="."
fi
echo "root=$ROOT" >> $GITHUB_OUTPUT
if [ -f "$ROOT/pnpm-lock.yaml" ]; then
PM="pnpm"; LOCK="$ROOT/pnpm-lock.yaml"
elif [ -f "$ROOT/yarn.lock" ]; then
PM="yarn"; LOCK="$ROOT/yarn.lock"
elif [ -f "$ROOT/package-lock.json" ]; then
PM="npm"; LOCK="$ROOT/package-lock.json"
elif [ -f "$ROOT/package.json" ]; then
PM="npm"; LOCK="" # 有 package.json 但无锁文件
else
PM="none"; LOCK=""
fi
echo "pm=$PM" >> $GITHUB_OUTPUT
echo "lock=$LOCK" >> $GITHUB_OUTPUT
echo "Detected: root=$ROOT, pm=$PM, lock=$LOCK"
- name: Setup pnpm
if: steps.detect.outputs.pm == 'pnpm'
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node (with cache)
if: steps.detect.outputs.lock != ''
uses: actions/setup-node@v4
with:
node-version: 20
cache: ${{ steps.detect.outputs.pm }}
cache-dependency-path: ${{ steps.detect.outputs.lock }}
- name: Setup Node (no cache)
if: steps.detect.outputs.lock == ''
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
working-directory: ${{ steps.detect.outputs.root }}
run: |
case "${{ steps.detect.outputs.pm }}" in
pnpm) pnpm install --frozen-lockfile || pnpm install ;;
yarn) yarn install --frozen-lockfile || yarn install ;;
npm)
if [ -f package-lock.json ]; then npm ci; else npm install; fi
;;
*)
echo "No package.json found, skip install";;
esac
- name: Build
id: build
working-directory: ${{ steps.detect.outputs.root }}
run: |
if [ ! -f package.json ]; then
echo "No build step, using root as output"
echo "output=${{ steps.detect.outputs.root }}" >> $GITHUB_OUTPUT
exit 0
fi
if node -e "const s=require('./package.json').scripts||{}; process.exit(s.build?0:1)"; then
npm run build
elif node -e "const s=require('./package.json').scripts||{}; process.exit(s.docs:build?0:1)"; then
npm run docs:build
else
echo "No build script found"; exit 1
fi
for d in dist out build public _site docs/.vitepress/dist .vitepress/dist; do
if [ -d "$d" ]; then
echo "output=${{ steps.detect.outputs.root }}/$d" >> $GITHUB_OUTPUT
exit 0
fi
done
echo "output=${{ steps.detect.outputs.root }}" >> $GITHUB_OUTPUT
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ${{ steps.build.outputs.output }}
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4