name: 'Upload Coverage'
description: 'Uploads code coverage reports to codecov with separate flags for separate packages'
inputs:
  codecov_token:
    description: 'Codecov token.'
    required: true
runs:
  using: 'composite'
  steps:
    - name: Upload Guide Coverage
      if: ${{ hashFiles('apps/guide/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./apps/guide/coverage/cobertura-coverage.xml
        disable_search: true
        flags: guide
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Website Coverage
      if: ${{ hashFiles('apps/website/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./apps/website/coverage/cobertura-coverage.xml
        disable_search: true
        flags: website
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Brokers Coverage
      if: ${{ hashFiles('packages/brokers/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/brokers/coverage/cobertura-coverage.xml
        disable_search: true
        flags: brokers
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Builders Coverage
      if: ${{ hashFiles('packages/builders/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/builders/coverage/cobertura-coverage.xml
        disable_search: true
        flags: builders
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Collection Coverage
      if: ${{ hashFiles('packages/collection/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/collection/coverage/cobertura-coverage.xml
        disable_search: true
        flags: collection
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Discord.js Coverage
      if: ${{ hashFiles('packages/discord.js/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/discord.js/coverage/cobertura-coverage.xml
        disable_search: true
        flags: discord.js
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Formatters Coverage
      if: ${{ hashFiles('packages/formatters/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/formatters/coverage/cobertura-coverage.xml
        disable_search: true
        flags: formatters
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Next Coverage
      if: ${{ hashFiles('packages/next/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/next/coverage/cobertura-coverage.xml
        disable_search: true
        flags: next
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Proxy Coverage
      if: ${{ hashFiles('packages/proxy/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/proxy/coverage/cobertura-coverage.xml
        disable_search: true
        flags: proxy
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Rest Coverage
      if: ${{ hashFiles('packages/rest/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/rest/coverage/cobertura-coverage.xml
        disable_search: true
        flags: rest
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Voice Coverage
      if: ${{ hashFiles('packages/voice/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/voice/coverage/cobertura-coverage.xml
        disable_search: true
        flags: voice
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload WS Coverage
      if: ${{ hashFiles('packages/ws/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/ws/coverage/cobertura-coverage.xml
        disable_search: true
        flags: ws
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Util Coverage
      if: ${{ hashFiles('packages/util/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/util/coverage/cobertura-coverage.xml
        disable_search: true
        flags: util
        token: ${{ inputs.CODECOV_TOKEN }}

    - name: Upload Utilities Coverage
      if: ${{ hashFiles('packages/actions/coverage/cobertura-coverage.xml') != '' || hashFiles('packages/scripts/coverage/cobertura-coverage.xml') != '' }}
      uses: codecov/codecov-action@v4
      with:
        files: ./packages/actions/coverage/cobertura-coverage.xml, ./packages/scripts/coverage/cobertura-coverage.xml
        disable_search: true
        flags: utilities
        token: ${{ inputs.CODECOV_TOKEN }}
