Skip to content

Create 嘻嘻.cpp

Create 嘻嘻.cpp #1

Workflow file for this run

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 }}