name: Checks after any release is published
on:
  release:
    types: ['published']

jobs:
  validate-github-action:
    runs-on: ubuntu-latest
    steps:
      - uses: carvel-dev/setup-action@v1
        with:
          only: ytt
          ytt: ${{ github.event.release.tag_name }}
      - run: |
          ytt version
          version=`ytt version`
          tag="${{ github.event.release.tag_name }}"
          tool_version="$(echo $version | sed 's/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/')"
          if [[ "v${tool_version}" == "${tag}" ]];
          then
            echo "Version match with $tag"
            exit 0
          else
            echo "Versions do not match v$tool_version != $tag"
            exit 1
          fi
      - run: |
          curl -X POST https://api.github.com/repos/carvel-dev/release-scripts/dispatches \
          -H 'Accept: application/vnd.github.everest-preview+json' \
          -u ${{ secrets.carvel_bot_access_token }} \
          --data '{"event_type": "ytt_released", "client_payload": { "tagName": "${{ github.event.release.tag_name }}", "repo": "${{ github.repository }}", "toolName": "ytt" }}'
