#!/bin/sh set -eu repo_root=$(pwd) if [ -f "$repo_root/manual/latex/devopsAssignment.tex" ]; then source_dir="$repo_root/manual/latex" elif [ -f "$repo_root/latex/devopsAssignment.tex" ]; then source_dir="$repo_root/latex" else echo 'ERROR: main LaTeX source was not found.' >&2 exit 1 fi output_dir="$repo_root/build/manual" mkdir -p "$output_dir/intermediate" # Remove an earlier deliverable so it cannot be uploaded after a failed build. rm -f "$output_dir/2026F-SSW-590-DevOps-Group-1.pdf" "$output_dir/pdf-sha256.txt" if [ "${MANUAL_LOCAL_TEST:-}" = '1' ]; then suffix='+local-test' revision='LOCAL WORKING COPY (not a Gitea run)' run_number='local-test' else : "${GITEA_SHA:?Workflow must supply the triggering commit}" : "${GITEA_RUN_NUMBER:?Workflow must supply the run number}" case "$GITEA_SHA" in *[!0-9a-fA-F]*|'') echo 'Invalid commit hash.' >&2; exit 1;; esac [ "${#GITEA_SHA}" -eq 40 ] || { echo 'Expected a full 40-character commit hash.' >&2; exit 1; } case "$GITEA_RUN_NUMBER" in *[!0-9]*|'') echo 'Invalid run number.' >&2; exit 1;; esac revision=$(git rev-parse HEAD) [ "$revision" = "$GITEA_SHA" ] || { echo 'Checked-out revision does not match the triggering commit.' >&2; exit 1; } short_sha=$(printf '%s' "$GITEA_SHA" | cut -c1-7) run_number="$GITEA_RUN_NUMBER" suffix="+build.$run_number.$short_sha" fi # minted in TeX Live 2022 expects its temporary files in the working directory. # Compile a disposable copy there instead of using pdflatex's output-directory. cp -R "$source_dir/." "$output_dir/intermediate/" printf '\\def\\CIBuildSuffix{%s}\n' "$suffix" > "$output_dir/intermediate/ci-build-metadata.tex" { printf 'Source revision: %s\nWorkflow run: %s\nVersion suffix: %s\n' "$revision" "$run_number" "$suffix" printf '\nToolchain:\n' pdflatex --version | head -n 1 latexmk -version git --version node --version } | tee "$output_dir/build-info.txt" cp /opt/manual-toolchain/packages.txt "$output_dir/toolchain-packages.txt" cd "$output_dir/intermediate" if latexmk -r "$repo_root/ci/manual/latexmkrc" -pdf -shell-escape \ -interaction=nonstopmode -halt-on-error -file-line-error \ devopsAssignment.tex \ > "$output_dir/compile-console.txt" 2>&1; then : else tail -n 65 "$output_dir/compile-console.txt" echo 'ERROR: LaTeX compilation failed.' >&2 exit 1 fi test -s "$output_dir/intermediate/devopsAssignment.pdf" || { echo 'ERROR: compiler returned without the expected PDF.' >&2 exit 1 } cp "$output_dir/intermediate/devopsAssignment.pdf" "$output_dir/2026F-SSW-590-DevOps-Group-1.pdf" sha256sum "$output_dir/2026F-SSW-590-DevOps-Group-1.pdf" | tee "$output_dir/pdf-sha256.txt" printf '\nPASS: PDF created at build/manual/2026F-SSW-590-DevOps-Group-1.pdf\n' printf 'Visible version suffix: %s\n' "$suffix"