From ac1534737825d103d7d13f09dd3452152c38cd8b Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 5 Jan 2025 19:53:55 +0400 Subject: [PATCH] test latex action --- .github/hello-paper/main.tex | 37 ++++++ .github/hello-paper/references.bib | 17 +++ .github/workflows/latex.yml | 34 ++++++ actions/latex/action.yml | 188 ++++++++++++++++++++++------- 4 files changed, 230 insertions(+), 46 deletions(-) create mode 100644 .github/hello-paper/main.tex create mode 100644 .github/hello-paper/references.bib create mode 100644 .github/workflows/latex.yml diff --git a/.github/hello-paper/main.tex b/.github/hello-paper/main.tex new file mode 100644 index 00000000..916e7df0 --- /dev/null +++ b/.github/hello-paper/main.tex @@ -0,0 +1,37 @@ +% paper written by Claude AI +\begin{document} +\maketitle + +\begin{abstract} +This paper provides a brief overview of the simple harmonic oscillator, +focusing on its mathematical description and physical significance. We discuss +the fundamental equation of motion and its solution, demonstrating why this +system serves as a cornerstone model in physics. +\end{abstract} + +\section{Introduction} +The simple harmonic oscillator is one of the most fundamental models in physics. +Its applications range from the motion of pendulums to the behavior of atoms +in crystal lattices \citep{feynman1963}. + +\section{Mathematical Description} +The equation of motion for a simple harmonic oscillator is given by: + +\begin{equation} + \frac{d^2x}{dt^2} + \omega^2x = 0 +\end{equation} + +where $\omega$ is the angular frequency of oscillation. The general solution +to this equation is: + +\begin{equation} + x(t) = A\cos(\omega t + \phi) +\end{equation} + +where $A$ is the amplitude and $\phi$ is the phase constant +\citep{goldstein2002}. + +\bibliography{references} +\bibliographystyle{plainnat} + +\end{document} diff --git a/.github/hello-paper/references.bib b/.github/hello-paper/references.bib new file mode 100644 index 00000000..ea514de5 --- /dev/null +++ b/.github/hello-paper/references.bib @@ -0,0 +1,17 @@ +% references.bib +@book{feynman1963, + author = {Feynman, Richard P. and Leighton, Robert B. and Sands, Matthew}, + title = {The Feynman Lectures on Physics}, + year = {1963}, + publisher = {Addison-Wesley}, + address = {Reading, MA} +} + +@book{goldstein2002, + author = {Goldstein, Herbert and Poole, Charles and Safko, John}, + title = {Classical Mechanics}, + year = {2002}, + edition = {3rd}, + publisher = {Addison Wesley}, + address = {San Francisco} +} diff --git a/.github/workflows/latex.yml b/.github/workflows/latex.yml new file mode 100644 index 00000000..825e19f2 --- /dev/null +++ b/.github/workflows/latex.yml @@ -0,0 +1,34 @@ +name: LATEX + +on: + push + +jobs: + build_paper: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Cat action + run: | + cat ./actions/latex/action.yml + + #- name: Build LaTeX document + # uses: ./actions/latex + # with: + # paper: ".github/hello-paper/main.tex" + #secrets: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + #- name: Upload build artifacts + # uses: actions/upload-artifact@v4 + # with: + # name: latex-build-${{ github.sha }} + # path: publish/ + # retention-days: 7 diff --git a/actions/latex/action.yml b/actions/latex/action.yml index fc936470..ecfe3da9 100644 --- a/actions/latex/action.yml +++ b/actions/latex/action.yml @@ -11,76 +11,172 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -name: Compile a LaTeX document +name: Compile and Deploy LaTeX Documents -description: "Compile a LaTeX document and upload it" +description: "Advanced LaTeX document compilation with error handling and artifacts" permissions: contents: write + pages: write + id-token: write on: workflow_call: inputs: paper: - description: 'paper' + description: 'Space-separated list of LaTeX files to compile' type: string required: true - - GITHUB_TOKEN: - required: true - output-folder: - description: 'output folder' + description: 'Output directory for compiled documents' type: string required: false default: '' - draft: - description: 'branch for draft' + description: 'Target branch for deployment' type: string required: false default: 'draft' + enable-cache: + description: 'Enable Tectonic caching' + type: boolean + required: false + default: true + create-release: + description: 'Create a GitHub release with compiled PDFs' + type: boolean + required: false + default: false + secrets: + GITHUB_TOKEN: + required: true runs: using: "composite" steps: - - name: Set up Git repository - uses: actions/checkout@v4 - - - uses: actions/cache@v4 - name: Tectonic Cache - with: - path: ~/.cache/Tectonic - key: ${{ runner.os }}-tectonic-${{ hashFiles('**/*.tex') }} - restore-keys: | - ${{ runner.os }}-tectonic- - - - uses: wtfjoke/setup-tectonic@v3 - with: - github-token: ${{ inputs.GITHUB_TOKEN }} - biber-version: '2.17' - - - name: Run Tectonic - shell: bash - env: - # as recommended by the problems in - # https://github.com/cvxgrp/robust_erm_note/actions/runs/5250958945/jobs/9485425629#step:5:1 - RUST_BACKTRACE: '1' - run: | - mkdir -p publish${{ inputs.output-folder }} - echo "Compiling ${{ inputs.paper }}" - for f in ${{ inputs.paper }} - do - echo "-- Compiling $f" - tectonic $f --outdir publish${{ inputs.output-folder }} + - name: Set up Git repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Full history for versioning + + - name: Setup environment variables + shell: bash + run: | + echo "TIMESTAMP=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV + echo "BUILD_DIR=build_${{ github.run_id }}" >> $GITHUB_ENV + + - name: Validate input files + shell: bash + run: | + for f in ${{ inputs.paper }}; do + if [ ! -f "$f" ]; then + echo "Error: File $f not found!" + exit 1 + fi + done + + - name: Setup Tectonic cache + if: inputs.enable-cache + uses: actions/cache@v4 + with: + path: | + ~/.cache/Tectonic + **/_minted* + key: ${{ runner.os }}-tectonic-${{ hashFiles('**/*.tex', '**/*.bib') }} + restore-keys: | + ${{ runner.os }}-tectonic- + + - name: Install Tectonic and dependencies + uses: wtfjoke/setup-tectonic@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + biber-version: '2.17' + # Add additional LaTeX packages if needed + packages: | + fonts-extra + standalone + latexmk + + - name: Create output directories + shell: bash + run: | + mkdir -p ${{ env.BUILD_DIR }} + mkdir -p publish${{ inputs.output-folder }} + + - name: Compile LaTeX documents + shell: bash + env: + RUST_BACKTRACE: '1' + run: | + echo "Starting compilation at $(date)" + + # Function to compile a single document + compile_doc() { + local doc="$1" + echo "Compiling $doc" + + # First pass + if ! tectonic "$doc" --outdir ${{ env.BUILD_DIR }} --keep-logs; then + echo "Error compiling $doc - check logs" + return 1 + fi + + # Copy final PDF to publish directory + cp ${{ env.BUILD_DIR }}/*.pdf publish${{ inputs.output-folder }}/ + echo "Successfully compiled $doc" + } + + # Export the function for parallel use + export -f compile_doc + + # Compile documents in parallel using GNU parallel if available + if command -v parallel >/dev/null 2>&1; then + echo ${{ inputs.paper }} | tr ' ' '\n' | parallel compile_doc + else + # Fall back to sequential compilation + for f in ${{ inputs.paper }}; do + compile_doc "$f" || exit 1 + done + fi + + - name: Generate compilation report + shell: bash + run: | + { + echo "# LaTeX Compilation Report" + echo "Generated: $(date)" + echo "## Compiled Documents" + for f in publish${{ inputs.output-folder }}/*.pdf; do + echo "- $(basename $f)" + echo " - Size: $(ls -lh "$f" | awk '{print $5}')" + echo " - SHA256: $(sha256sum "$f" | cut -d' ' -f1)" done + } > publish${{ inputs.output-folder }}/compilation_report.md + - name: Create GitHub Release + if: inputs.create-release + uses: softprops/action-gh-release@v1 + with: + files: publish${{ inputs.output-folder }}/*.pdf + name: LaTeX Build ${{ env.TIMESTAMP }} + body_path: publish${{ inputs.output-folder }}/compilation_report.md + draft: true + token: ${{ secrets.GITHUB_TOKEN }} - # Push the paper folder to the draft branch - - name: GitHub Pages action - uses: JamesIves/github-pages-deploy-action@v4 - with: - branch: ${{ inputs.draft || 'draft' }} # The branch the action should deploy to. - folder: publish${{ inputs.output-folder }} # The folder the action should deploy. + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: ${{ inputs.draft }} + folder: publish${{ inputs.output-folder }} + commit-message: "Build: ${{ env.TIMESTAMP }} [skip ci]" + clean: true + single-commit: false - # To make your draft folder public you would have to go to Settings => Pages + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: latex-build-${{ env.TIMESTAMP }} + path: | + publish${{ inputs.output-folder }} + ${{ env.BUILD_DIR }}/*.log + retention-days: 7