diff --git a/.github/actions/e2e_mini/action.yml b/.github/actions/e2e_mini/action.yml index 2efd3a9a4..49a550414 100644 --- a/.github/actions/e2e_mini/action.yml +++ b/.github/actions/e2e_mini/action.yml @@ -11,6 +11,9 @@ inputs: azureTenantID: description: "Azure tenant to use for login with OIDC" required: true + azureIAMCredentials: + description: "Azure IAM credentials used for cleaning up resources" + required: true registry: description: "Container registry to use" required: true @@ -38,9 +41,26 @@ runs: - name: MiniConstellation E2E shell: bash + id: e2e-test env: ARM_CLIENT_ID: ${{ inputs.azureClientID }} ARM_SUBSCRIPTION_ID: ${{ inputs.azureSubscriptionID }} ARM_TENANT_ID: ${{ inputs.azureTenantID }} run: | bazel run --test_timeout=14400 //e2e/miniconstellation:push_remote_test + + - name: Log in to azure + # only log in if e2e test failed or if the run was cancelled + if: (failure() && steps.e2e-test.conclusion == 'failure') || cancelled() + uses: ./.github/actions/login_azure + with: + azure_credentials: ${{ inputs.azureIAMCredentials }} + + - name: Clean up after failure + shell: bash + # clean up if e2e test failed or if the run was cancelled + if: (failure() && steps.e2e-test.conclusion == 'failure') || cancelled() + run: | + rg_name=${{ steps.e2e-test.outputs.rgname }} + echo "[*] Deleting resource group $rg_name" + az group delete -y --resource-group "$rg_name" diff --git a/.github/workflows/e2e-mini.yml b/.github/workflows/e2e-mini.yml index 06b824fbf..1d4805490 100644 --- a/.github/workflows/e2e-mini.yml +++ b/.github/workflows/e2e-mini.yml @@ -46,5 +46,6 @@ jobs: azureClientID: ${{ secrets.AZURE_E2E_MINI_CLIENT_ID }} azureSubscriptionID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} azureTenantID: ${{ secrets.AZURE_TENANT_ID }} + azureIAMCredentials: ${{ secrets.AZURE_E2E_IAM_CREDENTIALS }} registry: ghcr.io githubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/e2e-test-daily.yml b/.github/workflows/e2e-test-daily.yml index df0c8e1f5..8be319bec 100644 --- a/.github/workflows/e2e-test-daily.yml +++ b/.github/workflows/e2e-test-daily.yml @@ -181,6 +181,7 @@ jobs: azureClientID: ${{ secrets.AZURE_E2E_MINI_CLIENT_ID }} azureSubscriptionID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} azureTenantID: ${{ secrets.AZURE_TENANT_ID }} + azureIAMCredentials: ${{ secrets.AZURE_E2E_IAM_CREDENTIALS }} registry: ghcr.io githubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/e2e-test-weekly.yml b/.github/workflows/e2e-test-weekly.yml index 8757d60cf..0b46c6e0b 100644 --- a/.github/workflows/e2e-test-weekly.yml +++ b/.github/workflows/e2e-test-weekly.yml @@ -455,6 +455,7 @@ jobs: azureClientID: ${{ secrets.AZURE_E2E_MINI_CLIENT_ID }} azureSubscriptionID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} azureTenantID: ${{ secrets.AZURE_TENANT_ID }} + azureIAMCredentials: ${{ secrets.AZURE_E2E_IAM_CREDENTIALS }} registry: ghcr.io githubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/e2e/miniconstellation/main.sh.in b/e2e/miniconstellation/main.sh.in index 694f17bb3..19e1df279 100755 --- a/e2e/miniconstellation/main.sh.in +++ b/e2e/miniconstellation/main.sh.in @@ -28,6 +28,9 @@ terraform apply -auto-approve terraform output -raw ssh_private_key > id_rsa chmod 600 id_rsa +rg_name=$(terraform output -raw rg_name) +echo "rgname=$rg_name" >> "${GITHUB_OUTPUT:-/dev/null}" + azure_vm_ip=$(terraform output -raw public_ip) echo "::endgroup::" diff --git a/e2e/miniconstellation/output.tf b/e2e/miniconstellation/output.tf index 14f541264..c8f961a46 100644 --- a/e2e/miniconstellation/output.tf +++ b/e2e/miniconstellation/output.tf @@ -9,3 +9,9 @@ output "ssh_private_key" { sensitive = true depends_on = [tls_private_key.ssh_key] } + +output "rg_name" { + value = "e2e-mini-${random_string.suffix.result}" + sensitive = false + depends_on = [random_string.suffix] +}