Skip to content

Preview Update 31st July - #398

Merged
anarnold97 merged 2 commits into
migtools:mainfrom
anarnold97:Preview-Update-31July
Jul 31, 2026
Merged

Preview Update 31st July#398
anarnold97 merged 2 commits into
migtools:mainfrom
anarnold97:Preview-Update-31July

Conversation

@anarnold97

@anarnold97 anarnold97 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

PR #398 — Fork-Compatible PR Preview Workflows

Why this PR was needed

I made a fundamental mistake in PR #392 in which i worked on the logic that contributors work on branches within the migtools/mta-documentation repo itself.

In practice, contributors work on forks. GitHub intentionally gives fork PRs a read-only GITHUB_TOKEN as a security measure — malicious fork code cannot write to the upstream repo. The original workflows checked for this and simply skipped, which is why every fork PR showed "job skipped."

What PR #398 does differently

The original was a single workflow that built and deployed in one job. PR #398 splits this into three workflows using the pattern GitHub recommends for fork support.

PR #392 (original) PR #398 (this PR)
Build Single job, needed write token pr-preview.yml — read-only token, builds Jekyll, uploads _site as an artifact
Deploy Same job as build — failed for forks pr-preview-deploy.yml — new file, triggered by workflow_run, always runs in the base repo context so the write token is valid even for fork PRs
Cleanup Used pull_request event — skipped for forks pr-preview-cleanup.yml — switched to pull_request_target, which always runs in the base repo context
Fork PRs Skipped entirely Fully supported

Key technical detail

The workflow_run and pull_request_target events always execute in the context of the base repository (main branch), not the fork — so the write token is valid and can push to gh-pages regardless of where the PR originated.

Summary by CodeRabbit

  • New Features

    • Added automated preview deployments for pull requests.
    • Preview links are posted or updated directly in the pull request, along with the latest commit and update time.
    • Preview builds are stored temporarily before deployment, improving separation between build and publishing steps.
  • Bug Fixes

    • Improved preview cleanup and deployment reliability with retry handling for updates and rebased branches.
    • Failed updates are safely stopped before retrying, reducing the risk of inconsistent previews.

Signed-off-by: A.Arnold <anarnold@redhat.com>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The preview build now uploads a short-lived artifact. A separate workflow deploys the artifact to gh-pages, updates the PR comment, and handles push retries. Cleanup runs on closed PRs and handles failed rebases explicitly.

Changes

PR preview lifecycle

Layer / File(s) Summary
Build and upload preview artifact
.github/workflows/pr-preview.yml
The build workflow now uses read-only access, writes the PR number to _site/.pr-number, and uploads _site/ as pr-preview-site.
Deploy artifact to gh-pages
.github/workflows/pr-preview-deploy.yml
A separate workflow downloads the artifact, updates the PR-specific directory on gh-pages, retries rebased pushes, and creates or updates the marked preview comment.
Clean up closed previews
.github/workflows/pr-preview-cleanup.yml
Cleanup now runs through pull_request_target, removes the same-repository filter, and aborts failed rebases before retrying.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title identifies a preview update but does not state that the workflows were split to support fork pull requests. Use a specific title such as "Split PR Preview Workflows to Support Fork Pull Requests".
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vashirova vashirova left a comment

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.

LGTM

Signed-off-by: A.Arnold <anarnold@redhat.com>
@anarnold97
anarnold97 merged commit 3a01f02 into migtools:main Jul 31, 2026
0 of 2 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/pr-preview-deploy.yml (1)

42-53: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Use env vars instead of interpolating step outputs directly into github-script bodies.

pull_number: ${{ steps.pr.outputs.number }} (line 51) and const prNumber = ${{ steps.pr.outputs.number }}; / const sha = '${{ steps.sha.outputs.sha }}'; (lines 112-113) interpolate context expressions directly into JavaScript source before execution. zizmor flags this template-expansion pattern as a code-injection risk. pr-preview-cleanup.yml already avoids this by passing PR_NUMBER through env: and reading it with process.env.PR_NUMBER (lines 59-64 of that file). Apply the same pattern here.

🔒 Proposed fix
       - name: Get PR head SHA
         id: sha
         uses: actions/github-script@v7
+        env:
+          PR_NUMBER: ${{ steps.pr.outputs.number }}
         with:
           github-token: ${{ secrets.GITHUB_TOKEN }}
           script: |
             const pr = await github.rest.pulls.get({
               owner: context.repo.owner,
               repo:  context.repo.repo,
-              pull_number: ${{ steps.pr.outputs.number }},
+              pull_number: Number(process.env.PR_NUMBER),
             });
             core.setOutput('sha', pr.data.head.sha.substring(0, 7));
       - name: Post or update preview comment
         uses: actions/github-script@v7
+        env:
+          PR_NUMBER: ${{ steps.pr.outputs.number }}
+          COMMIT_SHA: ${{ steps.sha.outputs.sha }}
         with:
           github-token: ${{ secrets.GITHUB_TOKEN }}
           script: |
-            const prNumber = ${{ steps.pr.outputs.number }};
-            const sha      = '${{ steps.sha.outputs.sha }}';
+            const prNumber = Number(process.env.PR_NUMBER);
+            const sha      = process.env.COMMIT_SHA;

