File tree Expand file tree Collapse file tree 2 files changed +123
-0
lines changed
Expand file tree Collapse file tree 2 files changed +123
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Swift 中文版文档发布脚本 - 发布到 GitHub Pages
4+ # 基于 swiftlang/swift-book 的 update-book-preview 脚本修改
5+
6+ set -eux
7+
8+ REMOTE=${1:- origin}
9+ CURRENT_COMMIT_HASH=" $( git rev-parse --short HEAD) "
10+
11+ # 进入仓库根目录
12+ cd " $( git rev-parse --show-toplevel) "
13+
14+ # 检出 gh-pages 分支到子目录
15+ git worktree add --checkout gh-pages " $REMOTE " /gh-pages
16+
17+ # 美化 DocC JSON 输出,便于对比和版本控制
18+ export DOCC_JSON_PRETTYPRINT=" YES"
19+
20+ # 使用 header.html(如果需要不同版本可以先复制)
21+ # cp -n swift-6.docc/header-publish.html swift-6.docc/header.html
22+
23+ # 构建文档,输出到 gh-pages/docs 子目录
24+ xcrun docc convert \
25+ --experimental-enable-custom-templates \
26+ --hosting-base-path the-swift-programming-language-in-chinese-1 \
27+ --output-path " ./gh-pages/docs" \
28+ swift-6.docc
29+
30+ # 如果复制了临时 header,清理掉
31+ # rm swift-6.docc/header.html
32+
33+ # 提交并推送更改到 gh-pages 分支
34+ pushd gh-pages
35+ git add docs
36+
37+ if [[ -n " $( git status --porcelain) " ]]
38+ then
39+ echo " 发现文档更新。"
40+ echo " 正在提交更改到 'gh-pages' 分支并推送到 $REMOTE 。"
41+ git commit -m " 更新 GitHub Pages 文档站点到提交 '$CURRENT_COMMIT_HASH '"
42+ echo
43+ git push " $REMOTE " HEAD:gh-pages
44+ else
45+ echo " 没有发现文档更改。"
46+ fi
47+
48+ popd
49+
50+ git worktree remove gh-pages
51+
52+ echo " 发布完成!"
53+ echo " GitHub Pages 地址应该是:"
54+ echo " https://你的用户名.github.io/the-swift-programming-language-in-chinese-1/"
Original file line number Diff line number Diff line change 1+ name: Deploy to GitHub Pages
2+
3+ on:
4+ # 在推送到 Swift-6.1 分支时触发
5+ push:
6+ branches:
7+ - Swift-6.1
8+
9+ # 允许手动触发
10+ workflow_dispatch:
11+
12+ # 设置 GITHUB_TOKEN 的权限以允许部署到 GitHub Pages
13+ permissions:
14+ contents: read
15+ pages: write
16+ id-token: write
17+
18+ # 只允许一个并发部署,跳过正在进行的运行和最新排队的运行之间的运行
19+ # 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成
20+ concurrency:
21+ group: "pages"
22+ cancel-in-progress: false
23+
24+ jobs:
25+ # 构建作业
26+ build:
27+ runs-on: macos-latest
28+ steps:
29+ - name: Checkout
30+ uses: actions/checkout@v4
31+
32+ - name: Setup Pages
33+ uses: actions/configure-pages@v4
34+
35+ - name: Select Xcode
36+ run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
37+
38+ - name: Build with DocC
39+ run: |
40+ # 使用 xcrun docc 构建文档
41+ xcrun docc convert TSPL.docc \
42+ --fallback-display-name "Swift 编程语言" \
43+ --fallback-bundle-identifier "org.swift.tspl" \
44+ --fallback-bundle-version 6.1 \
45+ --additional-symbol-graph-dir . \
46+ --output-path ./_site
47+
48+ - name: Add custom header and footer
49+ run: |
50+ # 将自定义的 header 和 footer 应用到生成的页面
51+ if [ -f "TSPL.docc/header-publish.html" ] && [ -f "TSPL.docc/footer.html" ]; then
52+ find ./_site -name "*.html" -type f -exec sed -i '' '/<\/head>/e cat TSPL.docc/header-publish.html' {} \;
53+ find ./_site -name "*.html" -type f -exec sed -i '' '/<\/body>/e cat TSPL.docc/footer.html' {} \;
54+ fi
55+
56+ - name: Upload artifact
57+ uses: actions/upload-pages-artifact@v3
58+
59+ # 部署作业
60+ deploy:
61+ environment:
62+ name: github-pages
63+ url: ${{ steps.deployment.outputs.page_url }}
64+ runs-on: ubuntu-latest
65+ needs: build
66+ steps:
67+ - name: Deploy to GitHub Pages
68+ id: deployment
69+ uses: actions/deploy-pages@v4
You can’t perform that action at this time.
0 commit comments