forked from KaiserY/trpl-zh-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.62 KB
/
Copy pathmain.yml
File metadata and controls
84 lines (72 loc) · 2.62 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
name: Deploy to GitHub Pages
on:
push:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow pushing to gh-pages branch
permissions:
contents: write
env:
MDBOOK_VERSION: 0.5.2
MDBOOK_TYPST_PDF_VERSION: 0.7.0
TYPST_VERSION: 0.12.0
jobs:
deploy:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
# 1. 安装依赖
- uses: actions/checkout@v4
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v3
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-bin-mdbook-typst-pdf-${{ env.MDBOOK_TYPST_PDF_VERSION }}
- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install 1.90 -c rust-docs
rustup default 1.90
- name: Install mdbook
run: |
mkdir bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
- name: Install typst
run: |
curl -sSL https://github.com/typst/typst/releases/download/v${TYPST_VERSION}/typst-x86_64-unknown-linux-musl.tar.xz | tar -xJ --directory=bin --strip-components=1
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
- name: Install mdbook-typst-pdf
run: |
if ! command -v mdbook-typst-pdf &> /dev/null; then
cargo install mdbook-typst-pdf --version ${MDBOOK_TYPST_PDF_VERSION}
else
echo "mdbook-typst-pdf already installed (from cache)"
fi
# 2. 编译
- name: Build book
run: mdbook build
# 2.5. 复制 PDF 到 HTML 目录
- name: Copy PDF to HTML directory
run: |
mkdir -p book/html/pdf
cp book/typst-pdf/*.pdf book/html/pdf/ || echo "No PDF files found"
# 3. 上传产物到 gh-pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./book/html
publish_branch: gh-pages
force_orphan: true