Skip to content

Merge to main

Merge to main #22

Workflow file for this run

name: Screenshot Preview
on:
pull_request:
types: [opened, synchronize]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
screenshot:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Cache Puppeteer Chrome
uses: actions/cache@v4
with:
path: ~/.cache/puppeteer
key: puppeteer-chrome-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: puppeteer-chrome-${{ runner.os }}-
- name: Install dependencies
run: npm ci
- name: Install Ghostscript
run: sudo apt-get install -y ghostscript
- name: Build HTML and PDF
run: node build.js
- name: Convert PDF pages to PNG
run: |
gs -dNOPAUSE -dBATCH -sDEVICE=png16m -r150 \
-sOutputFile='screenshots/pdf-page-%d.png' resume.pdf
- name: Push screenshots to screenshots branch
id: store
run: |
HTML_FILE="run-${{ github.run_id }}-html.png"
PDF_P1_FILE="run-${{ github.run_id }}-pdf-p1.png"
PDF_P2_FILE="run-${{ github.run_id }}-pdf-p2.png"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Fetch screenshots branch if it exists
git fetch origin screenshots 2>/dev/null || true
# Create a worktree pointing at the screenshots branch (or a new orphan)
if git show-ref --verify --quiet refs/remotes/origin/screenshots; then
git worktree add /tmp/screenshots-worktree -b screenshots-ci origin/screenshots
else
git worktree add --detach /tmp/screenshots-worktree HEAD
cd /tmp/screenshots-worktree
git checkout --orphan screenshots-ci
git rm -rf . 2>/dev/null || true
cd - > /dev/null
fi
cp screenshots/html-screenshot.png "/tmp/screenshots-worktree/$HTML_FILE"
cp screenshots/pdf-page-1.png "/tmp/screenshots-worktree/$PDF_P1_FILE"
HAS_P2=false
if [ -f screenshots/pdf-page-2.png ]; then
cp screenshots/pdf-page-2.png "/tmp/screenshots-worktree/$PDF_P2_FILE"
HAS_P2=true
fi
cd /tmp/screenshots-worktree
git add "$HTML_FILE" "$PDF_P1_FILE"
if $HAS_P2; then git add "$PDF_P2_FILE"; fi
git commit -m "Screenshots for run ${{ github.run_id }}"
git push origin HEAD:screenshots
BASE_URL="https://raw.githubusercontent.com/${{ github.repository }}/screenshots"
echo "html_url=${BASE_URL}/${HTML_FILE}" >> "$GITHUB_OUTPUT"
echo "pdf_p1_url=${BASE_URL}/${PDF_P1_FILE}" >> "$GITHUB_OUTPUT"
if $HAS_P2; then
echo "pdf_p2_url=${BASE_URL}/${PDF_P2_FILE}" >> "$GITHUB_OUTPUT"
fi
echo "has_p2=${HAS_P2}" >> "$GITHUB_OUTPUT"
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const htmlUrl = '${{ steps.store.outputs.html_url }}';
const pdfP1Url = '${{ steps.store.outputs.pdf_p1_url }}';
const pdfP2Url = '${{ steps.store.outputs.pdf_p2_url }}';
const hasP2 = '${{ steps.store.outputs.has_p2 }}' === 'true';
const runUrl = `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`;
let pdfSection = `### PDF (page 1)\n![PDF Page 1](${pdfP1Url})\n`;
if (hasP2) {
pdfSection += `\n### PDF (page 2)\n![PDF Page 2](${pdfP2Url})\n`;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `## 📸 Screenshot Preview\n\n### HTML (screen)\n![HTML Preview](${htmlUrl})\n\n${pdfSection}\n*Generated by [run #${{ github.run_id }}](${runUrl})*`,
});