Skip to content

[CI]: Restructure and Standardize the preview-deploy workflow across repos subscribed to the meshery-academy topic. - #101

Closed
MrDadhich456 wants to merge 1 commit into
meshery-extensions:masterfrom
MrDadhich456:feature/update-preview-workflow
Closed

[CI]: Restructure and Standardize the preview-deploy workflow across repos subscribed to the meshery-academy topic.#101
MrDadhich456 wants to merge 1 commit into
meshery-extensions:masterfrom
MrDadhich456:feature/update-preview-workflow

Conversation

@MrDadhich456

@MrDadhich456 MrDadhich456 commented Jul 24, 2026

Copy link
Copy Markdown

Notes for Reviewers

This PR fixes #86

Standardizes the PR preview-deploy workflow on digitalocean-academy following the reference implementation established in meshery-extensions/tcslabs-academy#36 across repositories subscribed to the meshery-academy topic.

Summary

Replaces the legacy single deploy-preview.yml workflow with three decoupled workflows that implement GitHub's recommended 2-stage trust separation pattern for pull request previews: an unprivileged build stage, a privileged deploy stage communicating via build artifacts, and a cleanup stage on PR closure.


Architecture & Workflows Added

  1. preview-build-pr.yml & preview-build.yml (Build Stage)

    • Trigger: pull_request (opened, synchronize, reopened) against master.
    • Permissions: Unprivileged contents: read (safe for external fork contributions).
    • Action: Sets up Go, Node 20, and Hugo 0.158.0 extended, builds the site via hugo --environment dev, and uploads the public/ directory as a 1-day artifact (preview-site).
  2. preview-deploy-pr.yml & preview-deploy.yml (Deploy Stage)

    • Trigger: workflow_run when Preview Build completes with conclusion == 'success'.
    • Permissions: Privileged contents: write, pull-requests: write, actions: read.
    • Action: Downloads artifact by run-id, performs artifact sanity checks (index.html presence, removing smuggled symlinks, <200MB size limit), matches HEAD_SHA to open PRs via GitHub API, publishes to gh-pages under pr-preview/pr-<number>/, and posts/updates a sticky PR comment with the preview URL.
  3. preview-cleanup-pr.yml & preview-clean.yml (Cleanup Stage)

    • Trigger: pull_request_target: [closed] and workflow_dispatch.
    • Permissions: contents: write, pull-requests: write.
    • Action: Prunes preview directories from gh-pages for closed PRs or to maintain the retention limit (retention_limit: 6).

Key Fixes & Feedback Incorporated from PR #36

  • Reusable Workflow Context Fix (Katotodan Review): Avoided if: github.event_name == 'pull_request' inside the reusable workflow preview-build.yml (since github.event_name evaluates to 'workflow_call' when invoked via workflow_call).
  • Best-Effort PR Notification (Ian / Salmaan Review): Added continue-on-error: true to the notification step in preview-clean.yml so transient GitHub API glitches don't cause an otherwise successful gh-pages cleanup to fail.
  • Concurrency Serialization: Configured per-repo deploy concurrency to serialize pushes and avoid race conditions on gh-pages.
  • Retry Backoff Loops: Implemented a 5-attempt retry loop with exponential backoff on git push operations for both deploy and clean steps.

Verification Plan

Automated Verification

  • Workflows pass GitHub Actions YAML syntax and schema validation.

Manual Verification Steps (Upon Merging / PR Push)

  1. Build Test: Pushing a commit to a PR branch triggers Preview Build under pull_request with contents: read permissions.
  2. Deploy Test: When Preview Build succeeds, Preview Deploy triggers via workflow_run, downloads the artifact, updates gh-pages/pr-preview/pr-<number>/, and posts the preview URL comment.
  3. Cleanup Test: Closing a PR triggers Preview Cleanup, removing pr-preview/pr-<number>/ from gh-pages and leaving a cleanup notice.

Signed-off-by

  • Yes, I signed my commits: MrDadhich456 <aaryandadhich2006@gmail.com>

Summary by CodeRabbit

  • New Features
    • Added automated pull request preview builds and deployments.
    • Preview sites are published with pull-request-specific URLs and linked in pull request comments.
    • Added automatic cleanup of previews when pull requests close, including retention-based pruning.
    • Added artifact validation and deployment safeguards for preview content.

This PR fixes meshery-extensions#86

Refactors the single preview-deploy workflow into three decoupled workflows following GitHub's recommended trust-separation pattern for pull request previews:
1. preview-build-pr.yml & preview-build.yml: Unprivileged build stage running under pull_request with read-only permissions.
2. preview-deploy-pr.yml & preview-deploy.yml: Privileged deployment stage running under workflow_run (when build succeeds) with contents: write permissions, publishing to gh-pages with artifact sanity checks and retry loops.
3. preview-cleanup-pr.yml & preview-clean.yml: Cleanup stage running on pull_request_target (closed) to prune preview directories and notify PR authors.

Standardizes preview deployment architecture aligned with tcslabs-academy meshery-extensions#36.

Signed-off-by: MrDadhich456 <aaryandadhich2006@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR preview deployment is replaced with separate build, artifact-based deployment, and cleanup workflows. Builds run on pull requests, deployments publish validated artifacts to gh-pages, and cleanup removes closed or stale previews while updating pull request comments.

Changes

