Skip to content

Conversation

@jstirnaman
Copy link
Contributor

Summary

This PR completes the PR preview system fixes started in #6665:

  • Fix product-name shortcode: Add prPreviewPathOffset support so product names resolve correctly in subdirectory deployments
  • Fix sidebar navigation: Add path offset to sidebar partial so navigation menu displays correctly
  • Handle fork PRs gracefully: Skip preview deployment for fork PRs (GitHub security limitation) and post helpful comment with local preview instructions

Background

PR #6659 (from a fork) was failing because:

  1. Fork PRs have read-only GITHUB_TOKEN access to the base repository
  2. The workflow couldn't push to gh-pages branch

Additionally, after merging #6665, previews were working but product-name shortcode and sidebar weren't rendering because they used the same vulnerable .RelPermalink parsing pattern.

Changes

Shortcode/Partial Fixes

  • layouts/shortcodes/product-name.html - Add path offset for subdirectory baseURL
  • layouts/partials/sidebar.html - Add path offset for product/version detection

Workflow Improvements

  • Add condition to skip preview job for fork PRs
  • Add fork-notice job to post explanatory comment for fork PR contributors

Test plan

  • Verify same-repo PRs still get preview deployments
  • Verify fork PRs get the notice comment instead of failing
  • Check preview pages show correct product name and sidebar navigation

When PR preview builds use a subdirectory baseURL like
/docs-v2/pr-preview/pr-XXXX/, shortcodes that parse .RelPermalink
to detect product context fail because the path has extra segments.

This fix:
- Adds config/pr-preview/params.yml with prPreviewPathOffset: 3
- Updates workflow to use -e pr-preview environment
- Updates api-endpoint, influxdb/host, and children shortcodes to
  use the offset when indexing path segments
- Adds nil-safety with default fallback for placeholder_host

Normal builds are unaffected (offset defaults to 0).
Apply the same prPreviewPathOffset fix to product-name.html and
sidebar.html that was applied in the initial PR #6665.

These templates parse RelPermalink to detect product context, but when
baseURL includes a subdirectory path (e.g., /docs-v2/pr-preview/pr-XXXX/),
the path indices shift. This fix uses the configurable offset to skip
extra path segments in PR preview builds.
Fork PRs cannot deploy to gh-pages because GITHUB_TOKEN has read-only
access to the base repository. This is a GitHub security feature.

Changes:
- Add condition to skip preview job for fork PRs
- Add fork-notice job to post helpful comment explaining limitation
- Include local preview instructions for contributors
@jstirnaman jstirnaman merged commit 0fbf9e5 into master Dec 22, 2025
6 checks passed
@jstirnaman jstirnaman deleted the ci-pr-preview branch December 22, 2025 21:30
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