|
| 1 | +name: Visual Regressions |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +env: |
| 12 | + VISUAL_REGRESSION_SNAPSHOT_DIRECTORY: "__image_snapshots__" |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + name: Run Tests |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: github.event.ref != 'refs/heads/main' |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + - uses: actions/setup-node@v3 |
| 22 | + with: |
| 23 | + node-version: 18 |
| 24 | + cache: "npm" |
| 25 | + - name: "Download artifacts" |
| 26 | + # Turns out you can not use artifacts from a previous workflow run. |
| 27 | + # I'm reluctant to check in the resulting screenshots into the repository, |
| 28 | + # which is why we use the following hack, until it's solved on Github side: |
| 29 | + # https://github.com/actions/download-artifact/issues/3 |
| 30 | + run: | |
| 31 | + RUN_ID=`gh run --repo $GITHUB_REPOSITORY --branch main list --workflow "Visual Regressions" --json databaseId --jq .[0].databaseId` |
| 32 | + echo "Downloading snapshots created in run ${RUN_ID}" |
| 33 | + gh run --repo $GITHUB_REPOSITORY download ${RUN_ID} -n "visual-regression-snapshots" -D ${{ env.VISUAL_REGRESSION_SNAPSHOT_DIRECTORY }} |
| 34 | + env: |
| 35 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + - run: npm install |
| 37 | + - run: npm run build |
| 38 | + - run: npm run test:visual |
| 39 | + - uses: actions/upload-artifact@v3 |
| 40 | + if: always() |
| 41 | + with: |
| 42 | + name: visual-regression-snapshots-results |
| 43 | + path: ${{ env.VISUAL_REGRESSION_SNAPSHOT_DIRECTORY }} |
| 44 | + update: |
| 45 | + name: Update Snapshots |
| 46 | + runs-on: ubuntu-latest |
| 47 | + if: github.event.ref == 'refs/heads/main' |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v4 |
| 50 | + - uses: actions/setup-node@v3 |
| 51 | + with: |
| 52 | + node-version: 18 |
| 53 | + cache: "npm" |
| 54 | + - run: npm install |
| 55 | + - run: npm run build |
| 56 | + - run: npm run test:visual:update |
| 57 | + - uses: actions/upload-artifact@v3 |
| 58 | + with: |
| 59 | + name: visual-regression-snapshots |
| 60 | + path: ${{ env.VISUAL_REGRESSION_SNAPSHOT_DIRECTORY }} |
0 commit comments