on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
name: Test
jobs:
  npm-test:
    name: JavaScript Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Install Node
        uses: actions/setup-node@v3
      - name: Install pnpm
        uses: pnpm/action-setup@v2.2.2
        with:
          version: 6.20.1
      - name: Install dependencies
        run: pnpm install
      - name: Run Tests
        run: pnpm run test
  go-test:
    name: Go Tests
    runs-on: ubuntu-latest
    steps:
      - name: Install Go
        uses: actions/setup-go@v3
        with:
          go-version: 1.18.x
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Run Go Tests with Coverage
        run: make test SKIP_ASSET=1
  int-test:
    name: Integration Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 2
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2.0.0
      - name: Login to DockerHub
        uses: docker/login-action@v2.0.0
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: Build images
        run: COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f e2e/docker-compose.yml build --build-arg BUILDKIT_INLINE_CACHE=1
      - name: Push images
        run: COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f e2e/docker-compose.yml push
      - name: Set commit message for push
        if: github.event_name == 'push'
        run: |
          echo "GIT_LOG_MESSAGE<<EOF" >> $GITHUB_ENV
          git log -1 --pretty=%B ${GITHUB_SHA} >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV
      - name: Set commit message for pull request
        if: github.event_name == 'pull_request'
        run: |
          echo "GIT_LOG_MESSAGE<<EOF" >> $GITHUB_ENV
          git log -1 --pretty=%B ${{github.event.pull_request.head.sha}} >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV
      - name: Run tests
        run: COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f e2e/docker-compose.yml up --build --force-recreate --exit-code-from cypress
