From 2ff5f2d446cc0fb32b512381bd3b4b3d28be5a08 Mon Sep 17 00:00:00 2001 From: Craig O'Donnell Date: Tue, 28 Nov 2023 12:47:56 -0500 Subject: [PATCH] fix e2e-infra-cleanup workflow (#4177) --- .github/workflows/e2e-infra-cleanup.yaml | 10 +++++++-- .github/workflows/regression.yaml | 27 ++++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-infra-cleanup.yaml b/.github/workflows/e2e-infra-cleanup.yaml index 11f8356a2e..d4851036ca 100644 --- a/.github/workflows/e2e-infra-cleanup.yaml +++ b/.github/workflows/e2e-infra-cleanup.yaml @@ -44,10 +44,16 @@ jobs: - name: Get automation workspaces id: get-workspaces run: | - mapfile -t WORKSPACES < <(terraform workspace list | grep -o 'automation-\w*') + # automation workspace name is in the format automation-- + mapfile -t WORKSPACES < <(terraform workspace list | grep -o 'automation-.*') declare -a EXPIRED_WORKSPACES for workspace in "${WORKSPACES[@]}"; do - COMPLETION=$(date -d "$(TF_WORKSPACE="${workspace}" terraform output -no-color -raw completion_timestamp)" +%s) || continue + COMPLETION=$(echo "$workspace" | grep -o '[^-]*$' | grep -o '[0-9]*$') + if [ -z "$COMPLETION" ]; then + echo "Failed to parse completion date from workspace $workspace, adding to list of expired workspaces" + EXPIRED_WORKSPACES+=("${workspace}") + continue + fi [ $(($(date +%s) - COMPLETION)) -gt $((60 * 60 * CLEANUP_INTERVAL_HOURS)) ] && EXPIRED_WORKSPACES+=("${workspace}") done echo "workspaces=$(printf '%s\n' "${EXPIRED_WORKSPACES[@]}" | head -c -1 | jq -R . | jq -sc .)" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/regression.yaml b/.github/workflows/regression.yaml index 0373bc1ccf..e7c1f5eec2 100644 --- a/.github/workflows/regression.yaml +++ b/.github/workflows/regression.yaml @@ -55,13 +55,28 @@ env: AWS_ACCESS_KEY_ID: ${{ secrets.E2E_TESTIM_AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.E2E_TESTIM_AWS_SECRET_ACCESS_KEY }} TF_VAR_testim_token: ${{ secrets.TESTIM_ACCESS_TOKEN }} - WORKSPACE: automation-${{ github.event.inputs.id || inputs.id }} jobs: + get-workspace-name: + runs-on: ubuntu-latest + outputs: + name: ${{ steps.workspace.outputs.name }} + env: + WORKSPACE_PREFIX: automation-${{ github.event.inputs.id || inputs.id }} + steps: + - name: Set the workspace name as output + id: workspace + run: | + CURRENT_TIMESTAMP=$(date +%s) + echo "name=${{ env.WORKSPACE_PREFIX }}-${CURRENT_TIMESTAMP}" >> "$GITHUB_OUTPUT" + jumpbox: + needs: get-workspace-name runs-on: ubuntu-20.04 container: image: hashicorp/terraform:1.0.11 + env: + WORKSPACE: ${{ needs.get-workspace-name.outputs.name }} steps: - name: Checkout uses: actions/checkout@v4 @@ -116,10 +131,12 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.KOTS_BUILD_STATUS_SLACK_WEBHOOK_URL }} tests: - needs: jumpbox + needs: [get-workspace-name, jumpbox] runs-on: ubuntu-20.04 container: image: hashicorp/terraform:1.0.11 + env: + WORKSPACE: ${{ needs.get-workspace-name.outputs.name }} strategy: fail-fast: false matrix: @@ -263,8 +280,10 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.KOTS_BUILD_STATUS_SLACK_WEBHOOK_URL }} MATRIX_CONTEXT: ${{ toJson(matrix) }} cleanup: - needs: tests + needs: [get-workspace-name, tests] runs-on: ubuntu-20.04 + env: + WORKSPACE: ${{ needs.get-workspace-name.outputs.name }} steps: - name: Trigger workspace cleanup uses: peter-evans/repository-dispatch@v2 @@ -272,4 +291,4 @@ jobs: token: ${{ secrets.E2E_GH_PAT }} repository: replicatedhq/kots event-type: e2e-workspace-cleanup - client-payload: '{"workspace": "automation-${{ github.event.inputs.id || inputs.id }}"}' + client-payload: '{"workspace": "${{ env.WORKSPACE }}"}'