Skip to content

chore: fix visual testing workflow (#1023) #319

chore: fix visual testing workflow (#1023)

chore: fix visual testing workflow (#1023) #319

name: Visual testing
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
repository_dispatch:
types: [run_visual_testing]
jobs:
prepare-visual-testing:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20.11.0
registry-url: https://npm.pkg.github.com/
scope: '@carlsberggbs'
- name: Set npm registry and authentication
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > .npmrc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
if [ -e yarn.lock ]; then
yarn install
elif [ -e package-lock.json ]; then
npm ci
else
npm i
fi
- name: 'Tar files'
run: tar -cvf malty.tar .
- name: Save packages folder
uses: actions/upload-artifact@v3
with:
name: malty-artifact
if-no-files-found: error
path: malty.tar
retention-days: 1
visual-testing:
runs-on: ubuntu-latest
needs: prepare-visual-testing
env:
BASE_URL: https://pr-${{ github.event.number }}.d3acoh2jwy8aw9.amplifyapp.com
strategy:
fail-fast: false
matrix:
containers: [1, 2]
container:
image: cypress/included:cypress-13.6.4-node-20.11.0-chrome-121.0.6167.85-1-ff-120.0-edge-121.0.2277.83-1
env:
BASE_URL: ${{ env.BASE_URL }}
steps:
- uses: actions/checkout@v3
- name: Download the build folder
uses: actions/download-artifact@v3
with:
name: malty-artifact
- name: 'Untar files'
run: tar -xvf malty.tar
- run: |
if [ -e yarn.lock ]; then
yarn install
elif [ -e package-lock.json ]; then
npm ci
else
npm i
fi
- name: Run visual testing in desktop
if: matrix.containers == 1
# TODO: As soon as the ticket https://carlsberggbs.atlassian.net/browse/DEVOPS-3179 is finished we can remove the npx wait-on utility.
run: npx wait-on ${{ env.BASE_URL }} --interval 300000 --timeout 15m && yarn cypress:ci:desktop
- name: Run visual testing in mobile
if: matrix.containers == 2
run: echo 'Not implemented yet, moving on...'.
shell: bash
- name: Upload Cypress Screenshots
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-snapshots-${{ matrix.containers }}
path: cypress/snapshots
retention-days: 1