diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 75d189f..a5dfb59 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -37,12 +37,14 @@ env: userName: ${{ secrets.USER_NAME }} pullSecretEncoded: ${{ secrets.PULL_SECRET_ENCODED }} msTeamsWebhook: ${{ secrets.MSTEAMS_WEBHOOK }} - testResourceGroup: libertyAroTestRG${{ github.run_id }}${{ github.run_number }} - testDeploymentName: libertyAroTestDeployment${{ github.run_id }}${{ github.run_number }} + testResourceGroup: libertyAroTestRG-${{ github.repository_owner }}-${{ github.run_id }}-${{ github.run_number }} + testDeploymentName: libertyAroTestDeployment-${{ github.run_id }}-${{ github.run_number }} location: eastus jobs: integration-test: runs-on: ubuntu-latest + outputs: + clientId: ${{ steps.deploy.outputs.clientId }} steps: - name: Get versions of external dependencies run: | @@ -96,10 +98,12 @@ jobs: with: creds: ${{ env.azureCredentials }} - name: Start the deployment + id: deploy run: | servicePrincipal=$(az ad sp create-for-rbac --sdk-auth) clientId=$(echo $servicePrincipal | jq -r '.clientId') echo "clientId=${clientId}" >> $GITHUB_ENV + echo "clientId=${clientId}" >> "$GITHUB_OUTPUT" clientSecret=$(echo $servicePrincipal | jq -r '.clientSecret') aadObjectId=$(az ad sp show --id ${clientId} --query id -o tsv) rpObjectId=$(az ad sp list --display-name "Azure Red Hat OpenShift RP" --query [0].id -o tsv) @@ -127,15 +131,6 @@ jobs: echo "Invalid value of appEndpoint: ${appEndpoint}" exit 1 fi - - name: Delete all Azure resources - id: delete-resources-in-group - if: ${{ (github.event_name == 'workflow_dispatch' && inputs.deleteAzureResources) || (github.event_name == 'repository_dispatch' && github.event.client_payload.deleteAzureResources) }} - uses: azure/CLI@v1 - with: - azcliversion: ${{ env.azCliVersion }} - inlineScript: | - az group delete -n ${{ env.testResourceGroup }} --yes - az ad app delete --id ${clientId} - name: Generate artifact file name and path id: artifact_file run: | @@ -181,3 +176,26 @@ jobs: else echo "Job integration-test succeeded." fi + + delete-resources: + needs: [integration-test, notification] + runs-on: ubuntu-latest + if: always() + steps: + - uses: azure/login@v1 + id: azure-login + with: + creds: ${{ env.azureCredentials }} + - name: Checkout ${{ env.repoName }} + uses: actions/checkout@v2 + with: + path: ${{ env.repoName }} + ref: ${{ github.event.inputs.ref }} + - name: Delete all Azure resources + id: delete-resources + if: ${{ (github.event_name == 'workflow_dispatch' && inputs.deleteAzureResources) || (github.event_name == 'repository_dispatch' && github.event.client_payload.deleteAzureResources) }} + run: | + echo "delete resource group: " ${{ env.testResourceGroup }} + az group delete -n ${{ env.testResourceGroup }} --yes + echo "delete app with clientId: " ${clientId} + az ad app delete --id ${needs.integration-test.outputs.clientId}