# Triggers Percy job on push to master and release branches to create baseline screenshots
name: Percy

on:
  push:
    branches:
      - master
    paths-ignore:
      - "docs/**"
      - "**.md"
      - "**unit.spec.js"
      - "frontend/test/**"
      - "!frontend/test/metabase-visual/**"

jobs:
  percy:
    timeout-minutes: 45
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
      - name: Prepare front-end environment
        uses: ./.github/actions/prepare-frontend
      - name: Prepare back-end environment
        uses: ./.github/actions/prepare-backend
      - name: Prepare cypress environment
        uses: ./.github/actions/prepare-cypress
      - run: ./bin/build
      - name: Get the version info
        run: |
          jar xf target/uberjar/metabase.jar version.properties
          mv version.properties resources/
      - name: Run maildev
        run: docker run -d -p 80:80 -p 25:25 maildev/maildev:1.1.0
      - name: Percy Test
        run: yarn run test-visual-run
        env:
          PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
        if: env.PERCY_TOKEN != null
