name: v1-build
on:
  push:
    branches:
      - v1
jobs:
  validate:
    name: Validate
    runs-on: ubuntu-latest
    # build-tools is built from ../../tools/build-tools.Dockerfile
    container: kedacore/build-tools:v1
    steps:
      - name: Check out code
        uses: actions/checkout@v3
        with:
          fetch-depth: 1

      - name: Go modules cache
        uses: actions/cache@v3.3.1
        with:
          path: /go/pkg
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: Test
        run: make test

      - name: Login to Docker Hub
        env:
          DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
          DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
        run: echo $DOCKER_HUB_ACCESS_TOKEN | docker login -u $DOCKER_HUB_USERNAME --password-stdin

      - name: Publish
        run: make publish

      - name: Run end to end tests
        env:
          TF_AZURE_SUBSCRIPTION: ${{ secrets.TF_AZURE_SUBSCRIPTION }}
          TF_AZURE_RESOURCE_GROUP: ${{ secrets.TF_AZURE_RESOURCE_GROUP }}
          TF_AZURE_SP_APP_ID: ${{ secrets.TF_AZURE_SP_APP_ID }}
          AZURE_SP_KEY: ${{ secrets.AZURE_SP_KEY }}
          TF_AZURE_SP_TENANT: ${{ secrets.TF_AZURE_SP_TENANT }}
          TF_AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.TF_AZURE_STORAGE_CONNECTION_STRING }}
          TF_AZURE_LOG_ANALYTICS_WORKSPACE_ID: ${{ secrets.TF_AZURE_LOG_ANALYTICS_WORKSPACE_ID }}
        run: make e2e-test
