Skip to content

Build your personal knowledge base with Trilium Notes

ci(pdfjs): put the upstream changelog in the PR body

Elian Doran311e6ec8b54c
diff --git a/.github/workflows/update-pdfjs-viewer.yml b/.github/workflows/update-pdfjs-viewer.yml
index f1b2312582..eca30914a5 100644
--- a/.github/workflows/update-pdfjs-viewer.yml
+++ b/.github/workflows/update-pdfjs-viewer.yml
@@ -52,11 +52,16 @@ jobs:
# exact pin exact. It installs too, which the re-vendor and the suites below
# need — build.ts copies the library straight out of node_modules.
run: |
+ read_version() { node -p "require('./packages/pdfjs-viewer/package.json').devDependencies['pdfjs-dist']"; }
+ from=$(read_version)
pnpm --filter pdfjs-viewer update pdfjs-dist --latest
- git diff --quiet -- packages/pdfjs-viewer/package.json && changed=false || changed=true
- echo "changed=$changed" >> "$GITHUB_OUTPUT"
- version=$(node -p "require('./packages/pdfjs-viewer/package.json').devDependencies['pdfjs-dist']")
- echo "version=$version" >> "$GITHUB_OUTPUT"
+ to=$(read_version)
+ [ "$from" = "$to" ] && changed=false || changed=true
+ {
+ echo "from=$from"
+ echo "to=$to"
+ echo "changed=$changed"
+ } >> "$GITHUB_OUTPUT"
- name: Re-vendor the viewer
# Fails loudly if our viewer.html patches no longer match upstream's markup.
if: steps.bump.outputs.changed == 'true'
@@ -82,6 +87,56 @@ jobs:
with:
name: pdfjs-viewer e2e report
path: packages/pdfjs-viewer/test-output
+ - name: Compose the PR body
+ # Written to a file rather than inlined below, because upstream's release notes
+ # run to tens of kilobytes of markdown and would not survive YAML interpolation.
+ if: steps.bump.outputs.changed == 'true'
+ env:
+ GH_TOKEN: ${{ github.token }}
+ FROM: ${{ steps.bump.outputs.from }}
+ TO: ${{ steps.bump.outputs.to }}
+ run: |
+ body="$RUNNER_TEMP/pr-body.md"
+ printf 'Updates `pdfjs-dist` from %s to %s **and** re-vendors the viewer under\n' "$FROM" "$TO" > "$body"
+ cat >> "$body" <<'EOF'
+ `packages/pdfjs-viewer/viewer` from the matching pdf.js release. The two have to
+ move together — pdf.js refuses to start when their versions disagree — which is
+ why neither Renovate nor Dependabot handles this dependency.
+
+ Re-vendoring re-applies our patches to `viewer.html` (the custom stylesheet and
+ script, and the relaxed `style-src-elem` CSP) and fails if upstream's markup moved
+ out from under them.
+
+ CI ran the unit and Playwright suites against the result before opening this PR,
+ since a scheduled run's PR does not start workflows of its own.
+
+ ### Vendored files changed
+
+ Only `viewer.html` is patched by us; everything else is upstream verbatim.
+
+ ```
+ EOF
+ git diff --stat --stat-count=12 -- packages/pdfjs-viewer/viewer >> "$body"
+ printf '```\n\n' >> "$body"
+
+ # Upstream's notes are cumulative since the previous stable release, so they cover
+ # this hop exactly — unless more than one release was skipped, hence the compare
+ # link, which is always exact.
+ printf '[Upstream comparison](https://github.com/mozilla/pdf.js/compare/v%s...v%s)\n\n' "$FROM" "$TO" >> "$body"
+ notes=$(gh api "/repos/mozilla/pdf.js/releases/tags/v$TO" --jq .body 2>/dev/null || true)
+ if [ -n "$notes" ]; then
+ if [ "${#notes}" -gt 30000 ]; then
+ notes=$(printf '%s' "$notes" | head -c 30000)
+ notes="$notes"$'\n\n_Release notes truncated._'
+ fi
+ {
+ printf '<details>\n<summary>pdf.js release notes for v%s</summary>\n\n' "$TO"
+ printf '%s\n\n' "$notes"
+ printf '</details>\n'
+ } >> "$body"
+ else
+ printf '_No GitHub release notes found for v%s._\n' "$TO" >> "$body"
+ fi
- name: Open a PR
if: steps.bump.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v8
@@ -91,21 +146,7 @@ jobs:
packages/pdfjs-viewer/viewer
pnpm-lock.yaml
branch: chore/update-pdfjs-viewer
- commit-message: "build(pdfjs): update to pdf.js ${{ steps.bump.outputs.version }}"
- title: "build(pdfjs): update to pdf.js ${{ steps.bump.outputs.version }}"
- body: |
- Updates `pdfjs-dist` to ${{ steps.bump.outputs.version }} **and** re-vendors
- the viewer under `packages/pdfjs-viewer/viewer` from the matching pdf.js
- release. The two have to move together — pdf.js refuses to start when their
- versions disagree — which is why Renovate does not handle this dependency.
-
- Re-vendoring re-applies our patches to `viewer.html` (the custom stylesheet
- and script, and the relaxed `style-src-elem` CSP) and fails if upstream's
- markup moved out from under them.
-
- CI ran the unit and Playwright suites against the result before opening this
- PR, since a scheduled run's PR does not start workflows of its own.
-
- The diff is large and machine-generated; `viewer.html` is the file worth
- reading, since that is the only one we patch.
+ commit-message: "build(pdfjs): update to pdf.js ${{ steps.bump.outputs.to }}"
+ title: "build(pdfjs): update to pdf.js ${{ steps.bump.outputs.to }}"
+ body-path: ${{ runner.temp }}/pr-body.md
labels: dependencies