UHF-9998 link size #803
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
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 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set variables | |
run: echo "DRUPAL_ROOT=$HOME/drupal" >> $GITHUB_ENV | |
- name: Parse $THEME_NAME from composer.json | |
run: echo "THEME_NAME=$(cat composer.json | jq -r .name | awk -F/ '{print $NF}')" >> $GITHUB_ENV | |
- name: Set theme folder | |
run: echo "THEME_FOLDER=$DRUPAL_ROOT/public/themes/contrib/$THEME_NAME" >> $GITHUB_ENV | |
- name: Update | |
run: sudo apt update | |
- name: Clone platform | |
run: | | |
git clone --depth=1 https://github.com/City-of-Helsinki/drupal-helfi-platform.git $DRUPAL_ROOT | |
rm -rf $DRUPAL_ROOT/.git | |
- name: Install and start Stonehenge | |
run: | | |
git clone -b 4.x https://github.com/druidfi/stonehenge.git ~/stonehenge | |
cd ~/stonehenge && make up | |
- name: Build project | |
working-directory: ${{ env.DRUPAL_ROOT }} | |
env: | |
COMPOSER_MIRROR_PATH_REPOS: 1 | |
run: | | |
composer config repositories.5 path $GITHUB_WORKSPACE | |
composer require drupal/redis drupal/$THEME_NAME -W | |
# We use COMPOSER_MIRROR_PATH_REPOS=1 to mirror local repository | |
# instead of symlinking it to make sure the code is available inside | |
# the app container. | |
cp -r $GITHUB_WORKSPACE/.git $THEME_FOLDER/ | |
# Store the files folder in cache, so we don't have to install Drupal from | |
# scratch every time. | |
# You can force new re-installation by manually deleting the Actions cache. | |
- name: Restore files folder | |
id: drupal-cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.DRUPAL_ROOT }}/public/sites/default/files | |
key: drupal-cache | |
- name: Prepare Drupal setup | |
working-directory: ${{ env.DRUPAL_ROOT }} | |
run: | | |
mkdir public/sites/default/files/styles -p && \ | |
chmod 777 public/sites/default -R | |
# Start the project using Docker compose and wait until the database server | |
# is up. | |
- name: Start the project | |
working-directory: ${{ env.DRUPAL_ROOT }} | |
run: | | |
docker compose up -d --wait | |
for i in {1..5}; do docker compose exec app bash \ | |
-c "drush sqlq 'SHOW TABLES;' -q" && break || sleep 5; done | |
# Install the site from existing dump if the cache restoration was successful. | |
- name: Install Drupal from existing dump | |
working-directory: ${{ env.DRUPAL_ROOT }} | |
if: steps.drupal-cache.outputs.cache-hit == 'true' | |
run: | | |
docker compose exec app bash -c "mysql --user=drupal --password=drupal --database=drupal --host=db --port=3306 -A < /app/public/sites/default/files/latest.sql" | |
docker compose exec app bash -c "drush updb -y && drush cr" | |
# Install the site from scratch if we failed to restore the cache. | |
# Dump the database into the files folder, so we can speed up the | |
# installation process and install Drupal using that dump from now on. | |
- name: Install Drupal from scratch | |
working-directory: ${{ env.DRUPAL_ROOT }} | |
if: steps.drupal-cache.outputs.cache-hit != 'true' | |
run: | | |
docker compose exec app bash -c "drush si minimal -y" | |
docker compose exec app bash -c "drush en redis -y" | |
docker compose exec app bash -c "drush en helfi_test_content -y" | |
docker compose exec app bash -c "drush sql-dump --result-file=/app/public/sites/default/files/latest.sql" | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
- name: NPM Install | |
working-directory: ${{ env.THEME_FOLDER }} | |
run: | | |
npm install | |
# 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/drupal-hdbt/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: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
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@v2 | |
with: | |
comment_tag: status | |
pr_number: ${{ github.event.number }} | |
message: "${{join(steps.run-tests.outputs.*, ' ')}}" | |
- name: Export container logs | |
working-directory: ${{ env.DRUPAL_ROOT }} | |
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 |