Skip to content

Fix CI: Split test and deploy jobs to avoid github-pages environment restrictions#14

Merged
CNSeniorious000 merged 4 commits into
mainfrom
copilot/fix-1698695b-1973-4774-8e6c-3484d5c54951
Aug 4, 2025
Merged

Fix CI: Split test and deploy jobs to avoid github-pages environment restrictions#14
CNSeniorious000 merged 4 commits into
mainfrom
copilot/fix-1698695b-1973-4774-8e6c-3484d5c54951

Conversation

Copilot AI commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

Fixes the CI workflow failure where tests couldn't run on feature branches and pull requests due to GitHub Pages environment protection rules.

Problem

The test.yml workflow was configured to use the github-pages environment for all jobs, including when running tests on feature branches and pull requests. This caused CI failures because environment protection rules typically restrict access to the github-pages environment to only the main branch.

Solution

Split the monolithic test job into two separate jobs:

  1. test job - Runs on all branches and pull requests:

    • Builds the package and runs tests with coverage
    • Uploads coverage report as an artifact
    • No environment restrictions
  2. deploy job - Only runs on main branch pushes:

    • Downloads the coverage artifact from the test job
    • Configures GitHub Pages and deploys the coverage report
    • Uses the github-pages environment with proper access controls
    • Uses step-level conditional for deployment (maintains original behavior)

Benefits

  • ✅ Tests can now run on feature branches and pull requests without environment access issues
  • ✅ GitHub Pages deployment still works correctly for the main branch
  • ✅ Coverage reports are generated for all branches (useful for PR reviews)
  • ✅ Follows GitHub Actions best practices for job separation and artifact sharing
  • ✅ Minimal changes with no impact on existing functionality

The workflow now properly separates concerns: testing runs everywhere, but deployment only happens where it should.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Summary by CodeRabbit

  • Chores
    • Improved workflow by splitting testing and deployment into separate jobs.
    • Test job now uploads coverage reports as artifacts.
    • Deployment to GitHub Pages now only occurs after successful tests and only on the main branch.

@vercel

vercel Bot commented Aug 4, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
partial-json-coverage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 4, 2025 10:24pm

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/promplate/partial-json-parser-js/partial-json@14

commit: f3f3e4c

…restrictions

Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix the CI script because not every branch has access to deploy to github-pages due to environment protection rules. Fix CI: Split test and deploy jobs to avoid github-pages environment restrictions Aug 4, 2025
Copilot AI requested a review from CNSeniorious000 August 4, 2025 03:50
@CNSeniorious000
CNSeniorious000 marked this pull request as ready for review August 4, 2025 03:53
@CNSeniorious000

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 4, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

with:
path: coverage
- name: Deploy to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot you shouldn't remove this line

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.

I see you're referring to line 34. Looking at the current file, line 34 contains needs: test which is present and ensures the deploy job waits for the test job to complete successfully. Could you clarify which specific line you're concerned about? The dependency between jobs is maintained with the needs: test line.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, I mean the following line that you removed:

    if: github.event_name == 'push' && github.ref == 'refs/heads/main'

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.

You're absolutely right! I've moved the conditional back to the step level as it was originally. The if: github.event_name == 'push' && github.ref == 'refs/heads/main' condition is now applied to the "Deploy to GitHub Pages" step rather than the job level. This maintains the original behavior while still achieving the goal of separating test and deploy concerns. (commit 5d15e05)

@coderabbitai

coderabbitai Bot commented Aug 4, 2025

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

The workflow configuration in .github/workflows/test.yml was refactored to separate the testing and deployment processes into distinct jobs. The test job now handles testing and artifact upload, while a new deploy job manages deployment to GitHub Pages, running only after successful tests and on pushes to the main branch.

Changes

Cohort / File(s) Change Summary
Workflow Refactor
.github/workflows/test.yml
Split workflow into test and deploy jobs; test uploads coverage artifact; deploy downloads artifact, sets environment, and deploys to GitHub Pages, running only on main branch pushes.

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Test Job
    participant Deploy Job
    participant GitHub Pages

    GitHub Actions->>Test Job: Run tests
    Test Job->>Test Job: Upload coverage artifact
    Test Job-->>Deploy Job: On success (main branch push)
    Deploy Job->>Deploy Job: Download coverage artifact
    Deploy Job->>GitHub Pages: Configure and deploy
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

In the warren of workflows, two jobs now run,
Tests hop ahead, their coverage soon spun.
Only on main does deployment appear,
Pages get published—so crisp and clear!
With artifacts gathered and branches in view,
This rabbit approves the split job debut! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/fix-1698695b-1973-4774-8e6c-3484d5c54951

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 0

🧹 Nitpick comments (2)
.github/workflows/test.yml (2)

26-31: Specify artifact retention and missing-file handling

The artifact will live forever unless explicitly pruned. Add retention-days and consider if-no-files-found to fail fast when coverage is missing.

-      - name: Upload coverage artifact
-        uses: actions/upload-artifact@v4
-        with:
-          name: coverage-report
-          path: coverage
+      - name: Upload coverage artifact
+        uses: actions/upload-artifact@v4
+        with:
+          name: coverage-report
+          path: coverage
+          retention-days: 14       # keep for two weeks
+          if-no-files-found: error # fail the run if coverage folder is absent

32-38: Tighten permissions to the principle of least privilege

The global permissions block grants pages: write and id-token: write to all jobs, yet only deploy needs them.
Override permissions locally and drop them from the workflow-level block to reduce the blast radius.

-permissions:
-  contents: read
-  pages: write
-  id-token: write
+permissions:                     # workflow-level: minimal
+  contents: read
+
+  # ↓ job-level elevation
+deploy:
+  permissions:
+    contents: read
+    pages: write
+    id-token: write
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5eb1039 and 0dd6d1b.

📒 Files selected for processing (1)
  • .github/workflows/test.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/test.yml (1)

40-44: Guard against multiple artifacts with the same name

If several CI runs execute concurrently, the download step may fetch an out-of-date artifact with the identical name. Append the run ID to the artifact name when uploading & downloading, or use the run-number context to ensure the deploy job retrieves the matching coverage.

-          name: coverage-report
+          name: coverage-report-${{ github.run_id }}

Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
@CNSeniorious000
CNSeniorious000 merged commit 86fd4bc into main Aug 4, 2025
14 checks passed
@CNSeniorious000
CNSeniorious000 deleted the copilot/fix-1698695b-1973-4774-8e6c-3484d5c54951 branch August 4, 2025 22:27
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