generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make delete-env work as documented (#101)
I realized after looking at the code that delete-env was deleting an environment, which isn't really related to deployments like the rest of this action (at least not in a way that mirrors deactivate-env like the README says). I've added code here to do the delete in the way I expected it to work--deactivate all deployments for the given environment, then delete them.
- Loading branch information
1 parent
b0db961
commit a9488c4
Showing
5 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { GitHub } from "@actions/github/lib/utils"; | ||
|
||
import { DeploymentContext } from "./context"; | ||
import deactivateEnvironment from "./deactivate"; | ||
|
||
/** | ||
* Delete all deployments within this environment. | ||
*/ | ||
async function deleteEnvironment( | ||
github: InstanceType<typeof GitHub>, | ||
context: DeploymentContext | ||
) { | ||
const { | ||
log, | ||
owner, | ||
repo, | ||
coreArgs: { environment }, | ||
} = context; | ||
const deployments = await deactivateEnvironment(github, context); | ||
if (!deployments) { | ||
return; | ||
} | ||
const existing = deployments.data.length; | ||
for (let i = 0; i < existing; i++) { | ||
const deployment = deployments.data[i]; | ||
log.info( | ||
`${environment}.${deployment.id}: deleting deployment (${deployment.sha})"` | ||
); | ||
await github.rest.repos.deleteDeployment({ | ||
owner, | ||
repo, | ||
deployment_id: deployment.id, | ||
}); | ||
log.debug(`${environment}.${deployment.id} deleted`); | ||
} | ||
|
||
log.info(`${environment}: ${existing} deployments deleted`); | ||
} | ||
|
||
export default deleteEnvironment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters