Skip to content

Conversation

@stevencl840
Copy link
Contributor

@stevencl840 stevencl840 commented Nov 11, 2025

Context 🌆

Ephemeral environments are temporary environments that developers can use to test changes. They are expected to come and go with the same cadence as a PR, created when the PR is opened and torn down when it is merged.

Users need to be able to deprovision a specific project in an ephemeral environment

Details 🔍

I have added a command that allows users to deprovision a specific project in an ephemeral environment. The user must provide both a project and an ephemeral environment.
WindowsTerminal_cuVEInNgXa

WindowsTerminal_e2EvSWz8ne

With no deprovisioning runbook

image

Tasting 🧪

I have added automated tests to provide the behaviour of this new command.

[sc-124014]

@stevencl840 stevencl840 changed the title Deprovision an Ephemeral Environment Deprovision a proejct for an ephemeral environment Nov 11, 2025
Base automatically changed from lourens/deprovision-ee-for-project to main November 11, 2025 19:56
@stevencl840 stevencl840 changed the title Deprovision a proejct for an ephemeral environment Deprovision a project for an ephemeral environment Nov 11, 2025
@stevencl840 stevencl840 requested a review from Copilot November 11, 2025 20:47
@stevencl840 stevencl840 force-pushed the sjc/add-deprovision-project branch from 416abac to 97712fa Compare November 11, 2025 20:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to deprovision projects in ephemeral environments, allowing users to tear down specific project deployments when PRs are closed.

Key changes include:

  • Added a shared utility function GetByName for finding ephemeral environments by name with case-insensitive exact matching
  • Implemented deprovision-project command to deprovision a specific project in an ephemeral environment
  • Implemented deprovision-environment command to deprovision an entire ephemeral environment
  • Updated dependency to go-octopusdeploy/v2 v2.88.0 to support new deprovisioning APIs

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/cmd/ephemeralenvironment/util/util.go New utility function for finding ephemeral environments by name with case-insensitive matching
pkg/cmd/ephemeralenvironment/util/util_test.go Comprehensive tests for the GetByName utility function
pkg/cmd/ephemeralenvironment/deprovision-project/deprovision_project.go Command implementation for deprovisioning a project in an ephemeral environment
pkg/cmd/ephemeralenvironment/deprovision-project/deprovision_project_test.go Test coverage for the deprovision-project command
pkg/cmd/ephemeralenvironment/deprovision-environment/deprovision_environment.go Command implementation for deprovisioning an entire ephemeral environment
pkg/cmd/ephemeralenvironment/deprovision-environment/deprovision_environment_test.go Test coverage for the deprovision-environment command
pkg/cmd/ephemeralenvironment/ephemeralenvironment.go Registration of new deprovision commands
go.mod Updated go-octopusdeploy/v2 dependency to v2.88.0
go.sum Updated checksums for new dependency version

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@stevencl840 stevencl840 force-pushed the sjc/add-deprovision-project branch from c337352 to 112f88f Compare November 11, 2025 22:24
@stevencl840 stevencl840 requested a review from a team November 11, 2025 22:56
}

if slices.ContainsFunc(projectChannels, func(channel *channels.Channel) bool {
return channel.Type == "EphemeralEnvironment"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: The go library defines a constant we can use channels.ChannelTypeEphemeral


environmentId := environmentResource.ID

cmd.Printf("Deprovisioning ephemeral environment '%s' with id '%s' for project '%s'...\n", opts.Name.Value, environmentId, opts.Project.Value)
Copy link
Contributor

Choose a reason for hiding this comment

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

The output function displays a message about deprovisioning. Can either remove this one, or the one in the function. Yours is more specific to the project as well, if it is removed in the function just remember to add one to the deprovision environment command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the one from the util function and added a message to the command


cmd.Printf("\nSuccessfully deprovisioned ephemeral environment for project '%s' with id '%s'.\n", opts.Project.Value, environmentId)

util.OutPutDeprovisionResult(opts.Name.Value, cmd, []ephemeralenvironments.DeprovisioningRunbookRun{deprovisionedEnv.DeprovisioningRun})
Copy link
Contributor

@lourens-octopus lourens-octopus Nov 12, 2025

Choose a reason for hiding this comment

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

If deprovisionedEnv.DeprovisioningRun can be nil, this will make a slice containing nil [nil] which will have a count of 1, and the Output function will error because it checks for nil, or length of 0.

As an aside I've also just noticed OutPutDeprovisionResult should probably be OutputDeprovisionResult. Sorry that's my bad 🤦

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When it receives a null runbookrun it creates one with empty strings rather than having a null. So I just check that

@lourens-octopus
Copy link
Contributor

LGTM

@stevencl840 stevencl840 merged commit 5d0e58b into main Nov 12, 2025
4 checks passed
@stevencl840 stevencl840 deleted the sjc/add-deprovision-project branch November 12, 2025 20:56
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