name: 'E2E ARC Test Action'
description: 'Includes common arc installation, setup and test file run'

inputs:
  github-token:
    description: 'JWT generated with Github App inputs'
    required: true
  config-url:
    description: "URL of the repo, org or enterprise where the runner scale sets will be registered"
    required: true
  docker-image-repo:
    description: "Local docker image repo for testing"
    required: true
  docker-image-tag:
    description: "Tag of ARC Docker image for testing"
    required: true

runs:
  using: "composite"
  steps:
    - name: Install ARC
      run: helm install arc --namespace "arc-systems" --create-namespace --set image.tag=${{ inputs.docker-image-tag }}  --set image.repository=${{ inputs.docker-image-repo }} ./charts/gha-runner-scale-set-controller
      shell: bash
    - name: Get datetime
      # We are using this value further in the runner installation to avoid runner name collision that are a risk with hard coded values.
      # A datetime including the 3 nanoseconds are a good option for this and also adds to readability and runner sorting if needed.
      run: echo "DATE_TIME=$(date +'%Y-%m-%d-%H-%M-%S-%3N')" >> $GITHUB_ENV
      shell: bash
    - name: Install runners
      run: |
          helm install "arc-runner-${{ env.DATE_TIME }}" \
          --namespace "arc-runners" \
          --create-namespace \
          --set githubConfigUrl="${{ inputs.config-url }}" \
          --set githubConfigSecret.github_token="${{ inputs.github-token }}" \
          ./charts/gha-runner-scale-set \
          --debug
          kubectl get pods -A
      shell: bash
    - name: Test ARC scales pods up and down
      run: |
          export GITHUB_TOKEN="${{ inputs.github-token }}"
          export DATE_TIME="${{ env.DATE_TIME }}"
          go test ./test_e2e_arc -v
      shell: bash
