name: RemoveCustomDeployment
on:
  workflow_dispatch:
  pull_request:
    types: ['unlabeled', 'closed']
jobs:
  remove:
    runs-on: ubuntu-latest
    if: ${{ (github.event.label.name == 'status/feature_testing' || github.event.label.name == 'status/feature_testing_public') || (github.event.action == 'closed' && (contains(github.event.pull_request.labels.*.name, 'status/feature_testing') || contains(github.event.pull_request.labels.*.name, 'status/feature_testing_public'))) }}
    steps:
      - uses: actions/checkout@v3
      - name: clone
        run: |
          git clone https://kafka-ui-infra:${{ secrets.KAFKA_UI_INFRA_TOKEN }}@gitlab.provectus.com/provectus-internals/kafka-ui-infra.git
      - name: remove env
        run: |
          cd kafka-ui-infra/aws-infrastructure4eks/argocd/scripts
          ./delete-env.sh pr${{ github.event.pull_request.number }} || true
          git config --global user.email "kafka-ui-infra@provectus.com"
          git config --global user.name "kafka-ui-infra"
          git add ../kafka-ui-from-branch/
          git commit -m "removed env:${{ needs.build.outputs.deploy }}" && git push || true
      - name: make comment with deployment link
        uses: peter-evans/create-or-update-comment@v2
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body: |
            Custom deployment removed
