name: CI ARC E2E Linux VM Test

on:
  push:
    branches:
      - master
  pull_request:
  workflow_dispatch:

env:
  TARGET_ORG: actions-runner-controller
  CLUSTER_NAME: e2e-test
  RUNNER_VERSION: 2.302.1
  IMAGE_REPO: "test/test-image"
  
jobs:
  setup-steps:
    runs-on: [ubuntu-latest]
    steps:
      - uses: actions/checkout@v3
      - name: Add env variables
        run: |
            TAG=$(echo "0.0.$GITHUB_SHA")
            echo "TAG=$TAG" >> $GITHUB_ENV
            echo "IMAGE=$IMAGE_REPO:$TAG" >> $GITHUB_ENV
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
        with:
          version: latest
      - name: Docker Build Test Image
        run: |
            DOCKER_CLI_EXPERIMENTAL=enabled DOCKER_BUILDKIT=1 docker buildx build --build-arg RUNNER_VERSION=$RUNNER_VERSION --build-arg TAG=$TAG -t $IMAGE . --load
      - name: Create Kind cluster
        run: |
          PATH=$(go env GOPATH)/bin:$PATH
          kind create cluster --name $CLUSTER_NAME
      - name: Load Image to Kind Cluster
        run: kind load docker-image $IMAGE --name $CLUSTER_NAME
      - name: Get Token
        id: get_workflow_token
        uses: peter-murray/workflow-application-token-action@8e1ba3bf1619726336414f1014e37f17fbadf1db
        with:
          application_id: ${{ secrets.ACTIONS_ACCESS_APP_ID }}
          application_private_key: ${{ secrets.ACTIONS_ACCESS_PK }}
          organization: ${{ env.TARGET_ORG }}
      - uses: ./.github/actions/e2e-arc-test
        with:
          github-token: ${{ steps.get_workflow_token.outputs.token }}
          config-url: "https://github.com/actions-runner-controller/arc_e2e_test_dummy"
          docker-image-repo: $IMAGE_REPO
          docker-image-tag: $TAG
