Skip to content

Commit

Permalink
Introduce a new GitHub Action from the pandoc repo (#162)
Browse files Browse the repository at this point in the history
* Introduce a new GitHub Action from the pandoc repo

This change introduces an action called render that exists in the same
repo as the rest of the Pandoc tools, so we can eventually retire the
separate markdown repo (which hosted the action).

* move the action file

* rewrite boolean condition

* add missing echo

* use latest docker/login-action

* use bool vars as bools

* fix pdflog argument

* only do pdfdiff if pdf is requested, also do diff

* try removing quotes from diff_file_name

* remove environment variable

* move diff file naming into build script

* tweak diff file name

* fail if git can't reset

* add git fetch unshallow

* silence git fetch output

* use quiet
  • Loading branch information
chrisfenner authored Sep 5, 2024
1 parent 9d6f51c commit 22f5386
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 24 deletions.
62 changes: 62 additions & 0 deletions .github/actions/render/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 'Render'
description: 'Render a TCG Markdown document'
inputs:
input-md:
description: 'The name of the Markdown file to render'
required: true
output-basename:
description: 'The base name (without extension) to use for output file(s)'
required: true
pr-repo:
description: 'Pull request repo (use with pr-number)'
required: false
type: 'string'
pr-number:
description: 'Pull request number to reference (use with pr-repo)'
required: false
type: 'string'
pdf:
description: 'Render to PDF'
required: false
type: 'boolean'
default: 'true'
diffbase:
description: 'The revision to diff against (use with pdf)'
required: false
type: 'string'
html:
description: 'Render to HTML'
required: false
type: 'boolean'
default: 'false'
docx:
description: 'Render to Word'
required: false
type: 'boolean'
default: 'false'
tex:
description: 'Render to TeX'
required: false
type: 'boolean'
default: 'false'
extra-build-options:
description: 'Additional build options to be passed to build.sh'
runs:
using: 'composite'
steps:
# let the container take ownership of the repo dir, in case the user wants to check in the results
# workaround to https://github.com/actions/runner/issues/2033
- run: chown -R $(id -u):$(id -g) $PWD
shell: sh
- run: >
/usr/bin/build.sh
--versioned_filenames
$( [ -n "${{ inputs.pr-repo }}" -a -n "${{ inputs.pr-number }}" ] && echo --pr_number=${{ inputs.pr-number }} --pr_repo=${{ inputs.pr-repo }} )
$( [ ${{ inputs.pdf }} -a -n "${{ inputs.diffbase }}" ] && echo --diffbase=${{ inputs.diffbase }} --diffpdf=${{ inputs.output-basename }}.diff.pdf --diffpdflog=${{ inputs.output-basename }}.diff.pdf.log )
$( ${{ inputs.pdf }} && echo --pdf=${{ inputs.output-basename }}.pdf --pdflog=${{ inputs.output-basename }}.pdf.log )
$( ${{ inputs.html }} && echo --html=${{ inputs.output-basename }}.html )
$( ${{ inputs.docx }} && echo --docx=${{ inputs.output-basename }}.docx )
$( ${{ inputs.tex }} && echo --latex=${{ inputs.output-basename }}.tex )
${{ inputs.extra-build-options }}
${{ inputs.input-md }}
shell: sh
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/render-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand Down Expand Up @@ -68,25 +68,36 @@ jobs:
*.lof
*.lot
*.toc
*.upa
*.upb
*.convert.pdf
key: latex-${{ github.run_id }}
restore-keys: latex

- name: Run the action on guide
uses: trustedcomputinggroup/markdown@latest
uses: ./.github/actions/render
with:
input-md: guide.tcg
extra-build-options: "--versioned_filenames --pr_number=${{ github.event.number }} --pr_repo=${{ github.repository }} --diffbase=${{ github.event.pull_request.base.sha }}"
output-pdf: guide.pdf
output-tex: guide.tex
output-docx: guide.docx
output-basename: guide
pdf: true
tex: true
docx: true
diffbase: "${{ github.event.pull_request.base.sha }}"
pr-number: "${{ github.event.number }}"
pr-repo: "${{ github.repository }}"

- name: Upload PDF
uses: actions/upload-artifact@master
with:
name: PDF
path: guide.*.pdf

- name: Upload logs
uses: actions/upload-artifact@master
with:
name: Logs
path: guide.*.log

- name: Upload TeX
uses: actions/upload-artifact@master
with:
Expand Down
38 changes: 21 additions & 17 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ if [ "${VERSIONED_FILENAMES}" == "yes" ]; then
PDF_OUTPUT=$(prefix_filename "${version_prefix}" "${PDF_OUTPUT}")
fi
if [ ! -z "${DIFFPDF_OUTPUT}" ]; then
DIFFPDF_OUTPUT=$(prefix_filename "${DIFFBASE}_to_${version_prefix}" "${DIFFPDF_OUTPUT}")
DIFFPDF_OUTPUT=$(prefix_filename ".$(echo ${DIFFBASE} | cut -c1-10).to${version_prefix}" "${DIFFPDF_OUTPUT}")
fi
if [ ! -z "${LATEX_OUTPUT}" ]; then
LATEX_OUTPUT=$(prefix_filename "${version_prefix}" "${LATEX_OUTPUT}")
Expand Down Expand Up @@ -778,22 +778,26 @@ readonly TEMP_DIFF_TEX_FILE="${BUILD_DIR}/${INPUT_FILE}.diff.tex"
readonly TEMP_LATEXDIFF_LOG="${BUILD_DIR}/latexdiff.log"
export MERMAID_FILTER_FORMAT="pdf"
if [ -n "${DIFFPDF_OUTPUT}" ]; then
git reset --hard ${DIFFBASE}

do_md_fixups "${BUILD_DIR}/${INPUT_FILE}"
do_latex "${BUILD_DIR}/${INPUT_FILE}" "${TEMP_DIFFBASE_TEX_FILE}"
latexdiff --type PDFCOMMENT --driver "${PDF_ENGINE}" "${TEMP_DIFFBASE_TEX_FILE}" "${TEMP_TEX_FILE}" > "${TEMP_DIFF_TEX_FILE}" 2>"${TEMP_LATEXDIFF_LOG}"
do_tex_fixups "${TEMP_DIFF_TEX_FILE}"
do_pdf "${TEMP_DIFF_TEX_FILE}" "${SOURCE_DIR}/${DIFFPDF_OUTPUT}" "${LATEX_LOG}"

# Copy the logs, if requested. Note that this file gets the latexdiff and PDF driver output.
if [ -n "${DIFFPDFLOG_OUTPUT}" ]; then
mkdir -p "$(dirname ${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT})"
echo "latexdiff output:" > "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
cat "${TEMP_LATEXDIFF_LOG}" >> "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
echo "" >> "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
echo "${PDF_ENGINE} output:" >> "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
cat "${LATEX_LOG}" >> "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
git fetch --unshallow --quiet && git reset --hard ${DIFFBASE}
if [ $? -ne 0 ]; then
FAILED=true
echo "diff output failed"
else
do_md_fixups "${BUILD_DIR}/${INPUT_FILE}"
do_latex "${BUILD_DIR}/${INPUT_FILE}" "${TEMP_DIFFBASE_TEX_FILE}"
latexdiff --type PDFCOMMENT --driver "${PDF_ENGINE}" "${TEMP_DIFFBASE_TEX_FILE}" "${TEMP_TEX_FILE}" > "${TEMP_DIFF_TEX_FILE}" 2>"${TEMP_LATEXDIFF_LOG}"
do_tex_fixups "${TEMP_DIFF_TEX_FILE}"
do_pdf "${TEMP_DIFF_TEX_FILE}" "${SOURCE_DIR}/${DIFFPDF_OUTPUT}" "${LATEX_LOG}"

# Copy the logs, if requested. Note that this file gets the latexdiff and PDF driver output.
if [ -n "${DIFFPDFLOG_OUTPUT}" ]; then
mkdir -p "$(dirname ${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT})"
echo "latexdiff output:" > "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
cat "${TEMP_LATEXDIFF_LOG}" >> "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
echo "" >> "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
echo "${PDF_ENGINE} output:" >> "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
cat "${LATEX_LOG}" >> "${SOURCE_DIR}/${DIFFPDFLOG_OUTPUT}"
fi
fi
fi

Expand Down

0 comments on commit 22f5386

Please sign in to comment.