---
name: Check for new usages of deprecated functionality

permissions:
  contents: read
  pull-requests: write

on:
  pull_request_target:
    types: ['opened', 'synchronize']
    paths:
      - '.github/workflows/gradually-deprecated.yaml'
      - '**.go'

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/setup-go@v3
        with:
          go-version-file: ./.go-version
      - run: ./scripts/run-gradually-deprecated.sh
      - name: Add waiting-response on fail
        if: failure()
        uses: actions-ecosystem/action-add-labels@v1
        with:
          labels: waiting-response
          github_token: ${{ secrets.GITHUB_TOKEN }}
          number: ${{ github.event.number }}
          repo: ${{ github.event.repository.full_name }}
      - name: Get run url
        if: failure()
        run: |
          echo "gha_url=https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" >> $GITHUB_ENV
      - name: Send build failure comment
        if: failure()
        uses: actions/github-script@v6
        with:
          result-encoding: string
          script: |
            github.rest.issues.createComment({
             issue_number: ${{ github.event.number }},
             owner: context.repo.owner,
             repo: context.repo.repo,
             body: '<b>Build failure</b> \n\n Found new usages of deprecated functionality: \n\n ${{ env.gha_url}}'
             })