Add track changes to PR previews in HTML and DOCX formats #62
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Quarto Preview | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - closed | |
| - labeled | |
| - unlabeled | |
| paths: | |
| - 'chapters/**' | |
| - '_quarto.yml' | |
| - '_quarto-*.yml' | |
| - '.github/workflows/preview.yml' | |
| - '.github/workflows/publish.yml' | |
| - '*.qmd' | |
| - '*.css' | |
| - 'references.bib' | |
| concurrency: preview-${{ github.ref }} | |
| jobs: | |
| build-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch full history for git diff | |
| - name: Set up Quarto | |
| uses: quarto-dev/quarto-actions/setup@v2 | |
| with: | |
| tinytex: true | |
| - uses: r-lib/actions/setup-r@v2 | |
| with: | |
| use-public-rspm: true | |
| - uses: r-lib/actions/setup-renv@v2 | |
| with: | |
| cache-version: 1 | |
| - name: Render | |
| if: github.event.action != 'closed' # skip the build if the PR has been closed | |
| uses: quarto-dev/quarto-actions/render@v2 | |
| # Detect which chapters have changed and optionally disable highlighting | |
| # based on the 'no-preview-highlights' PR label | |
| - name: Detect changed chapters (based on rendered files) | |
| if: github.event.action != 'closed' | |
| run: python3 .github/scripts/detect-changed-chapters.py | |
| env: | |
| HTML_DIR: ./_site | |
| # Set to 'true' if PR has 'no-preview-highlights' label | |
| DISABLE_PREVIEW_HIGHLIGHTS: ${{ contains(github.event.pull_request.labels.*.name, 'no-preview-highlights') }} | |
| - name: Inject preview metadata | |
| if: github.event.action != 'closed' && env.PREVIEW_SHOW_HIGHLIGHTS == 'true' | |
| run: python3 .github/scripts/inject-preview-metadata.py | |
| - name: Re-render with metadata | |
| if: github.event.action != 'closed' && env.PREVIEW_SHOW_HIGHLIGHTS == 'true' | |
| uses: quarto-dev/quarto-actions/render@v2 | |
| - name: Install python-docx for DOCX comparison | |
| if: github.event.action != 'closed' && env.PREVIEW_SHOW_HIGHLIGHTS == 'true' | |
| run: pip install python-docx | |
| - name: Highlight HTML content changes | |
| if: github.event.action != 'closed' && env.PREVIEW_SHOW_HIGHLIGHTS == 'true' | |
| run: | | |
| echo "Changed chapters:" | |
| echo "${{ env.PREVIEW_CHANGED_CHAPTERS }}" | |
| python3 .github/scripts/highlight-html-changes.py | |
| env: | |
| HTML_DIR: ./_site | |
| PREVIEW_CHANGED_CHAPTERS: ${{ env.PREVIEW_CHANGED_CHAPTERS }} | |
| - name: Create DOCX with tracked changes | |
| if: github.event.action != 'closed' | |
| run: python3 .github/scripts/create-docx-tracked-changes.py | |
| env: | |
| DOCX_DIR: ./_site | |
| - name: Add home page banner | |
| if: github.event.action != 'closed' | |
| run: python3 .github/scripts/add-home-banner.py | |
| env: | |
| HTML_DIR: ./_site | |
| PREVIEW_CHANGED_CHAPTERS: ${{ env.PREVIEW_CHANGED_CHAPTERS }} | |
| - name: list files | |
| if: github.event.action != 'closed' | |
| shell: bash | |
| run: | | |
| echo "contents of _site:" | |
| ls _site/ || echo "_site directory not found" | |
| echo "contents of .:" | |
| ls . | |
| - name: Deploy PR Preview | |
| uses: rossjrw/pr-preview-action@main | |
| with: | |
| source-dir: _site/ | |
| pages-base-url: scaling-robot-wry3qok.pages.github.io |