ci: add changed page links to docs PR preview comments#2813
ci: add changed page links to docs PR preview comments#2813
Conversation
After deploying a docs preview, post a comment listing up to 5 changed pages with direct links to the preview. Resolves slugs from frontmatter when present, falls back to file path.
- Fix race condition: retry 3x with 10s sleep to find preview comment - Compute file list once instead of two separate execSync calls - Filter out deleted files (fs.existsSync) to avoid broken links - Strip quotes from frontmatter slug values - Add error handling for git fetch - Add comments explaining key decisions
aeluce
left a comment
There was a problem hiding this comment.
Definitely useful. The script could be streamlined (the workflow feels a bit tenuous relying on matching strings and retries), but let me know if no alternatives seem to fit.
| with: | ||
| source-dir: ./site/build/ | ||
| - name: Comment with changed pages | ||
| if: github.event.action != 'closed' |
There was a problem hiding this comment.
Should more of the previous steps be conditional like this? (Are we currently trying to build and deploy when a PR gets closed? 🤔)
There was a problem hiding this comment.
Good catch — added if: github.event.action \!= 'closed' to the build, install, and setup-node steps. No point building the site on PR close.
| // Get all changed docs files, filter to md/mdx, exclude deleted files | ||
| const allFiles = execSync('git diff --name-only origin/master -- site/docs/') | ||
| .toString().trim().split('\n') | ||
| .filter(f => /\.(md|mdx)$/.test(f)) |
There was a problem hiding this comment.
I don't believe we currently have any .mdx files in docs anymore, though that could always change again in the future.
There was a problem hiding this comment.
Removed — no .mdx files in docs currently.
| const pagesBlock = `\n\n📄 **Changed pages:**\n${links.join('\n')}${suffix}`; | ||
|
|
||
| // Append to the PR Preview Action comment to keep the PR tidy. | ||
| // Retry a few times since the preview action posts its comment asynchronously. |
There was a problem hiding this comment.
It feels messy to find the right comment by searching for a hardcoded message. Is there a better way to do this?
We could potentially manage the sticky comment ourselves so that we create the customized version all at once rather than create the generic comment, search for it, then edit it. I believe that would also mean we wouldn't have to worry about stripping the comment body on re-runs or defaulting to a regular comment if we can't find the PR preview one.
There was a problem hiding this comment.
Agreed — refactored to use marocchino/sticky-pull-request-comment with comment: false on the preview action. Now we build the full comment (preview link + changed pages) in one shot. No more string matching, retries, or regex stripping.
Address review feedback: - Use marocchino/sticky-pull-request-comment for a single managed comment - Disable rossjrw/pr-preview-action's built-in comment - Add if: != 'closed' to build/install steps (skip on PR close) - Remove retry logic, string matching, and regex stripping - Remove .mdx filter (no mdx files in docs currently)
|
🚀 Preview deployed to https://docs.estuary.dev/pr-preview/pr-2813/ 📄 Changed pages: |
Summary
After deploying a docs preview, posts a comment listing up to 5 changed pages with direct links to the preview URL. Resolves slugs from frontmatter when present, falls back to file path.
Includes a trivial docs change to trigger the workflow for testing - you can see the '📄 Changed pages:' addition in the below comment
How it works
.md/.mdxundersite/docs/slug:from frontmatter if present, otherwise derives path from filenameREADME.md→ parent directory, deleted files, and slug edge cases