Skip to content

按 issue #71 在 README「其他语言」加 chuanman2707 维护的越南语翻译链接 #120

按 issue #71 在 README「其他语言」加 chuanman2707 维护的越南语翻译链接

按 issue #71 在 README「其他语言」加 chuanman2707 维护的越南语翻译链接 #120

Workflow file for this run

# 正文一改就重新生成三样,挂到固定的 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
# 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
# 统计数字检查: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: 装 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
- 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 三样,正文每次更新后自动重新生成,下载链接固定不变。"
if gh release view epub-latest >/dev/null 2>&1; then
gh release edit epub-latest --title "电子书(EPUB / PDF / 离线 HTML,自动更新)" --notes "$notes"
else
gh release create epub-latest --title "电子书(EPUB / PDF / 离线 HTML,自动更新)" --notes "$notes" --latest=false
fi
gh release upload epub-latest \
dist/HowToLiveBetter.epub \
dist/HowToLiveBetter.pdf \
dist/HowToLiveBetter.html --clobber