From afb62d8782cf48f488f352a85265e4e2b51aa82a Mon Sep 17 00:00:00 2001 From: TianKai Ma Date: Tue, 9 Apr 2024 22:36:06 +0800 Subject: [PATCH] feat: use GitHub Actions to build PDF files --- .github/workflows/build.yaml | 32 ++++++++++++++++++++++++++++++++ .gitignore | 3 ++- .vscode/settings.json | 3 ++- compile.sh | 22 ++++++++++++++++++++++ setup-font.sh | 4 ++++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100755 compile.sh create mode 100755 setup-font.sh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..2a879e4 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,32 @@ +name: Build Typst document +on: [push, workflow_dispatch] + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Run + run: | + brew install typst + ./setup-font.sh + ./compile.sh + - name: Upload Build files + uses: actions/upload-artifact@v3 + with: + name: PDFs + path: | + ./build + - name: Get current date + id: date + run: echo "DATE=$(date +%Y-%m-%d-%H:%M)" >> $GITHUB_ENV + - name: Release + uses: softprops/action-gh-release@v1 + if: github.ref_type == 'tag' + with: + name: "${{ github.ref_name }} — ${{ env.DATE }}" + files: "*.pdf" \ No newline at end of file diff --git a/.gitignore b/.gitignore index bb44266..b5b1533 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ fonts/ -**/**.pdf \ No newline at end of file +**/**.pdf +build/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index eb317c3..3025b42 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,5 +16,6 @@ "**/.DS_Store": true, "**/Thumbs.db": true, "**/*.pdf": true, - } + "**/build/": true, + }, } diff --git a/compile.sh b/compile.sh new file mode 100755 index 0000000..3bfc288 --- /dev/null +++ b/compile.sh @@ -0,0 +1,22 @@ +if [ ! -d "fonts" ]; then + echo "Please create a folder named 'fonts' and put your fonts in it." + exit 1 +fi + +if [ ! -d "build" ]; then + mkdir -p build +else + rm -rf build/* +fi + +for folder in $(ls -d */); do + folder=${folder%?} + if [ "$folder" == "fonts" ]; then + continue + fi + if [ "$folder" == "build" ]; then + continue + fi + echo "Compiling $folder" + typst compile --font-path fonts/ ./$folder/main.typ build/${folder}.pdf +done \ No newline at end of file diff --git a/setup-font.sh b/setup-font.sh new file mode 100755 index 0000000..bfad1a3 --- /dev/null +++ b/setup-font.sh @@ -0,0 +1,4 @@ +wget https://github.com/adobe-fonts/source-han-serif/releases/download/2.002R/01_SourceHanSerif.ttc.zip +mkdir -p fonts +unzip 01_SourceHanSerif.ttc.zip -d fonts +rm 01_SourceHanSerif.ttc.zip \ No newline at end of file