Skip to content

Merge pull request #1655 from Princeton-CDH/feature/1641-places-metad… #2157

Merge pull request #1655 from Princeton-CDH/feature/1641-places-metad…

Merge pull request #1655 from Princeton-CDH/feature/1641-places-metad… #2157

Workflow file for this run

name: visual tests
on:
push:
branches:
- develop
pull_request:
branches:
- develop
env:
NODE_VERSION: 16 # required for percy CLI
DB_NAME: geniza
DB_USER: geniza
DB_PASSWORD: geniza
DJANGO_ENV: test
jobs:
# Get commit message using HEAD^2 if the event is "pull_request".
# From https://github.community/t/accessing-commit-message-in-pull-request-event/17158/15
get_commit_msg:
name: Get commit message for pull requests
runs-on: ubuntu-latest
steps:
- name: Checkout commits up to and including HEAD^2
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get commit message
id: get_commit_message
run: |
if [[ '${{ github.event_name }}' == 'pull_request' ]]; then
echo ::set-output name=commit_message::$(git log --format=%B -n 1 HEAD^2)
fi
outputs:
commit_message: echo "${{ steps.get_commit_message.outputs.commit_message }}"
visual-tests:
name: Visual regression tests
runs-on: ubuntu-latest
needs: get_commit_msg # grab the output from this job for the commit message
# on pull request: only run if the phrase "[run percy]" (including brackets) is present in the commit message
# on push to develop: run if the phrase "[skip percy]" (including brackets) is NOT present in the commit message
if: ${{ (github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip percy]')) || contains(needs.get_commit_msg.outputs.commit_message, '[run percy]') }}
services:
postgres:
image: postgres:12
env:
POSTGRES_DB: ${{ env.DB_NAME }}
POSTGRES_USER: ${{ env.DB_USER }}
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
ports:
- 5432:5432
solr:
image: solr:9.2
ports:
- 8983:8983
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Decrypt encrypted fonts zip
run: |
gpg --quiet --batch --yes --decrypt --passphrase="${{ secrets.GPG_PASSPHRASE }}" --output sitemedia/fonts.zip sitemedia/fonts.zip.gpg
- name: Unzip decrypted fonts zip
run: |
unzip -q -o sitemedia/fonts.zip -d sitemedia
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: |
npm-${{ hashFiles('package-lock.json') }}
npm-
- name: Install JS dependencies
run: npm ci
- name: Get Python version
run: echo "PYTHON_VERSION=$(cat .python-version)" >> $GITHUB_ENV
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
pip-${{ hashFiles('requirements/*.txt') }}
pip-
- name: Install dependencies
run: pip install -r requirements/test.txt
- name: Configure solr and create test core
run: |
docker cp solr_conf ${{ job.services.solr.id }}:/opt/solr/server/solr/configsets/geniza
docker exec --user root ${{ job.services.solr.id }} /bin/bash -c "chown -R solr:solr /opt/solr/server/solr/configsets/geniza"
docker exec -d ${{ job.services.solr.id }} cp -r /opt/solr/server/solr/configsets /var/solr/data
curl "http://localhost:8983/solr/admin/cores?action=CREATE&name=geniza&configSet=geniza"
# NOTE: command line core creation does not seem to actually use the configset
- name: Setup local_settings.py
run: python -c "import uuid; print('SECRET_KEY = \'%s\'' % uuid.uuid4())" >> geniza/settings/local_settings.py
- name: Run webpack to process scss/js
run: npm run build
- name: Migrate database
run: python manage.py migrate
- name: Load test site data
run: python manage.py create_test_site
- name: Update Solr index
run: python manage.py index
- name: Compile translation text
run: |
sudo apt install gettext
python manage.py compilemessages
- name: Build static assets
run: python manage.py collectstatic
- name: Take DOM snapshots and upload to Percy
run: npm run test:visual
env:
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}