Skip to content

Commit 23f9c87

Browse files
committed
Create help-to-wiki.yml
feat: add help to wiki action
1 parent 8715a51 commit 23f9c87

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

.github/workflows/help-to-wiki.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Publish Help (HTML → Wiki Markdown)
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- "help/SwiftCraftLauncher.help/Contents/Resources/en.lproj/**"
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: publish-help-to-wiki
14+
cancel-in-progress: true
15+
16+
jobs:
17+
publish:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout assets repo
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 1
24+
25+
- name: Install pandoc
26+
run: |
27+
sudo apt-get update
28+
sudo apt-get install -y pandoc
29+
30+
- name: Convert HTML to Markdown (GFM)
31+
shell: bash
32+
run: |
33+
set -euo pipefail
34+
35+
SRC_DIR="help/SwiftCraftLauncher.help/Contents/Resources/en.lproj"
36+
OUT_DIR="_wiki_help/en"
37+
mkdir -p "$OUT_DIR"
38+
39+
shopt -s nullglob
40+
for f in "$SRC_DIR"/*.html; do
41+
base="$(basename "$f" .html)"
42+
out="$OUT_DIR/$base.md"
43+
pandoc "$f" \
44+
--from=html \
45+
--to=gfm \
46+
--wrap=none \
47+
--extract-media="$OUT_DIR/media" \
48+
-o "$out"
49+
50+
# Keep wiki-internal links working (html → md)
51+
perl -pi -e 's/(\]\([^\)]*)\.html(\))/\1.md\2/g; s/(\]\([^\)]*)\.html(#)/\1.md\2/g' "$out" || true
52+
done
53+
54+
- name: Publish to GitHub Wiki repo
55+
env:
56+
WIKI_REPO: suhang12332/Swift-Craft-Launcher.wiki
57+
WIKI_TOKEN: ${{ secrets.WIKI_TOKEN }}
58+
shell: bash
59+
run: |
60+
set -euo pipefail
61+
62+
if [[ -z "${WIKI_TOKEN:-}" ]]; then
63+
echo "Missing secret WIKI_TOKEN. Create a PAT with access to the wiki repo and add it as repository secret."
64+
exit 1
65+
fi
66+
67+
git config user.name "github-actions[bot]"
68+
git config user.email "github-actions[bot]@users.noreply.github.com"
69+
70+
git clone "https://x-access-token:${WIKI_TOKEN}@github.com/${WIKI_REPO}.git" wiki
71+
72+
rm -rf "wiki/help/en"
73+
mkdir -p "wiki/help/en"
74+
cp -R "_wiki_help/en/." "wiki/help/en/"
75+
76+
cd wiki
77+
git add -A
78+
if git diff --cached --quiet; then
79+
echo "No wiki changes to publish."
80+
exit 0
81+
fi
82+
git commit -m "Update help docs (HTML → Markdown)"
83+
git push
84+

0 commit comments

Comments
 (0)