|
| 1 | +name: Compile LaTeX |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - '**.tex' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + compile: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Install LaTeX |
| 20 | + run: | |
| 21 | + sudo apt-get update |
| 22 | + sudo apt-get install -y texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra |
| 23 | +
|
| 24 | + - name: Compile LaTeX document |
| 25 | + id: compile |
| 26 | + run: | |
| 27 | + set +e |
| 28 | + # Run compilation and capture output |
| 29 | + output=$(bash compile.sh 2>&1) |
| 30 | + exit_code=$? |
| 31 | + echo "$output" |
| 32 | + |
| 33 | + # Store output for later use (handle multiline) |
| 34 | + { |
| 35 | + echo "output<<EOF" |
| 36 | + echo "$output" |
| 37 | + echo "EOF" |
| 38 | + } >> $GITHUB_OUTPUT |
| 39 | + |
| 40 | + exit $exit_code |
| 41 | +
|
| 42 | + - name: Post error comment and close PR on failure |
| 43 | + if: failure() |
| 44 | + uses: actions/github-script@v7 |
| 45 | + env: |
| 46 | + COMPILE_OUTPUT: ${{ steps.compile.outputs.output }} |
| 47 | + with: |
| 48 | + script: | |
| 49 | + const output = process.env.COMPILE_OUTPUT || 'No output captured'; |
| 50 | + const prAuthor = context.payload.pull_request.user.login; |
| 51 | + |
| 52 | + // Post comment with compilation errors |
| 53 | + await github.rest.issues.createComment({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + issue_number: context.payload.pull_request.number, |
| 57 | + body: `@${prAuthor} The LaTeX compilation failed with the following errors:\n\n\`\`\`\n${output}\n\`\`\`` |
| 58 | + }); |
| 59 | + |
| 60 | + // Close the pull request |
| 61 | + await github.rest.pulls.update({ |
| 62 | + owner: context.repo.owner, |
| 63 | + repo: context.repo.repo, |
| 64 | + pull_number: context.payload.pull_request.number, |
| 65 | + state: 'closed' |
| 66 | + }); |
0 commit comments