#
# Copyright 2021 The Dapr Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This workflows is triggered manually and it deletes all images in the E2E image cache
#
# Required secrets:
# - AZURE_CREDENTIALS: JSON object containing the Azure service principal credentials. Docs: https://github.com/Azure/login#configure-a-service-principal-with-a-secret

name: dapr-test-cache-clean

on:
  # Manual trigger
  workflow_dispatch:

jobs:
  cleanup:
    runs-on: ubuntu-22.04
    steps:
      - name: Login to Azure
        uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
      - name: "Clean E2E image cache"
        run: |
          for repo in $(az acr repository list -n dapre2eacr -o tsv); do
            echo "Deleting: $repo"
            az acr repository delete --repository "$repo" -n dapre2eacr --yes
          done
        shell: bash