name: Trigger Load Test
on:
  workflow_dispatch:
    inputs:
      environment: 
        description: 'The environment on which to run load tests'
        required: true
        default: 'stage'
      region:
        description: 'The region on which to run load tests'
        required: true
        default: 'us-east-1'
      version:
        description: 'Which version of the load test to run'
        required: true
        default: '0'
      testSetId:
        description: 'Which test set you wish to run'
        required: true
        default: 'en-IT'
env:
  ATL_NODE_VERSION: '16.17.0'

jobs:
  load-test:
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v3.3.0
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ env.ATL_NODE_VERSION }}
      - name: install
        run: |
          npm ci
          npm run compile
        working-directory: .companyx_performance
      - name: Run k6 cloud test
        uses: grafana/k6-action@v0.2.0
        with:
          filename: .companyx_performance/dist/load-v${{ github.event.inputs.version }}.js
          token: ${{ secrets.GLOBAL_K6_CLOUD_TOKEN }}
          flags: --out cloud
        env:
          REGION: ${{ github.event.inputs.region }}
          ENV: ${{ github.event.inputs.environment }}
          TEST_SET_ID: ${{ github.event.inputs.testSetId }}