Also applies to: 107-153

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/pr-preview-deploy.yml around lines 42 - 53, Update the
github-script steps in pr-preview-deploy.yml, including “Get PR head SHA” and
the later script around prNumber/sha, to pass step outputs through the action’s
env block and read them via process.env inside JavaScript. Remove direct ${{
steps... }} interpolation from script bodies while preserving the existing PR
number and SHA behavior.

Source: Linters/SAST tools

.github/workflows/pr-preview.yml (1)

43-53: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use an env var for the PR number instead of inline interpolation.

Line 46 already exposes PR_NUMBER as an env var for the Jekyll build. Line 53 re-interpolates ${{ github.event.number }} directly into the shell command instead of reusing that pattern. pr-preview-cleanup.yml uses the safer env + variable pattern consistently (see its PR_NUMBER env and process.env.PR_NUMBER usage). Apply the same pattern here for consistency and defense-in-depth against template-expansion into shell.

♻️ Proposed fix
       - name: Save PR number for deploy workflow
-        run: echo "${{ github.event.number }}" > _site/.pr-number
+        env:
+          PR_NUMBER: ${{ github.event.number }}
+        run: echo "${PR_NUMBER}" > _site/.pr-number
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/pr-preview.yml around lines 43 - 53, Update the “Save PR
number for deploy workflow” step to expose PR_NUMBER through the step’s env
configuration and write the shell variable to _site/.pr-number, removing the
inline github.event.number interpolation. Keep the existing Jekyll build
PR_NUMBER usage unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/pr-preview-deploy.yml:
- Around line 10-12: Update the workflow’s top-level permissions block to
include actions: read alongside contents and pull-requests, so the artifact
download step using actions/download-artifact@v4 and a cross-run run-id can
authenticate successfully.

---

Nitpick comments:
In @.github/workflows/pr-preview-deploy.yml:
- Around line 42-53: Update the github-script steps in pr-preview-deploy.yml,
including “Get PR head SHA” and the later script around prNumber/sha, to pass
step outputs through the action’s env block and read them via process.env inside
JavaScript. Remove direct ${{ steps... }} interpolation from script bodies while
preserving the existing PR number and SHA behavior.

In @.github/workflows/pr-preview.yml:
- Around line 43-53: Update the “Save PR number for deploy workflow” step to
expose PR_NUMBER through the step’s env configuration and write the shell
variable to _site/.pr-number, removing the inline github.event.number
interpolation. Keep the existing Jekyll build PR_NUMBER usage unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e50d3c10-a3f6-4e6f-83d3-7e0d383ee11d

📥 Commits

Reviewing files that changed from the base of the PR and between 14123d0 and eb51e75.

📒 Files selected for processing (3)
  • .github/workflows/pr-preview-cleanup.yml
  • .github/workflows/pr-preview-deploy.yml
  • .github/workflows/pr-preview.yml

Comment on lines +10 to +12
permissions:
contents: write
pull-requests: write

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does actions/download-artifact v4 require actions:read permission to download an artifact from a different workflow run via run-id in the same repository?

💡 Result:

Yes, when using actions/download-artifact@v4 to download an artifact from a different workflow run (even within the same repository), you must provide a github-token with the appropriate permissions [1][2][3]. By default, the actions/download-artifact action is scoped to the current workflow run [1][4]. To access artifacts from a different run, you must specify the github-token input [2][3]. This token must have at least actions:read permissions for the target repository to successfully authenticate the request via the GitHub API [5][6]. While the default GITHUB_TOKEN provided in a standard workflow environment is typically scoped to the current repository and workflow, it may lack the necessary permissions to access artifacts from other workflow runs unless specifically configured or replaced with a token (such as a Personal Access Token or a scoped installation token) that possesses the required actions:read access [5]. If the provided token lacks these permissions, the action will fail during the API call [5].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Workflow metadata:"
if [ -f .github/workflows/pr-preview-deploy.yml ]; then
  sed -n '1,40p' .github/workflows/pr-preview-deploy.yml | cat -n
else
  echo "missing .github/workflows/pr-preview-deploy.yml"
fi

echo
echo "Action download step:"
sed -n '20,36p' .github/workflows/pr-preview-deploy.yml | cat -n 2>/dev/null

echo
echo "Search github-token inputs in download-artifact usages:"
rg -n "download-artifact@v|github-token|run-id" .github/workflows || true

Repository: migtools/mta-documentation

Length of output: 2805


Add actions: read permission for cross-run artifact download.

actions/download-artifact@v4 uses the provided github-token to fetch artifacts from another run via run-id. Since this workflow declares an explicit permission block without actions: read, the deploy job cannot authenticate that artifact request and the preview deployment fails.

🔧 Proposed fix
 permissions:
   contents: write
   pull-requests: write
+  actions: read

Applies to lines: 10-12 and 27-33.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
permissions:
contents: write
pull-requests: write
permissions:
contents: write
pull-requests: write
actions: read
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/pr-preview-deploy.yml around lines 10 - 12, Update the
workflow’s top-level permissions block to include actions: read alongside
contents and pull-requests, so the artifact download step using
actions/download-artifact@v4 and a cross-run run-id can authenticate
successfully.

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