Skip to content

Dev to main

Dev to main #349

Workflow file for this run

on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
paths-ignore:
- '**.md'
branches-ignore:
- 'renovate/**'
push:
branches:
- main
name: Visual regression tests
# The concurrency group is used to make sure only one visual regression test
# can be run at a time. Running multiple tests in parallel can cause a race
# condition with GitHub Pages deployments.
# Due to GitHub's limitation, only one test suite can be queued and run at
# a time; any additional run will be canceled automatically and must be
# re-started manually.
concurrency:
group: visual-regression
jobs:
tests:
# Don't run tests against Draft pull requests.
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
env:
THEME_FOLDER: public/themes/custom/hdbt_subtheme
REPORT_REPO: helsinki-paatokset-visual-regression
steps:
- uses: actions/checkout@v5
with:
repository: druidfi/stonehenge
- name: Install and start Stonehenge
run: make up
- uses: actions/checkout@v5
- name: Setup Docker compose environment variables
run: |
touch .env.local
source .env
# Make sure testing is always included in compose profiles.
if [ ! -n "$COMPOSE_PROFILES" ]; then
COMPOSE_PROFILES=testing
else
COMPOSE_PROFILES=$COMPOSE_PROFILES,testing
fi
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV
- name: Start compose project
run: |
docker compose up -d --wait
- name: Build project
run: docker compose exec app bash -c "composer install --no-interaction"
- name: Download latest dump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh run download -n latest.sql
- name: Install Drupal
run: |
docker compose exec app bash -c '$(drush sql:connect) < latest.sql'
docker compose exec app bash -c "drush deploy"
docker compose exec app bash -c "drush en paatokset_test_content -y"
- uses: actions/setup-node@v5
with:
node-version-file: ${{ env.THEME_FOLDER }}/.nvmrc
- name: NPM Install
working-directory: ${{ env.THEME_FOLDER }}
run: |
npm install --ignore-scripts
# Reference images are stored as Actions artifact, attempt to restore
# the images.
- name: Restore bitmaps
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: ${{ env.THEME_FOLDER }}
run: gh run download -n bitmaps -D backstop/full/bitmaps_reference || true
# Generate new reference images if:
# - Something is merged into the main branch.
# - Reference images do not exist yet
# - Pull request has 'recreate-reference-images' label.
- name: Evaluate if we should re-create reference images
id: evaluate-reference-images
if: |
contains(github.event.pull_request.labels.*.name, 'recreate-reference-images') ||
hashFiles('backstop/full/bitmaps_reference/') != '' ||
github.ref == 'refs/heads/main'
run: echo "generate-references=true" >> $GITHUB_OUTPUT
- name: Generate new reference images
working-directory: ${{ env.THEME_FOLDER }}
if: steps.evaluate-reference-images.outputs.generate-references == 'true'
run: npm run full-reference
- uses: actions/upload-artifact@v4
if: steps.evaluate-reference-images.outputs.generate-references == 'true'
with:
name: bitmaps
path: ${{ env.THEME_FOLDER }}/backstop/full/bitmaps_reference
overwrite: true
compression-level: 0
- name: Run tests
working-directory: ${{ env.THEME_FOLDER }}
id: run-tests
# Skip tests if we generated reference images since the tests should never fail.
if: steps.evaluate-reference-images.outputs.generate-references != 'true'
run: |
if ! npm run full-test; then
echo "result=:warning: Visual regression found! Please check if this change is wanted or accidental. " >> $GITHUB_OUTPUT
else
echo "result=✅ Tests passed!" >> $GITHUB_OUTPUT
fi
echo "report_url=You can check the output here: https://city-of-helsinki.github.io/${{ env.REPORT_REPO }}/pull/${{ github.event.pull_request.number }}/html_report/" >> $GITHUB_OUTPUT
- name: Deploy to PR preview
uses: peaceiris/actions-gh-pages@v4
if: steps.evaluate-reference-images.outputs.generate-references != 'true'
with:
personal_token: ${{ secrets.VISUAL_REGRESSION_DEPLOY_KEY }}
external_repository: City-of-Helsinki/${{ env.REPORT_REPO }}
publish_branch: main
publish_dir: ${{ env.THEME_FOLDER }}/backstop/full
destination_dir: pull/${{github.event.number}}
- name: Update comment
if: steps.evaluate-reference-images.outputs.generate-references != 'true'
uses: thollander/actions-comment-pull-request@v3
with:
comment-tag: status
pr-number: ${{ github.event.number }}
message: "${{join(steps.run-tests.outputs.*, ' ')}}"
- name: Export container logs
working-directory: ${{ env.DRUPAL_ROOT }}
if: always()
run: docker compose logs app > /tmp/container.log
- name: Upload container logs
uses: actions/upload-artifact@v4
if: always()
with:
name: container-log
path: /tmp/container.log
retention-days: 1