PR preview pipeline

Layer / File(s) Summary
Build and package preview artifacts
.github/workflows/preview-build-pr.yml, .github/workflows/preview-build.yml
Pull request events invoke a reusable Hugo build workflow that installs tooling, builds with a PR-specific base URL, and uploads preview-site.
Resolve and publish completed previews
.github/workflows/preview-deploy-pr.yml, .github/workflows/preview-deploy.yml
Successful build completions resolve the open PR, validate the artifact, publish it under pr-preview/pr-<PR_NUMBER>/ on gh-pages, and create or update the preview comment.
Reconcile and notify preview removals
.github/workflows/preview-cleanup-pr.yml, .github/workflows/preview-clean.yml
Closed or manually triggered cleanup removes previews for closed PRs and enforces a retention limit, then updates affected PR comments.
Remove the previous deployment workflow
.github/workflows/deploy-preview.yml
The former combined preview build, deployment, pruning, commenting, and close cleanup workflow is removed.

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

Possibly related issues

  • meshery-extensions/meshery-academy Issue 148 — Covers the same split between unprivileged PR builds and privileged artifact-based deployment.
  • meshery-extensions/tcslabs-academy Issue 35 — Describes the same separate build, artifact, and deployment workflow pattern.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning [#86] The split build/deploy/cleanup workflows and artifact flow match the issue, but the build still runs Hugo directly instead of the required make targets. Change the build job to use the repo's standard make targets, then confirm the artifact still passes to deployment and PR-ref checkouts remain removed.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main change: restructuring the preview-deploy workflow.
Out of Scope Changes check ✅ Passed All changes stay within the requested preview build, deploy, and cleanup workflow restructuring.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
.github/workflows/preview-build.yml (1)

34-61: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Delegate the preview build to the repo target

The workflow already defines build-preview for the npm-managed Hugo preview build. Drop the separate peaceiris/actions-hugo step and run make build-preview after the existing npm ci, exporting the preview URL as DEPLOY_PRIME_URL so the build logic stays in one place.

🤖 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/preview-build.yml around lines 34 - 61, The preview
workflow should use the repository’s existing build target instead of invoking
Hugo directly. Remove the “Setup Hugo” step, keep “Install dependencies” with
npm ci, and update “Build preview” to export the existing BASE_URL value as
DEPLOY_PRIME_URL before running make build-preview.
🤖 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/preview-build-pr.yml:
- Around line 3-6: The pull request trigger in the workflow hardcodes the base
branch as master, preventing reuse by repositories with different default
branches. Add a workflow_call base-branch input and use it to parameterize the
pull_request branches filter, following the existing deployment-url input
pattern; apply the same change to preview-deploy.yml and preview-cleanup-pr.yml.

---

Nitpick comments:
In @.github/workflows/preview-build.yml:
- Around line 34-61: The preview workflow should use the repository’s existing
build target instead of invoking Hugo directly. Remove the “Setup Hugo” step,
keep “Install dependencies” with npm ci, and update “Build preview” to export
the existing BASE_URL value as DEPLOY_PRIME_URL before running make
build-preview.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 80278187-94b9-465a-8121-28e7270bac38

📥 Commits

Reviewing files that changed from the base of the PR and between 1b4b560 and d34cf8b.

📒 Files selected for processing (7)
  • .github/workflows/deploy-preview.yml
  • .github/workflows/preview-build-pr.yml
  • .github/workflows/preview-build.yml
  • .github/workflows/preview-clean.yml
  • .github/workflows/preview-cleanup-pr.yml
  • .github/workflows/preview-deploy-pr.yml
  • .github/workflows/preview-deploy.yml
💤 Files with no reviewable changes (1)
  • .github/workflows/deploy-preview.yml

Comment on lines +3 to +6
on:
pull_request:
branches: [master]
types: [opened, synchronize, reopened]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Hardcoded master branch limits cross-repo reuse.

This workflow is intended to be applied consistently across repos subscribed to the meshery-academy topic, but the base branch is hardcoded here (and mirrored in preview-deploy.yml and preview-cleanup-pr.yml). Any repo using main (or another default branch name) would silently never trigger this pipeline. Consider making the base branch a workflow_call input, consistent with how deployment-url is already parameterized.

🤖 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/preview-build-pr.yml around lines 3 - 6, The pull request
trigger in the workflow hardcodes the base branch as master, preventing reuse by
repositories with different default branches. Add a workflow_call base-branch
input and use it to parameterize the pull_request branches filter, following the
existing deployment-url input pattern; apply the same change to
preview-deploy.yml and preview-cleanup-pr.yml.

@MrDadhich456

Copy link
Copy Markdown
Author

Note regarding the failing build-and-deploy check:
The failing check is from the legacy .github/workflows/deploy-preview.yml defined on master, which triggers under pull_request_target and is now blocked by actions/checkout for fork PRs.

This PR deletes deploy-preview.yml and replaces it with the standardized preview-build-pr.yml (pull_request) and preview-deploy-pr.yml (workflow_run) architecture (from tcslabs-academy#36), which resolves this checkout failure.

@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.6.3
Preview removed because the pull request was closed.
2026-07-24 15:25 UTC

@coderabbitai coderabbitai Bot mentioned this pull request Aug 4, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI]: Standardize the PR preview-deploy workflow across meshery-academy repos

1 participant