Skip to content

Commit

Permalink
feat: use GitHub Actions to build PDF files
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankaima committed Apr 9, 2024
1 parent 3db1da4 commit b10e079
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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: |
mkdir -p /tmp/typst
cd /tmp/typst
wget https://github.com/typst/typst/releases/download/v0.11.0/typst-x86_64-unknown-linux-musl.tar.xz
tar -xf typst-x86_64-unknown-linux-musl.tar.xz
export PATH=$PATH:$(pwd/typst-x86_64-unknown-linux-musl)
cd $GITHUB_WORKSPACE
./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"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fonts/
**/**.pdf
**/**.pdf
build/
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/*.pdf": true,
}
"**/build/": true,
},
}
22 changes: 22 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions setup-font.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b10e079

Please sign in to comment.