Repository navigation
169 lines (149 loc) · 6.18 KB
/
Copy pathbook.yml
File metadata and controls
169 lines (149 loc) · 6.18 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# 正文一改就重新生成四样,挂到固定的 Release「epub-latest」上,下载链接不变:
# EPUB https://github.com/eternity4719/HowToLiveBetter/releases/download/epub-latest/HowToLiveBetter.epub
# PDF https://github.com/eternity4719/HowToLiveBetter/releases/download/epub-latest/HowToLiveBetter.pdf
# 离线单文件 https://github.com/eternity4719/HowToLiveBetter/releases/download/epub-latest/HowToLiveBetter.html
# Anki 牌组 https://github.com/eternity4719/HowToLiveBetter/releases/download/epub-latest/HowToLiveBetter.apkg
# PR 只生成并校验,不发布,产物在 Actions 页面的 artifact 里。
name: 电子书
on:
push:
branches: [main]
paths:
- README.md
- index.html
- og.png
- ads/**
- book/**
- docs/*.md
- tools/**
- .github/workflows/book.yml
pull_request:
paths:
- README.md
- index.html
- og.png
- ads/**
- book/**
- docs/*.md
- tools/**
- .github/workflows/book.yml
workflow_dispatch:
permissions:
contents: write
concurrency:
group: book-${{ github.ref }}
cancel-in-progress: true
env:
PANDOC_VERSION: '3.11'
TYPST_VERSION: '0.15.1'
jobs:
# 交叉引用检查。单独一个 job,不挂在 build 里:锚点没补好不该连累 EPUB、PDF 和
# 离线单文件的发布,那是两回事。PR 上照样红,main 上该发的还是发出去。
# 本地那条链路(sync-stats.mjs)要记得跑才会跑,
# 外部 PR 更是完全跑不到,所以这道检查得在 CI 里有一份。零依赖,几秒钟。
refs:
name: 交叉引用检查
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node tools/check-refs.mjs --check
# 说人话检查:长度、研究行话、抽象说法。理由同上,单独一个 job,不挡发布。
plain:
name: 说人话检查
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node tools/check-plain.mjs
# 拆分规则一致性检查:超长收益、备注和来源的拆分规则有两份(tools/lib/split-items.mjs 给 EPUB、PDF,
# index.html 里 <split-rules> 那段给网页和离线版),只改了一边就会四个出口长得不一样。理由同上,不挡发布。
split:
name: 拆分规则一致性检查
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node tools/check-split.mjs
# 统计数字检查:README、index.html、og.html 里的条目数、A/B/C 数、链接数等是否和 book/ 对得上。
# 本地 sync-stats.mjs 要记得跑才会更新,网页上直接合并的 PR 完全经过不了它。理由同上,不挡发布。
# 只查不改:让 CI 往 main 推提交会和本地分叉,而且 Ubuntu 没有微软雅黑,og.png 截不对。
stats:
name: 统计数字检查
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node tools/sync-stats.mjs --check
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: tools/epub/package-lock.json
- run: npm ci
working-directory: tools/epub
- name: EPUB
run: node tools/epub/build.mjs
- name: 离线单文件 HTML
run: node tools/offline/build.mjs
- name: Anki 牌组
run: node tools/anki/build.mjs
- name: 装 pandoc、typst 和中文字体
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends fonts-noto-cjk
curl -sSL "https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-linux-amd64.tar.gz" | tar xz
curl -sSL "https://github.com/typst/typst/releases/download/v${TYPST_VERSION}/typst-x86_64-unknown-linux-musl.tar.xz" | tar xJ
echo "$PWD/pandoc-${PANDOC_VERSION}/bin" >> "$GITHUB_PATH"
echo "$PWD/typst-x86_64-unknown-linux-musl" >> "$GITHUB_PATH"
- name: PDF
run: |
typst fonts | grep -i -E 'noto (serif|sans) cjk' || echo '没找到 Noto CJK,PDF 会退到别的字体,检查 fonts-noto-cjk 这一步'
node tools/pdf/build.mjs
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: epubcheck
run: |
curl -sSL -o epubcheck.zip https://github.com/w3c/epubcheck/releases/download/v5.4.0/epubcheck-5.4.0.zip
unzip -q epubcheck.zip
java -jar epubcheck-5.4.0/epubcheck.jar dist/HowToLiveBetter.epub
- uses: actions/upload-artifact@v4
with:
name: HowToLiveBetter
path: |
dist/HowToLiveBetter.epub
dist/HowToLiveBetter.pdf
dist/HowToLiveBetter.html
dist/HowToLiveBetter.apkg
- name: 发布到 Release epub-latest
if: github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
git tag -f epub-latest
git push -f origin epub-latest
notes="正文提交 ${GITHUB_SHA::7},生成于 $(date -u -d '+8 hours' +'%Y-%m-%d %H:%M')(北京时间)。EPUB、PDF、离线单文件 HTML、Anki 牌组四样,正文每次更新后自动重新生成,下载链接固定不变。"
if gh release view epub-latest >/dev/null 2>&1; then
gh release edit epub-latest --title "电子书(EPUB / PDF / 离线 HTML / Anki,自动更新)" --notes "$notes"
else
gh release create epub-latest --title "电子书(EPUB / PDF / 离线 HTML / Anki,自动更新)" --notes "$notes" --latest=false
fi
gh release upload epub-latest \
dist/HowToLiveBetter.epub \
dist/HowToLiveBetter.pdf \
dist/HowToLiveBetter.html \
dist/HowToLiveBetter.apkg --clobber