From 41c363f0588246c609740ce8d3c6b3774c84429d Mon Sep 17 00:00:00 2001 From: Craig O'Donnell Date: Tue, 28 Nov 2023 10:18:01 -0500 Subject: [PATCH 1/2] fix e2e-infra-cleanup workflow --- .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 a788e3157d..955b98f881 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 2a99593730..4b10215d7b 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@v3 @@ -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 }}"}' From 2bc27c9a9fe3a3b866e2f6e586db98de29c19f49 Mon Sep 17 00:00:00 2001 From: Craig O'Donnell Date: Tue, 28 Nov 2023 10:23:12 -0500 Subject: [PATCH 2/2] fix action lint --- .github/workflows/regression.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/regression.yaml b/.github/workflows/regression.yaml index 4b10215d7b..450a18e43e 100644 --- a/.github/workflows/regression.yaml +++ b/.github/workflows/regression.yaml @@ -68,7 +68,7 @@ jobs: id: workspace run: | CURRENT_TIMESTAMP=$(date +%s) - echo "name=${{ env.WORKSPACE_PREFIX }}-${CURRENT_TIMESTAMP}" >> $GITHUB_OUTPUT + echo "name=${{ env.WORKSPACE_PREFIX }}-${CURRENT_TIMESTAMP}" >> "$GITHUB_OUTPUT" jumpbox: needs: get-workspace-name