name: integration

on:
  push:
    branches:
      - 'master'
      - 'develop'
      - '*rc'
      - 'regenesis/*'
  pull_request:
  workflow_dispatch:

jobs:
  integration:
    runs-on: ubuntu-latest
    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000
    env:
        DOCKER_BUILDKIT: 1
        COMPOSE_DOCKER_CLI_BUILD: 1
    steps:
      # Monorepo tests
      - uses: actions/checkout@v2

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v2
        id: yarn-cache
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Bring the stack up
        working-directory: ./ops
        run: |
          ./scripts/stats.sh &
          docker-compose up -d

      - name: Wait for the Sequencer node
        working-directory: ./ops
        run: ./scripts/wait-for-sequencer.sh

      - name: Run the integration tests
        working-directory: ./ops
        run: docker-compose run integration_tests

      - name: Collect docker logs on failure
        if: failure()
        uses: jwalton/gh-docker-logs@v1
        with:
          images: 'ethereumoptimism/hardhat,ops_deployer,ops_dtl,ethereumoptimism/l2geth,ethereumoptimism/message-relayer,ops_batch_submitter,ethereumoptimism/l2geth,ops_integration_tests'
          dest: '/home/runner/logs'

      - name: Tar logs
        if: failure()
        run: tar cvzf ./logs.tgz ~/logs

      - name: Upload logs to GitHub
        if: failure()
        uses: actions/upload-artifact@master
        with:
          name: logs.tgz
          path: ./logs.tgz
