-
Notifications
You must be signed in to change notification settings - Fork 54
104 lines (90 loc) · 3.87 KB
/
generate_release_pdf.yml
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
name: Generate Release PDF
# 感谢 Derived Cat (@hooyuser) 提供的自动发布小脚本!
on:
push:
branches:
- main
paths-ignore:
- '.gitignore'
- '**.md'
env:
TYPST_FILE_NAME: cppguidebook
TYPST_FONT_PATH: fonts
MIRROR_SITE_URL: https://142857.red/files
MIRROR_SITE_HOOK: https://142857.red/hooks/update_cppguidebook
MIRROR_SITE_TOKEN: ${{ secrets.SEVEN_TOKEN }}
jobs:
build_typst:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Set up Git repository for secondary repo
uses: actions/checkout@v4
- name: Cache Fonts
uses: actions/cache@v4
id: cache-fonts
with:
path: fonts
key: ${{ runner.os }}-fonts-noto_sans_sc-lxgwwenkai
- name: Download Fonts
if: steps.cache-fonts.outputs.cache-hit != 'true'
run: |
if [ -f "${{ env.TYPST_FONT_PATH }}/NotoSansSC-Regular.ttf" ]; then
echo "Font already existed."
else
# Download font metadata
mkdir -p cv
curl -sL "https://fonts.google.com/download/list?family=Noto%20Sans%20SC" > cv/noto_sans_sc_raw.txt
# Remove ")]}'" from the beginning of the file
tail -c +5 cv/noto_sans_sc_raw.txt > cv/noto_sans_sc_metadata.json
# Extract the necessary information from the JSON file
file_refs=$(jq -rc '.manifest.fileRefs[]' cv/noto_sans_sc_metadata.json)
# Download, save the font file to /fonts
mkdir -p ${{ env.TYPST_FONT_PATH }}
while IFS= read -r file_ref; do
filename=$(echo "$file_ref" | jq -r '.filename')
url=$(echo "$file_ref" | jq -r '.url')
fontname=$(basename "$filename")
echo $url $fontname
curl -L "$url" -o "${{ env.TYPST_FONT_PATH }}/$fontname"
done <<< "$file_refs"
ls -l ${{ env.TYPST_FONT_PATH }}
fi
for form in Light Regular Bold; do
curl -L "https://github.com/lxgw/LxgwWenKai/releases/download/v1.330/LXGWWenKai-$form.ttf" -o "${{ env.TYPST_FONT_PATH }}/LXGWWenKai-$form.ttf"
done
- name: Prepare Typst environment
uses: typst-community/setup-typst@v3
- name: Compile Typst document
run: |
typst fonts --variants --font-path ${{ env.TYPST_FONT_PATH }}
typst compile ${{ env.TYPST_FILE_NAME }}.typ ${{ env.TYPST_FILE_NAME }}.pdf --font-path ${{ env.TYPST_FONT_PATH }}
- name: Delete old Release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo
try {
const { data: { id } } = await github.rest.repos.getLatestRelease({ owner, repo })
await github.rest.repos.deleteRelease({ owner, repo, release_id: id })
} catch {}
- name: Generate release tag
id: tag
run: |
echo "release_date=$(date +"%Y 年 %m 月 %d 日 %H 点 %M 分")" >> $GITHUB_OUTPUT
echo "release_tag=latest_$(date +"%Y-%m-%d_%H-%M")" >> $GITHUB_OUTPUT
- name: Release
uses: softprops/action-gh-release@v2
with:
name: 伟大,无需多言
body: |
小彭老师发布的最新 C++ 大典,更新时间 ${{ steps.tag.outputs.release_date }}
> Release 页面太慢?GitHub 卡顿,无法下载?访问 [小彭老师自己维护的镜像](${{ env.MIRROR_SITE_URL }}/${{ env.TYPST_FILE_NAME }}.pdf)。
tag_name: ${{ steps.tag.outputs.release_tag }}
files: ${{ env.TYPST_FILE_NAME }}.pdf
- name: Publish to mirror site
continue-on-error: true
run: |
curl -L -X POST ${{ env.MIRROR_SITE_HOOK }} -d token=${{ env.MIRROR_SITE_TOKEN }} -d tag=${{ steps.tag.outputs.release_tag }}