Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 70 additions & 13 deletions .github/workflows/gen_pdf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,96 @@ name: Generate PDF
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions:
contents: write
pull-requests: write

jobs:
gen-pdf:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: biohackathon name given?
run: |
sed -n '/^---$/,/^---$/{//b;p}' paper/paper.md | grep biohackathon_name
- name: biohackathon location given?
run: |
sed -n '/^---$/,/^---$/{//b;p}' paper/paper.md | grep biohackathon_location
- name: biohackathon url given?

- name: Validate metadata
run: |
sed -n '/^---$/,/^---$/{//b;p}' paper/paper.md | grep biohackathon_url
- name: Git repository given?
run: |
sed -n '/^---$/,/^---$/{//b;p}' paper/paper.md | grep git_url
- uses: kohlerdominik/docker-run-action@v2.0.0
# Extract YAML front matter
YAML=$(sed -n '/^---$/,/^---$/{//b;p}' paper/paper.md)
ERRORS=""
for field in biohackathon_name biohackathon_location biohackathon_url git_url; do
if ! echo "$YAML" | grep -q "$field"; then
ERRORS="${ERRORS} - Missing required field: ${field}\n"
fi
done
if [ -n "$ERRORS" ]; then
echo "::error::Metadata validation failed"
echo -e "The following required fields are missing from paper/paper.md:\n${ERRORS}"
echo "See https://index.biohackrxiv.org/for-submitters/ for details on required metadata."
exit 1
fi
echo "All required metadata fields present."

- name: Generate PDF
uses: kohlerdominik/docker-run-action@v2.0.0
with:
image: ghcr.io/biohackrxiv/bhxiv-gen-pdf:master
volumes: ${{ github.workspace }}:/work
workdir: /work
run: |
gen-pdf paper

- name: Create info file
run: |
echo -e "ref: $GITHUB_REF \ncommit: $GITHUB_SHA\nbuild: $(date +"%Y-%m-%dT%H:%M:%SZ")" \
> info.txt

- name: Upload generated PDF as artifact
uses: actions/upload-artifact@v4
with:
name: PDF and info.txt
name: paper
path: |
paper/paper.pdf
info.txt

- name: Commit PDF to repository
if: github.event_name == 'push'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add paper/paper.pdf
git diff --cached --quiet && echo "No changes to PDF" || git commit -m "Update paper.pdf [skip ci]" && git push

- name: Comment on PR with PDF link
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = `### PDF Preview Ready\n\nThe PDF has been generated successfully. Download it from the [Actions artifacts](${runUrl}#artifacts).`;
// Check for existing bot comment to avoid duplicates
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('### PDF Preview Ready')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body,
});
}