-
Notifications
You must be signed in to change notification settings - Fork 137
196 lines (177 loc) · 6.03 KB
/
printcss.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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: PrintCSS
on:
workflow_dispatch:
inputs:
tag_name:
description: "Tag name for release (empty for no release)"
required: false
default: contiguous
push:
branches: [ "main" ]
tags: ["v[0-9]+.[0-9]+.[0-9]+*"]
paths:
- README.md
- "src/现代C\\+\\+题目/**"
- .github/workflows/printcss.yml
pull_request:
branches: [ "main" ]
paths:
- README.md
- "src/现代C\\+\\+题目/**"
- .github/workflows/printcss.yml
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
cache-hit: ${{ steps.cache.outputs.cache-hit }}
steps:
- uses: actions/cache/restore@v4
id: cache
with:
lookup-only: true
key: treesitter-cli
path: ~/tree-sitter/tree-sitter
build-tree-sitter:
needs: prepare
if: needs.prepare.outputs.cache-hit != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: tree-sitter/tree-sitter
- uses: actions/checkout@v4
with:
path: lhw
- name: Apply CLI patch
run: |
git apply --check --apply lhw/.github/0001-Suppress-HTML-header-and-footer-for-CLI-highlight.patch
git apply --check --apply lhw/.github/0002-Reduce-lang_not_found-message.patch
- run: rustup toolchain install stable-x86_64-unknown-linux-gnu --profile minimal
- uses: Swatinem/rust-cache@v2
- name: Build CLI
run: |
cargo build --release
mkdir ~/tree-sitter
cp target/release/tree-sitter ~/tree-sitter/
- name: Save cache
uses: actions/cache/save@v4
with:
path: ~/tree-sitter/tree-sitter
key: treesitter-cli
build-printcss:
needs: [prepare, build-tree-sitter]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache/restore@v4
with:
key: treesitter-cli
path: ~/tree-sitter/tree-sitter
fail-on-cache-miss: true
- name: Setup tree-sitter
run: |
echo "$HOME/tree-sitter" >> $GITHUB_PATH
mkdir -p ~/.config/tree-sitter
cp .github/tree-sitter.json ~/.config/tree-sitter/config.json
- uses: actions/cache@v4
id: cache-tsp
with:
key: treesitter-parsers
path: |
~/.cache/tree-sitter/
~/tree-sitter-parsers/
- name: Fetch tree-sitter parsers
if: steps.cache-tsp.outputs.cache-hit != 'true'
run: |
mkdir -p ~/tree-sitter-parsers
cd ~/tree-sitter-parsers/
git clone --depth 1 --no-tags https://github.com/tree-sitter/tree-sitter-cpp.git
pushd tree-sitter-cpp
npm install
popd
- name: Dump tree-sitter parsers
run: |
tree-sitter dump-languages
- uses: actions/setup-node@v4
with:
node-version: '>=18'
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- run: python3 -m pip install -r requirements.txt
- name: Configure mit2html and pagedgen
run: |
pushd src/现代C++题目/
pushd mit2html
npm install
popd
pushd pagedgen
npm install
npx playwright install chromium
popd
popd
- name: Generate HTML
run: |
python3 src/现代C++题目/generate.py
- name: Generate PDF
run: |
node src/现代C++题目/pagedgen/cli.js generated.html -o homework_problemtext.pdf --additional-script src/现代C++题目/remove_details.js
node src/现代C++题目/pagedgen/cli.js generated.html -o homework_full.pdf --additional-script src/现代C++题目/unwrap_details.js
- name: Update artifacts
uses: actions/upload-artifact@v4
with:
name: pdf
path: |
homework_problemtext.pdf
homework_full.pdf
release:
runs-on: ubuntu-latest
needs: build-printcss
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || (github.event_name == 'schedule') || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != '') && !cancelled()
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: pdf
path: artifacts
- name: Archive and compress
run: |
find artifacts/ -printf "%P\n" | tar -cvf adocs.tar --no-recursion -C artifacts/ -T -
zstd -z -1 adocs.tar -o loser-homework-pdf.tar.zst
- if: github.event_name == 'workflow_dispatch'
run: echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
- if: github.event_name == 'schedule'
run: echo 'TAG_NAME=contiguous' >> $GITHUB_ENV
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: |
TAG_NAME=${{ github.ref }}
echo "TAG_NAME=${TAG_NAME#refs/tags/}" >> $GITHUB_ENV
echo "DRAFT=true" >> $GITHUB_ENV
- if: env.TAG_NAME == 'contiguous'
name: Delete previous contiguous
env:
GH_TOKEN: ${{ github.token }}
run: |
echo 'PRERELEASE=true' >> $GITHUB_ENV
gh release delete contiguous --yes || true
git config user.name github-actions
git config user.email [email protected]
git push origin :contiguous || true
sleep 2
- name: Rename release files
run: |
mv loser-homework-pdf.tar.zst loser-homework-pdf-${{ env.TAG_NAME }}.tar.zst
- name: Release
uses: softprops/action-gh-release@v1
if: github.event_name != 'pull_request' && env.TAG_NAME != ''
with:
name: "Docs ${{ env.TAG_NAME }}"
prerelease: ${{ env.PRERELEASE != '' }}
files: loser-homework-pdf-${{ env.TAG_NAME }}.tar.zst
tag_name: ${{ env.TAG_NAME }}
draft: ${{ env.DRAFT != '' || null }}