Skip to content

ci: add changed page links to docs PR preview comments#2813

Merged
jwhartley merged 5 commits intomasterfrom
ci/docs-preview-changed-pages
Mar 31, 2026
Merged

ci: add changed page links to docs PR preview comments#2813
jwhartley merged 5 commits intomasterfrom
ci/docs-preview-changed-pages

Conversation

@jwhartley
Copy link
Copy Markdown
Contributor

@jwhartley jwhartley commented Mar 27, 2026

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

  • Filters changed files to .md/.mdx under site/docs/
  • Reads slug: from frontmatter if present, otherwise derives path from filename
  • Handles README.md → parent directory, deleted files, and slug edge cases
  • Shows "... and N more" if >5 pages changed

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.
@estuary estuary deleted a comment from github-actions Bot Mar 27, 2026
@jwhartley jwhartley requested a review from aeluce March 27, 2026 04:04
- 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
Copy link
Copy Markdown
Collaborator

@aeluce aeluce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should more of the previous steps be conditional like this? (Are we currently trying to build and deploy when a PR gets closed? 🤔)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — added if: github.event.action \!= 'closed' to the build, install, and setup-node steps. No point building the site on PR close.

Comment thread .github/workflows/docs-ci-previews.yaml Outdated
// 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))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we currently have any .mdx files in docs anymore, though that could always change again in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed — no .mdx files in docs currently.

Comment thread .github/workflows/docs-ci-previews.yaml Outdated
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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 30, 2026

🚀 Preview deployed to https://docs.estuary.dev/pr-preview/pr-2813/

📄 Changed pages:

@estuary estuary deleted a comment from github-actions Bot Mar 30, 2026
@jwhartley jwhartley requested a review from aeluce March 31, 2026 00:12
Copy link
Copy Markdown
Collaborator

@aeluce aeluce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! 🙌

@jwhartley jwhartley merged commit 1e77866 into master Mar 31, 2026
12 checks passed
@jwhartley jwhartley deleted the ci/docs-preview-changed-pages branch March 31, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants