|
| 1 | +on: |
| 2 | + workflow_dispatch: |
| 3 | + push: |
| 4 | + branches: main |
| 5 | + |
| 6 | +name: Quarto Publish |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-deploy: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + steps: |
| 14 | + - name: Check out repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Set up Quarto |
| 18 | + uses: quarto-dev/quarto-actions/setup@v2 |
| 19 | + env: |
| 20 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + with: |
| 22 | + tinytex: true |
| 23 | + - name: Install Python and Dependencies |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.10' |
| 27 | + cache: 'pip' |
| 28 | + - run: pip install jupyter |
| 29 | + - run: pip install -r requirements.txt |
| 30 | + - name: Remove .onlyteacher blocks from .qmd files |
| 31 | + run: | |
| 32 | + for file in Week*/*.qmd; do |
| 33 | + [ -f "$file" ] || continue # Skip if not a regular file |
| 34 | + sed -i '/::: {.onlyteacher}/,/:::/d' "$file" |
| 35 | + done |
| 36 | + - name: Render Book and Slides |
| 37 | + run: | |
| 38 | + quarto render --profile book |
| 39 | + - name: Build PDFs from slides |
| 40 | + run: | |
| 41 | + python3 -m http.server 8000 & |
| 42 | + find ./_slides -name 'slides.html' | while read slide; do |
| 43 | + echo "Converting $slide to PDF" |
| 44 | + pdf_path="${slide%.html}.pdf" |
| 45 | + relative_slide_path="${slide#./}" |
| 46 | + url_path="/slides/$relative_slide_path" |
| 47 | + # Output path inside container: use /tmp |
| 48 | + tmp_pdf_name="$(basename "$pdf_path")" |
| 49 | + tmp_pdf_path="/tmp/$tmp_pdf_name" |
| 50 | + clean_slide=$(echo "$slide" | sed 's|^\./||') |
| 51 | + echo "http://localhost:8000/$clean_slide" |
| 52 | + docker run --rm -t --network=host -v "$(pwd)":/slides -v /tmp:/tmp astefanutti/decktape "http://localhost:8000/$clean_slide" "$tmp_pdf_path" |
| 53 | + cp "/tmp/$tmp_pdf_name" "$pdf_path" |
| 54 | + done |
| 55 | + - name: Deploy _book to gh-pages |
| 56 | + uses: peaceiris/actions-gh-pages@v4 |
| 57 | + with: |
| 58 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + publish_dir: ./_book |
| 60 | + publish_branch: gh-pages |
| 61 | + keep_files: true |
| 62 | + |
| 63 | + - name: Deploy _slides to gh-pages (subfolder) |
| 64 | + uses: peaceiris/actions-gh-pages@v4 |
| 65 | + with: |
| 66 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + publish_dir: ./_slides |
| 68 | + publish_branch: gh-pages |
| 69 | + destination_dir: slides |
| 70 | + keep_files: true |
0 commit comments