-
Notifications
You must be signed in to change notification settings - Fork 4
180 lines (150 loc) · 5.78 KB
/
deploy-docs.yml
File metadata and controls
180 lines (150 loc) · 5.78 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Deploy Documentation
on:
push:
branches:
- main # 监听主分支推送
workflow_dispatch: # 手动触发
repository_dispatch:
types: [build_pages]
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# 2. 使用 GH_TOKEN 拉取私有仓库 TROLLSTORE
- name: Checkout Private TrollScript Repository
uses: actions/checkout@v4
with:
repository: ${{ secrets.TROLLSTORE }}
token: ${{ secrets.GH_TOKEN }}
path: TrollScript-Private
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
# 3. 生成 API 文档和 NPM 包
- name: Generate API Documentation and NPM Package
run: |
echo "📋 Generating API documentation..."
if [ -d "TrollScript-Private/JSModulesAPI" ]; then
# Generate API.md from split module directories
python3 TrollScript-Private/scripts/generate_api_docs.py TrollScript-Private/JSModulesAPI/zh ./API.md
python3 TrollScript-Private/scripts/generate_api_docs.py TrollScript-Private/JSModulesAPI/en ./API.en.md
echo "✅ Generated API.md and API.en.md"
# Generate NPM Package with auto-incrementing version
mkdir -p npm
# 获取当前 NPM 包的最新版本
CURRENT_VERSION=$(npm view @dompling/trollscript-types version 2>/dev/null || echo "1.0.0")
echo "📋 Current NPM version: $CURRENT_VERSION"
# 提取 patch 版本号并递增
PATCH_VERSION=$(echo $CURRENT_VERSION | cut -d. -f3)
NEW_PATCH=$((PATCH_VERSION + 1))
PACKAGE_VERSION="1.0.$NEW_PATCH"
echo "📋 New version: $PACKAGE_VERSION"
python3 TrollScript-Private/scripts/generate_npm_package.py TrollScript-Private/JSModulesAPI/zh ./npm $PACKAGE_VERSION
echo "✅ Generated NPM package (v$PACKAGE_VERSION) in npm/"
else
echo "⚠️ JSModulesAPI directory not found"
fi
# 检查 API 是否有变化
- name: Check if API changed
id: check_api
run: |
API_CHANGED="false"
# Check if API.md exists and has changes
if [ -f "API.md" ]; then
# Compare with git to see if there are changes
if ! git diff --quiet API.md 2>/dev/null; then
API_CHANGED="true"
fi
else
# If API.md doesn't exist yet, consider it as changed
API_CHANGED="true"
fi
echo "api_changed=$API_CHANGED" >> $GITHUB_OUTPUT
echo "📋 API changed: $API_CHANGED"
# 发布 NPM 包(仅在 API 有变化时)
- name: Publish NPM Package
if: success() && steps.check_api.outputs.api_changed == 'true'
continue-on-error: true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [ ! -d "npm" ]; then
echo "⚠️ Skipping NPM publish: Directory npm/ not found"
exit 0
fi
if [ -z "$NODE_AUTH_TOKEN" ]; then
echo "⚠️ Skipping NPM publish: NODE_AUTH_TOKEN is empty. Please check if NPM_TOKEN secret is set correctly."
exit 0
fi
cd npm
echo "📦 Publishing to NPM..."
# 尝试发布,捕获错误但不中断工作流
if npm publish --access public 2>&1; then
echo "✅ Published successfully"
else
echo "⚠️ NPM publish failed (version may already exist or token issue)"
echo "ℹ️ Continuing workflow..."
exit 0
fi
# 4. 复制私有仓库的文件到当前仓库
- name: Copy files from Private Repository
run: |
echo "📋 Starting file sync from private repository..."
# Sync templates directory
if [ -d "TrollScript-Private/templates" ]; then
rm -rf templates
cp -r TrollScript-Private/templates ./
echo "✅ Synced templates/"
else
echo "⚠️ templates/ not found in private repository"
fi
# Sync README.md
if [ -f "TrollScript-Private/templates/README.md" ]; then
cp TrollScript-Private/templates/README.md ./
echo "✅ Synced README.md"
else
echo "⚠️ README.md not found in private repository"
fi
# 5. 提交更改到当前仓库
- name: Commit and Push changes
if: success()
run: |
echo "📋 Checking for changes..."
# Check if there are changes
if [ -n "$(git status --porcelain)" ]; then
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git commit -m "🔄 Sync from private repository - $(date '+%Y-%m-%d %H:%M:%S')"
git push
echo "✅ Changes committed and pushed"
else
echo "ℹ️ No changes to commit"
fi
- name: Install dependencies
run: |
pip install mkdocs-material
- name: Prepare Workspace
run: |
mkdir -p docs
cp *.md docs/
cp templates/*.md docs/
cp templates/API/*.md docs/
cp -r AppIcon.png docs/
cp -r images docs/
cp -r CNAME docs/
- name: Build and Deploy
run: mkdocs gh-deploy --force