Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/PI-601] workspace destruction #399

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/on_pr_close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "On PR Close"

permissions:
id-token: write
contents: read
actions: write

env:
TF_CLI_ARGS: -no-color
CI_ROLE_NAME: ${{ secrets.CI_ROLE_NAME }}
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}

on:
pull_request:
types: [closed]

jobs:
parse-secrets:
runs-on: [self-hosted, ci]
steps:
- id: parse-secrets
run: |
echo "::add-mask::${{ secrets.CI_ROLE_NAME }}"

build-base:
runs-on: [self-hosted, ci]
needs: [parse-secrets]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }}
- uses: ./.github/actions/make/
with:
command: build
save-to-cache: "true"
restore-from-cache: "false"

destroy-pr-workspaces:
runs-on: [self-hosted, ci]
needs: [parse-secrets, build-base]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }}
fetch-depth: 0
- name: Remove PR workspaces
uses: ./.github/actions/make/
with:
command: destroy--redundant-workspaces BRANCH_NAME=origin/${{ env.BRANCH_NAME }} DESTROY_ALL_COMMITS_ON_BRANCH=true KILL_ALL=true TF_CLI_ARGS=${{ env.TF_CLI_ARGS }}
requires-aws: true
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ function _destroy_redundant_workspaces() {
workspaces=$(aws s3 ls "$bucket" --no-paginate | awk '{print $NF}' | sed 's:/$::')

# get JIRA ID from branch name
ENVIRONMENT="dev"
if [[ $BRANCH_NAME =~ feature\/(PI-[0-9]+)[-_] ]]; then
workspace_id="${BASH_REMATCH[1]}"
ENVIRONMENT="ref"
elif [[ $BRANCH_NAME == *release/* ]]; then
workspace_id="${BRANCH_NAME##*release/}"
ENVIRONMENT="dev"
fi
echo "The workspace ID is: $workspace_id"
echo "Destroying workspaces in: $ENVIRONMENT"
Expand Down
Loading