Skip to content

ci: delete GitHub environment upon PR preview cleanup#28

Merged
MrOrz merged 2 commits into
masterfrom
fix-preview-environment-deletion-392506522579631310
May 3, 2026
Merged

ci: delete GitHub environment upon PR preview cleanup#28
MrOrz merged 2 commits into
masterfrom
fix-preview-environment-deletion-392506522579631310

Conversation

@MrOrz
Copy link
Copy Markdown
Member

@MrOrz MrOrz commented Apr 24, 2026

Currently, the .github/workflows/preview-cleanup.yml workflow sets the GitHub deployment to 'inactive' when a PR is closed. This causes preview environments (e.g., pr-123) to accumulate indefinitely in the repository's environments settings page.

This updates the GitHub Action script to explicitly delete the environment using github.rest.repos.deleteAnEnvironment. Deleting the environment automatically cleans up the repository settings. The try...catch block was removed so that any errors directly fail the action step, as requested.


PR created automatically by Jules for task 392506522579631310 started by @MrOrz

Currently, the `preview-cleanup.yml` workflow sets the GitHub deployment to 'inactive' when a PR is closed. This causes preview environments (e.g., `pr-123`) to accumulate indefinitely in the repository's environments settings page.

This commit updates the GitHub Action script to explicitly delete the environment using `github.rest.repos.deleteAnEnvironment`. Deleting the environment automatically handles the deployment statuses associated with it. The `try...catch` block was removed so that any errors directly fail the action step, per requirements.

Co-authored-by: MrOrz <108608+MrOrz@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Copy Markdown

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Hi @MrOrz, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@github-actions
Copy link
Copy Markdown
Contributor

🤖 I'm sorry @MrOrz, but I was unable to process your request. Please see the logs for more details.

Currently, the `preview-cleanup.yml` workflow sets the GitHub deployment to 'inactive' when a PR is closed. This causes preview environments (e.g., `pr-123`) to accumulate indefinitely in the repository's environments settings page.

This commit updates the GitHub Action script to explicitly delete the environment using `github.rest.repos.deleteAnEnvironment`. Deleting the environment automatically handles the deployment statuses associated with it. The `try...catch` block was removed so that any errors directly fail the action step, per requirements.

Co-authored-by: MrOrz <108608+MrOrz@users.noreply.github.com>
@MrOrz
Copy link
Copy Markdown
Member Author

MrOrz commented May 3, 2026

@claude review

@claude
Copy link
Copy Markdown

claude Bot commented May 3, 2026

Claude finished @MrOrz's task in 1m 46s —— View job


PR Review

Tasks

  • Read repository guidelines (CLAUDE.md)
  • Examine the workflow file changes
  • Analyze the changes for correctness and best practices
  • Provide comprehensive review feedback

Review Summary

This PR successfully simplifies the cleanup workflow and addresses the stated goal of preventing environment accumulation. The changes are sound overall, with one consideration for error handling.

What Changed

Before: The workflow iterated through all deployments in the environment and marked each as 'inactive', wrapped in a try-catch that silently logged errors.

After: The workflow directly deletes the GitHub environment using github.rest.repos.deleteAnEnvironment(), which automatically cleans up all associated deployments.

Code reduction: ~18 lines → ~7 lines (much cleaner!)

Analysis

Strengths

  1. Correct API usage: The deleteAnEnvironment call is properly structured with the required parameters (owner, repo, environment_name)

  2. Achieves the goal: Deleting the environment will prevent accumulation in repository settings, as stated in the PR description

  3. Simplified logic: Removing the deployment iteration loop makes the code more maintainable

  4. Proper permissions: The workflow has deployments: write permission which is sufficient for deleting environments

⚠️ Consideration

Error handling for missing environments:

The PR description mentions that the try-catch was removed "so that any errors directly fail the action step, as requested." However, this means if the environment doesn't exist (perhaps it was manually deleted, or never created), the entire workflow will fail with an error.

File: .github/workflows/preview-cleanup.yml:40-44

await github.rest.repos.deleteAnEnvironment({
  owner,
  repo,
  environment_name,
});

Consideration: If you want to avoid noise from environments that don't exist, you could add specific error handling for 404 responses:

try {
  await github.rest.repos.deleteAnEnvironment({
    owner,
    repo,
    environment_name,
  });
} catch (error) {
  if (error.status === 404) {
    console.log(`Environment ${environment_name} not found, skipping deletion.`);
  } else {
    throw error; // Re-throw other errors to fail the action
  }
}

However, if you prefer strict failure for any error (including missing environments) to surface potential issues, the current approach is fine.

Recommendation

If the current "fail on any error" behavior is intentional, this PR is ready to merge as-is.

If you'd prefer to handle missing environments gracefully, consider the error handling suggestion above.

Either approach is valid depending on your operational preferences!

--- | Branch: fix-preview-environment-deletion-392506522579631310

@MrOrz MrOrz marked this pull request as ready for review May 3, 2026 11:44
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@MrOrz MrOrz merged commit 8b36593 into master May 3, 2026
1 check passed
@MrOrz MrOrz deleted the fix-preview-environment-deletion-392506522579631310 branch May 3, 2026 11:44
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.

1 participant