Skip to content

Commit 7323054

Browse files
author
dompling
committed
update
1 parent 7143452 commit 7323054

1 file changed

Lines changed: 123 additions & 0 deletions

File tree

.github/workflows/deploy-docs.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,133 @@ jobs:
2020
with:
2121
fetch-depth: 0
2222

23+
# 2. 使用 GH_TOKEN 拉取私有仓库 TROLLSTORE
24+
- name: Checkout Private TrollScript Repository
25+
uses: actions/checkout@v4
26+
with:
27+
repository: ${{ secrets.TROLLSTORE }}
28+
token: ${{ secrets.GH_TOKEN }}
29+
path: TrollScript-Private
30+
fetch-depth: 0
31+
2332
- name: Set up Python
2433
uses: actions/setup-python@v5
2534
with:
2635
python-version: 3.x
2736

37+
- name: Setup Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: '20.x'
41+
registry-url: 'https://registry.npmjs.org'
42+
43+
# 3. 生成 API 文档和 NPM 包
44+
- name: Generate API Documentation and NPM Package
45+
run: |
46+
echo "📋 Generating API documentation..."
47+
48+
if [ -f "TrollScript-Private/scripts/generate_api_docs.py" ] && [ -f "TrollScript-Private/TrollScript/Resources/JSModulesAPI.zh.json" ]; then
49+
# Generate API.md
50+
python3 TrollScript-Private/scripts/generate_api_docs.py TrollScript-Private/TrollScript/Resources/JSModulesAPI.zh.json ./API.md
51+
python3 TrollScript-Private/scripts/generate_api_docs.py TrollScript-Private/TrollScript/Resources/JSModulesAPI.en.json ./API.en.md
52+
echo "✅ Generated API.md and API.en.md"
53+
else
54+
echo "⚠️ API generation scripts or data files not found"
55+
fi
56+
57+
if [ -f "TrollScript-Private/scripts/generate_npm_package.py" ]; then
58+
# Generate NPM Package
59+
mkdir -p npm
60+
PACKAGE_VERSION="1.0.${{ github.run_number }}"
61+
python3 TrollScript-Private/scripts/generate_npm_package.py TrollScript-Private/TrollScript/Resources/JSModulesAPI.zh.json ./npm $PACKAGE_VERSION
62+
echo "✅ Generated NPM package (v$PACKAGE_VERSION) in npm/"
63+
else
64+
echo "⚠️ NPM package generation script not found"
65+
fi
66+
67+
# 检查 API 是否有变化
68+
- name: Check if API changed
69+
id: check_api
70+
run: |
71+
API_CHANGED="false"
72+
73+
# Check if API.md exists and has changes
74+
if [ -f "API.md" ]; then
75+
# Compare with git to see if there are changes
76+
if ! git diff --quiet API.md 2>/dev/null; then
77+
API_CHANGED="true"
78+
fi
79+
else
80+
# If API.md doesn't exist yet, consider it as changed
81+
API_CHANGED="true"
82+
fi
83+
84+
echo "api_changed=$API_CHANGED" >> $GITHUB_OUTPUT
85+
echo "📋 API changed: $API_CHANGED"
86+
87+
# 发布 NPM 包(仅在 API 有变化时)
88+
- name: Publish NPM Package
89+
if: success() && steps.check_api.outputs.api_changed == 'true'
90+
env:
91+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
92+
run: |
93+
if [ ! -d "npm" ]; then
94+
echo "⚠️ Skipping NPM publish: Directory npm/ not found"
95+
exit 0
96+
fi
97+
98+
if [ -z "$NODE_AUTH_TOKEN" ]; then
99+
echo "⚠️ Skipping NPM publish: NODE_AUTH_TOKEN is empty. Please check if NPM_TOKEN secret is set correctly."
100+
exit 0
101+
fi
102+
103+
cd npm
104+
echo "📦 Publishing to NPM..."
105+
npm publish --access public
106+
echo "✅ Published successfully"
107+
108+
# 4. 复制私有仓库的文件到当前仓库
109+
- name: Copy files from Private Repository
110+
run: |
111+
echo "📋 Starting file sync from private repository..."
112+
113+
# Sync templates directory
114+
if [ -d "TrollScript-Private/templates" ]; then
115+
rm -rf templates
116+
cp -r TrollScript-Private/templates ./
117+
echo "✅ Synced templates/"
118+
else
119+
echo "⚠️ templates/ not found in private repository"
120+
fi
121+
122+
# Sync README.md
123+
if [ -f "TrollScript-Private/templates/README.md" ]; then
124+
cp TrollScript-Private/templates/README.md ./
125+
echo "✅ Synced README.md"
126+
else
127+
echo "⚠️ README.md not found in private repository"
128+
fi
129+
130+
# 5. 提交更改到当前仓库
131+
- name: Commit and Push changes
132+
if: success()
133+
run: |
134+
echo "📋 Checking for changes..."
135+
136+
# Check if there are changes
137+
if [ -n "$(git status --porcelain)" ]; then
138+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
139+
git config --local user.name "github-actions[bot]"
140+
141+
git add -A
142+
git commit -m "🔄 Sync from private repository - $(date '+%Y-%m-%d %H:%M:%S')"
143+
git push
144+
145+
echo "✅ Changes committed and pushed"
146+
else
147+
echo "ℹ️ No changes to commit"
148+
fi
149+
28150
- name: Install dependencies
29151
run: |
30152
pip install mkdocs-material
@@ -34,6 +156,7 @@ jobs:
34156
mkdir -p docs
35157
cp *.md docs/
36158
cp templates/*.md docs/
159+
cp templates/API/*.md docs/
37160
cp -r AppIcon.png docs/
38161
cp -r images docs/
39162
cp -r CNAME docs/

0 commit comments

Comments
 (0)