Skip to content

Commit

Permalink
Merge pull request WASdev#111 from azure-javaee/ensure_workflow_delet…
Browse files Browse the repository at this point in the history
…e_resources

Ensure workflow delete resources
  • Loading branch information
venunathb authored Mar 6, 2024
2 parents 69f359b + 7756ac4 commit 8cc38b7
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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}

0 comments on commit 8cc38b7

Please sign in to comment.