Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,45 @@ jobs:
echo "should-run=true" >> $GITHUB_OUTPUT
fi

# Notify fork PRs that preview is not available
fork-notice:
needs: check-draft
if: |
needs.check-draft.outputs.should-run == 'true' &&
github.event.action != 'closed' &&
github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- name: Post fork notice comment
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});

const marker = '<!-- pr-preview-fork-notice -->';
const existing = comments.find(c => c.body.includes(marker));

if (!existing) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `${marker}\n## 📝 PR Preview Not Available\n\nPR previews are not available for pull requests from forks due to GitHub Actions security restrictions.\n\nTo preview your changes locally, run:\n\`\`\`bash\nnpx hugo server\n\`\`\`\n\nOnce merged, your changes will be visible on the production site.`
});
}

# Build and deploy preview
preview:
needs: check-draft
# Skip fork PRs - GITHUB_TOKEN doesn't have write access to push to gh-pages
if: |
needs.check-draft.outputs.should-run == 'true' &&
github.event.action != 'closed'
github.event.action != 'closed' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
6 changes: 4 additions & 2 deletions layouts/partials/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{{ $currentPage := . }}
{{ $productPathData := findRE "[^/]+.*?" .RelPermalink }}
{{ $product := index $productPathData 0 }}
{{/* Support deployments (such as CI tools) with subdirectory baseURL */}}
{{ $pathOffset := .Site.Params.prPreviewPathOffset | default 0 }}
{{ $product := index $productPathData (add $pathOffset 0) }}
{{ $productName := (index .Site.Data.products $product).name }}
{{ $currentVersion := index $productPathData 1 }}
{{ $currentVersion := index $productPathData (add $pathOffset 1) }}

<!-- Menu Key -->
{{ .Scratch.Set "menuKey" "menu"}}
Expand Down
4 changes: 3 additions & 1 deletion layouts/shortcodes/product-name.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
{{- $currentProduct := index $productPathData 1 -}}
{{- /* Support deployments (such as CI tools) with subdirectory baseURL */ -}}
{{- $pathOffset := .Site.Params.prPreviewPathOffset | default 0 -}}
{{- $currentProduct := index $productPathData (add $pathOffset 1) -}}
{{- $length := .Get 0 | default "long" -}}
{{- $omit := .Get "omit" | default "" -}}
{{- $scratch := newScratch -}}
Expand Down
Loading