# Replays recorded bid requests against the bidder on every push and pull
# request, and fails when a response breaks the spec or the expected outcome.
name: Bidder fixtures
on: [push, pull_request]
permissions:
  contents: read
jobs:
  bidder-fixtures:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    env:
      RTBLINT_VERSION: v0.14.7
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 22
          cache: npm
      - name: Install bidder dependencies
        run: npm ci
      - name: Install the RTBlint CLI
        run: |
          mkdir -p "$RUNNER_TEMP/rtblint"
          curl -fsSL "https://github.com/aleksUIX/rtblint/releases/download/$RTBLINT_VERSION/rtblint-linux-x86_64.tar.gz" \
            | tar -xz -C "$RUNNER_TEMP/rtblint"
          echo "$RUNNER_TEMP/rtblint" >> "$GITHUB_PATH"
      - name: Start the bidder
        run: |
          node server.mjs > bidder.log 2>&1 &
          for _ in $(seq 1 50); do
            if curl -s -o /dev/null http://localhost:8080/; then exit 0; fi
            sleep 0.2
          done
          echo "The bidder did not start." >&2
          exit 1
      - name: Replay fixtures and validate responses
        run: bash scripts/test-bidder.sh fixtures
      - name: Show the bidder log
        if: always()
        run: cat bidder.log
      - name: Keep responses for review
        if: failure()
        uses: actions/upload-artifact@v7
        with:
          name: bidder-responses
          path: out/
