name: KONG

env:
  test_api_key: ${{ secrets.KONG_SERVER_SDK_KEY }}
  test_client_key: ${{ secrets. KONG_CLIENT_SDK_KEY }}
  repo_pat: ${{ secrets.KONG_FINE_GRAINED_REPO_PAT }}
  FORCE_COLOR: true

on:
  workflow_dispatch:
    inputs:
      kong-branch:
        description: 'Kong branch name'
        type: string
        required: false
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  KONG:
    timeout-minutes: 15
    runs-on: ubuntu-latest
    steps:
      - name: Get KONG
        run: |
          if [[ -n "${{ inputs.kong-branch }}" && ${{ github.event_name }} == "workflow_dispatch" ]]; then
              git clone -b ${{ inputs.kong-branch }} https://oauth2:$repo_pat@github.com/statsig-io/kong.git .
          else
              git clone https://oauth2:$repo_pat@github.com/statsig-io/kong.git .
          fi

      - uses: actions/setup-node@v4
        with:
          node-version: '16.x'

      - name: Install Deps
        run: npm install

      - name: Setup Node SDK
        run: npm run kong -- setup nodejs -v

      - name: Build Bridge
        run: npm run kong -- build nodejs -v

      - name: Run Tests
        run: npm run kong -- test nodejs -v -r

      - name: Run Measure Base Benchmark Score
        if: github.ref == 'refs/heads/main'
        run: npm run kong -- regression_test nodejs -p base -v

      # - name: Upload base benchmark score
      #   if: github.ref == 'refs/heads/main'
      #   uses: actions/upload-artifact@v3
      #   with:
      #     name: nodejs-perf
      #     path: /tmp/perf/nodejs_perf_score.txt
      #     retention-days: 5

      # - name: Run regression test
      #   if: github.ref != 'refs/heads/main'
      #   run: npm run kong -- regression_test nodejs -p test -v
