|
| 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 | + - ".github/scripts/**" |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: publish-help-to-wiki |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + publish: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout assets repo |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 1 |
| 25 | + |
| 26 | + - name: Install pandoc |
| 27 | + run: | |
| 28 | + sudo apt-get update |
| 29 | + sudo apt-get install -y pandoc |
| 30 | +
|
| 31 | + - name: Convert HTML to Markdown (GFM) |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + set -euo pipefail |
| 35 | +
|
| 36 | + SRC_DIR="help/SwiftCraftLauncher.help/Contents/Resources/en.lproj" |
| 37 | + OUT_DIR="_wiki_help" |
| 38 | + SCRIPT_DIR=".github/scripts" |
| 39 | + mkdir -p "$OUT_DIR" |
| 40 | +
|
| 41 | + shopt -s nullglob |
| 42 | + for f in "$SRC_DIR"/*.html; do |
| 43 | + [[ -e "$f" ]] || continue |
| 44 | + base="$(basename "$f" .html)" |
| 45 | +
|
| 46 | + out_name="$base.md" |
| 47 | + if [[ "$base" == "index" ]]; then |
| 48 | + out_name="home.md" |
| 49 | + fi |
| 50 | +
|
| 51 | + out="$OUT_DIR/$out_name" |
| 52 | + tmp_preprocessed="$OUT_DIR/pre_${base}.html" |
| 53 | + map_file="$OUT_DIR/.img_${base}.map" |
| 54 | +
|
| 55 | + echo "转换: $base.html -> $out_name" |
| 56 | +
|
| 57 | + # 1. 预处理:用 span 占位符替换 img,pandoc 会保留 span |
| 58 | + perl "$SCRIPT_DIR/help-to-md-preprocess.pl" "$f" "$tmp_preprocessed" "$map_file" |
| 59 | +
|
| 60 | + # 2. pandoc 转换 |
| 61 | + pandoc "$tmp_preprocessed" \ |
| 62 | + --from=html \ |
| 63 | + --to=gfm+raw_html \ |
| 64 | + --wrap=none \ |
| 65 | + -o "$out" |
| 66 | +
|
| 67 | + # 3. 后处理:恢复 img 标签,app-icon 64x64,topicIcon 48x48 |
| 68 | + perl "$SCRIPT_DIR/help-to-md-postprocess.pl" "$out" "$map_file" |
| 69 | + rm -f "$map_file" "$tmp_preprocessed" 2>/dev/null || true |
| 70 | +
|
| 71 | + # 4. 调整内部链接以适配 GitHub Wiki |
| 72 | + perl -pi -e ' |
| 73 | + s/\]\(((?!https?:\/\/)[^)]*?)index\.html(\))/\]\(\1home\2/g; |
| 74 | + s/\]\(((?!https?:\/\/)[^)]*?)index\.html(#)/\]\(\1home\2/g; |
| 75 | + s/\]\(((?!https?:\/\/)[^)]*?)\.html(\))/\]\(\1\2/g; |
| 76 | + s/\]\(((?!https?:\/\/)[^)]*?)\.html(#)/\]\(\1\2/g; |
| 77 | + s/\]\(home(\#[^)]*)\)/\](home.md$1)/g; |
| 78 | + s/\]\(home\)/\](home.md)/g; |
| 79 | + s/href="index\.html"/href="home"/g; |
| 80 | + s/href="index\.html#/href="home#/g; |
| 81 | + ' "$out" 2>/dev/null || true |
| 82 | + done |
| 83 | +
|
| 84 | + - name: Publish to GitHub Wiki repo |
| 85 | + env: |
| 86 | + WIKI_REPO: suhang12332/Swift-Craft-Launcher.wiki |
| 87 | + WIKI_PAT: ${{ secrets.WIKI_PAT }} |
| 88 | + shell: bash |
| 89 | + run: | |
| 90 | + set -euo pipefail |
| 91 | +
|
| 92 | + if [[ -z "${WIKI_PAT:-}" ]]; then |
| 93 | + echo "Missing secret WIKI_PAT. Add your existing PAT as a repository secret named WIKI_PAT." |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | +
|
| 97 | + # 为当前 runner 设置全局 git 身份,避免 Author identity unknown |
| 98 | + git config --global user.name "github-actions[bot]" |
| 99 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 100 | +
|
| 101 | + git clone "https://x-access-token:${WIKI_PAT}@github.com/${WIKI_REPO}.git" wiki |
| 102 | +
|
| 103 | + # 覆盖 wiki 主仓库根目录(不再使用子目录) |
| 104 | + cp -R "_wiki_help/." "wiki/" |
| 105 | +
|
| 106 | + cd wiki |
| 107 | + git config user.name "github-actions[bot]" |
| 108 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 109 | + git add -A |
| 110 | + if git diff --cached --quiet; then |
| 111 | + echo "No wiki changes to publish." |
| 112 | + exit 0 |
| 113 | + fi |
| 114 | + git commit -m "Update help docs (HTML → Markdown)" |
| 115 | + git push |
| 116 | +
|
0 commit comments