From 067f74115c455cc84cbbf36e0026e64fb2822750 Mon Sep 17 00:00:00 2001 From: Sally Young Date: Wed, 30 Mar 2022 21:26:08 +0100 Subject: [PATCH] Mark GitHub Deployments as inactive and delete associated environments once PRs have been closed (#92) --- scaffold/github/actions/pantheon/review/action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scaffold/github/actions/pantheon/review/action.yml b/scaffold/github/actions/pantheon/review/action.yml index 114505a01..b68ac9e3e 100644 --- a/scaffold/github/actions/pantheon/review/action.yml +++ b/scaffold/github/actions/pantheon/review/action.yml @@ -60,6 +60,12 @@ runs: # if $MULTIDEV starts with "pr-" elif [[ $MULTIDEV == pr-* ]]; then echo "No PR for $MULTIDEV, shutting down..." + DEPLOYMENTS=$(curl -s -f -H "Authorization: token ${{ inputs.github-token }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$GITHUB_REPOSITORY/deployments?environment=pantheon-$MULTIDEV | jq '.[] | .id') + for DEPLOYMENT_ID in $DEPLOYMENTS; do + echo "Marking GitHub Deployment $DEPLOYMENT_ID as inactive" + curl -f -H "Authorization: token ${{ inputs.github-token }}" -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$GITHUB_REPOSITORY/deployments/$DEPLOYMENT_ID/statuses -d "{\"state\":\"inactive\"}" + curl -H "Authorization: token ${{ inputs.github-token }}" -X DELETE -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$GITHUB_REPOSITORY/environments/pantheon-$MULTIDEV + done drainpipe_exec "terminus multidev:delete ${{ inputs.site-name }}.$MULTIDEV --delete-branch --yes" else "Dangling Multidev environment $MULTIDEV found, no action taken."