Skip to content

Add GitHub Actions workflow for PR documentation previews#8

Merged
samuelduchesne merged 1 commit intomainfrom
claude/add-docs-preview-pr-wEwyy
Feb 25, 2026
Merged

Add GitHub Actions workflow for PR documentation previews#8
samuelduchesne merged 1 commit intomainfrom
claude/add-docs-preview-pr-wEwyy

Conversation

@samuelduchesne
Copy link
Copy Markdown
Contributor

Summary

This PR adds a new GitHub Actions workflow that automatically generates and deploys documentation previews for pull requests, making it easier for reviewers to see documentation changes before merging.

Key Changes

  • New workflow file: .github/workflows/pr-docs-preview.yml
    • Triggers on PR open, synchronize, reopen, and close events
    • Generates documentation previews by cloning the EnergyPlus source repository and converting documentation
    • Deploys previews to the gh-pages branch under pr-preview/pr-{number}/
    • Automatically adds or updates a comment on the PR with a link to the preview
    • Cleans up preview directories when PRs are closed

Implementation Details

  • Uses sparse checkout to efficiently clone only the doc/ directory from the EnergyPlus repository
  • Leverages existing Python environment setup and conversion scripts
  • Installs Pandoc for documentation conversion
  • Manages concurrency to cancel in-progress runs for the same PR
  • Uses GitHub Script action to manage preview comments, creating new ones or updating existing ones
  • Implements proper git configuration for automated commits to the gh-pages branch
  • Includes conditional logic to separate deployment and cleanup jobs based on PR action type

https://claude.ai/code/session_01E38miZodYjjJERhXvXsAG1

Deploy a docs preview for the latest EnergyPlus version to gh-pages
when a pull request is opened or updated. The preview is published to
a pr-preview/pr-<number>/ subdirectory, and a bot comment with the
preview link is posted on the PR. The preview is cleaned up when the
PR is closed.

https://claude.ai/code/session_01E38miZodYjjJERhXvXsAG1
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ea9b0fe6d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

git diff --cached --quiet || {
git commit -m "Deploy docs preview for PR #${{ github.event.number }}"
git pull --rebase origin gh-pages
git push origin gh-pages
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Gate gh-pages pushes for fork pull requests

This workflow is triggered for all pull_request events and always attempts to push to gh-pages, but forked PRs run with a read-only workflow token, so the deploy path fails even when conversion succeeds. That means external contributors (the main OSS contribution path) will consistently get a failing preview job and no preview URL. Add a fork check to skip write operations (or move to a safe pull_request_target pattern) so fork PRs do not hard-fail.

Useful? React with 👍 / 👎.

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.

@codex what is a safe pull_request_target pattern?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Safe pull_request_target pattern (answer to your question)

If you do choose pull_request_target, the safe pattern is:

  1. Run only trusted/privileged actions there (labeling, commenting, dispatching, metadata checks).
  2. Do not run untrusted PR code directly in that context (no checkout of PR head + build using secrets/write token).
  3. Split workflows: untrusted build/test on pull_request; privileged publish/comment on pull_request_target (or via workflow_run) with strict conditions/allowlists.

For this PR, I implemented the safer immediate fix requested by review: fork-aware write gating on pull_request, which prevents hard-failures for external contributors while preserving behavior for same-repo PRs. .github/workflows/pr-docs-preview.ymlL17-L25 .github/workflows/pr-docs-preview.ymlL64-L83

Testing

  • ruby -e "require 'yaml'; YAML.load_file('.github/workflows/pr-docs-preview.yml'); puts 'YAML OK'"
  • ⚠️ python - <<'PY'\nimport yaml,sys\nwith open('.github/workflows/pr-docs-preview.yml') as f:\n yaml.safe_load(f)\nprint('YAML OK')\nPY (warning: PyYAML is not installed in the environment)
  • curl -Ls https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows | rg -n "pull_request_target|Warning|security" | head -n 20

Committed and opened a follow-up PR via the required PR tool.

View task →

@idfkit idfkit deleted a comment from chatgpt-codex-connector Bot Feb 25, 2026
@idfkit idfkit deleted a comment from chatgpt-codex-connector Bot Feb 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Docs preview for this PR is available at:
https://docs.idfkit.com/pr-preview/pr-8/

github-actions Bot added a commit that referenced this pull request Feb 25, 2026
@samuelduchesne samuelduchesne merged commit aed8a57 into main Feb 25, 2026
4 checks passed
@samuelduchesne samuelduchesne deleted the claude/add-docs-preview-pr-wEwyy branch February 25, 2026 14:56
github-actions Bot added a commit that referenced this pull request Feb 25, 2026
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