Skip to content

Commit

Permalink
fix e2e-infra-cleanup workflow (#4177)
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig O'Donnell authored Nov 28, 2023
1 parent dbc8a38 commit 2ff5f2d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/e2e-infra-cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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-<id/sha>-<timestamp>
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"
Expand Down
27 changes: 23 additions & 4 deletions .github/workflows/regression.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -263,13 +280,15 @@ 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
with:
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 }}"}'

0 comments on commit 2ff5f2d

Please sign in to comment.