name: E2E Test
permissions:
  contents: read
on:
  workflow_call:
    inputs:
      package:
        required: true
        type: string
      event_name:
        required: true
        type: string

jobs:
  e2e-test:
    name: E2E Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: 20
          cache: yarn
      - run: yarn install --immutable
      - name: Cache for Turbo
        uses: rharkor/caching-for-turbo@v2.3.11
        with:
          cache-prefix: turbo-cache-
      - name: E2E Test
        if: ${{ inputs.event_name != 'pull_request' }}
        run: yarn test:e2e --filter=./packages/${{ inputs.package }}
        env:
          DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
          E2E_TEST_GUILD_ID: ${{ secrets.UNIT_TEST_GUILD_ID }}
          PROXY_REST_SECRET: ${{ secrets.PROXY_REST_SECRET }}
          PROXY_REST_URL: ${{ secrets.PROXY_REST_URL }}
      - name: Collect and upload the coverage report
        uses: codecov/codecov-action@v6
        if: ${{ inputs.event_name != 'pull_request' }}
        with:
          files: ./packages/${{ inputs.package }}/coverage/lcov.info
          flags: ${{ inputs.package }}-e2e,${{ inputs.package }}
          token: ${{ secrets.CODECOV_TOKEN }}
