Generate PDF, Word & EPUB Documents #58
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: Generate PDF, Word & EPUB Documents | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: 'Branch, tag, or SHA to build (defaults to the selected ref)' | |
| required: false | |
| type: string | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: generate-docs-${{ github.repository }}-${{ inputs.ref || github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| build-docs: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 25 | |
| outputs: | |
| md_file: ${{ steps.inputs.outputs.md_file }} | |
| base: ${{ steps.inputs.outputs.base }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd | |
| with: | |
| ref: ${{ inputs.ref || github.ref }} | |
| - name: Setup docs toolchain | |
| uses: dknauss/ai-assisted-docs/.github/actions/setup-docs-toolchain@daefe86423522f8ce7c42947c5d1c91f7f48b126 | |
| timeout-minutes: 15 | |
| - name: Bootstrap pandoc styling assets | |
| run: | | |
| mkdir -p .github/pandoc | |
| if [ ! -f .github/pandoc/reference.docx ]; then | |
| pandoc --print-default-data-file reference.docx > .github/pandoc/reference.docx | |
| fi | |
| if [ ! -f .github/pandoc/pdf-defaults.yaml ]; then | |
| { | |
| printf '%s\n' 'from: markdown' | |
| printf '%s\n' 'standalone: true' | |
| printf '%s\n' 'pdf-engine: tectonic' | |
| printf '%s\n' 'variables:' | |
| printf '%s\n' ' colorlinks: true' | |
| printf '%s\n' ' geometry:' | |
| printf '%s\n' ' - margin=1in' | |
| printf '%s\n' ' header-left: WordPress-Security-Hardening-Guide' | |
| printf '%s\n' ' header-right: Dan Knauss' | |
| printf '%s\n' ' footer-center: "\thepage"' | |
| printf '%s\n' ' titlepage: false' | |
| } > .github/pandoc/pdf-defaults.yaml | |
| fi | |
| if [ ! -f .github/pandoc/epub.css ]; then | |
| { | |
| printf '%s\n' 'body { font-family: "Noto Serif", Georgia, serif; line-height: 1.6; }' | |
| printf '%s\n' 'code, pre { font-family: "Noto Sans Mono", Menlo, monospace; }' | |
| printf '%s\n' 'img { max-width: 100%; height: auto; }' | |
| } > .github/pandoc/epub.css | |
| fi | |
| - name: Resolve build inputs | |
| id: inputs | |
| run: | | |
| echo "md_file=WordPress-Security-Hardening-Guide.md" >> "$GITHUB_OUTPUT" | |
| echo "base=WordPress-Security-Hardening-Guide" >> "$GITHUB_OUTPUT" | |
| - name: Validate source release metadata | |
| run: | | |
| python3 .github/scripts/validate-release-metadata.py --markdown "${{ steps.inputs.outputs.md_file }}" --changelog CHANGELOG.md | |
| - name: Convert primary document | |
| run: | | |
| md_file="${{ steps.inputs.outputs.md_file }}" | |
| base="${{ steps.inputs.outputs.base }}" | |
| docx_file="${base}.docx" | |
| version=$(sed -n '/^---$/,/^---$/{ s/^version: *"\{0,1\}\([^"\n]*\)"\{0,1\}/\1/p }' "$md_file") | |
| source_date=$(sed -n '/^---$/,/^---$/{ s/^date: *"\{0,1\}\([^"\n]*\)"\{0,1\}/\1/p }' "$md_file") | |
| if [ -n "$version" ] && [ -n "$source_date" ]; then | |
| display_date="Version $version — $source_date" | |
| elif [ -n "$source_date" ]; then | |
| display_date="$source_date" | |
| else | |
| display_date="" | |
| fi | |
| pandoc "$md_file" --reference-doc=".github/pandoc/reference.docx" --toc --toc-depth=3 -o "$docx_file" | |
| pandoc "$docx_file" --from docx --template eisvogel --pdf-engine tectonic --defaults ".github/pandoc/pdf-defaults.yaml" --metadata "date=${display_date}" --toc --toc-depth=3 -o "${base}.pdf" | |
| pandoc "$docx_file" --from docx --css ".github/pandoc/epub.css" --toc --toc-depth=3 --epub-title-page=false --metadata "lang=en-US" -o "${base}.epub" | |
| - name: Validate generated artifacts | |
| run: python3 .github/scripts/validate-artifacts.py | |
| - name: Upload generated document bundle | |
| uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f | |
| with: | |
| name: generated-docs-bundle | |
| path: | | |
| ${{ steps.inputs.outputs.md_file }} | |
| ${{ steps.inputs.outputs.base }}.pdf | |
| ${{ steps.inputs.outputs.base }}.docx | |
| ${{ steps.inputs.outputs.base }}.epub | |
| .github/pandoc/reference.docx | |
| .github/pandoc/pdf-defaults.yaml | |
| .github/pandoc/epub.css |