Skip to content

feat: Reusable validator site tests #132

feat: Reusable validator site tests

feat: Reusable validator site tests #132

name: Test and Deploy
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
repository_dispatch:
types: [data-models-update, data-model-validator-update, rpde-validator-update]
workflow_call:
inputs:
data-models_ref:
default: 'refs/heads/master'
required: false
type: string
data-model-validator_ref:
default: 'refs/heads/master'
required: false
type: string
rpde-validator_ref:
default: 'refs/heads/master'
required: false
type: string
data-model-validator-site_ref:
default: 'refs/heads/master'
required: false
type: string
jobs:
test-site:
runs-on: ubuntu-latest
outputs:
lost-pixel-conclusion: ${{ steps.lp.conclusion }}
steps:
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14
- name: Checkout data models
uses: actions/checkout@v2
with:
repository: openactive/data-models
ref: ${{ inputs.data-models_ref }}
path: data-models
- name: Install data models
run: npm install
working-directory: data-models
- name: Test data models
run: npm test
working-directory: data-models
- name: Checkout model validator
uses: actions/checkout@v2
with:
repository: openactive/data-model-validator
ref: ${{ inputs.data-model-validator_ref }}
path: data-model-validator
- name: Install data model validator
run: npm install
working-directory: data-model-validator
- name: Test data model validator
run: npm test
working-directory: data-model-validator
- name: Checkout rpde validator
uses: actions/checkout@v2
with:
repository: openactive/rpde-validator
ref: ${{ inputs.rpde-validator_ref }}
path: rpde-validator
- name: Install rpde validator
run: npm install
working-directory: rpde-validator
- name: Test rpde validator
run: npm test
working-directory: rpde-validator
- name: Checkout validator site
uses: actions/checkout@v2
with:
repository: openactive/data-model-validator-site
ref: ${{ inputs.data-model-validator-site_ref || github.ref }}
path: data-model-validator-site
- name: Install validator site
run: npm install
working-directory: data-model-validator-site
- name: Update data-model-validator-site to reference local data-models
run: npm install file:../data-models
working-directory: data-model-validator-site
- name: Update data-model-validator-site to reference local data-model-validator
run: npm install file:../data-model-validator
working-directory: data-model-validator-site
- name: Update data-model-validator-site to reference local rpde-validator
run: npm install file:../rpde-validator
working-directory: data-model-validator-site
- name: Test validator site
run: npm test
working-directory: data-model-validator-site
- name: Start server (in background)
run: npm run start &
working-directory: data-model-validator-site
- name: Check for unintentional UI changes with Lost Pixel
id: lp
uses: lost-pixel/lost-pixel@v3.16.0
- name: Upload Lost Pixel artefacts
uses: actions/upload-artifact@v3
if: ${{ failure() && steps.lp.conclusion == 'failure' }}
with:
name: lost-pixel-artefacts
path: .lostpixel
create-pr-to-update-lost-pixel-baseline:
runs-on: ubuntu-latest
needs: [test-site]
# Only run this job on branches other than master; this is to prevent the Lost Pixel baseline from being updated on the master branch.
# The baseline should only be updated on PRs, not on the master branch.
if: ${{ github.repository == 'openactive/data-model-validator-site' && failure() && github.ref != 'refs/heads/master' && needs.test-site.outputs.lost-pixel-conclusion == 'failure'}}
steps:
- name: Checkout validator site
uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14
- name: Install
run: npm install
- name: Test
run: npm test
- name: Start server (in background)
run: npm run start &
- name: Lost Pixel
uses: lost-pixel/lost-pixel@v3.16.0
env:
LOST_PIXEL_MODE: update
# Note this deletes the branch and PR if differences are resolved
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
path: ./
token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
commit-message: Update lost-pixel baselines
committer: openactive-bot <openactive-bot@users.noreply.github.com>
author: openactive-bot <openactive-bot@users.noreply.github.com>
signoff: false
branch: 'lost-pixel-update/${{ github.ref_name }}'
delete-branch: true
title: 'Lost Pixel update - ${{ github.ref_name }}'
body: |
Automated baseline update PR created by Lost Pixel
Please check the updated baseline images are as expected before merging this PR.
labels: |
automated pr
draft: false
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
deploy-site:
needs: [test-site]
if: ${{ github.repository == 'openactive/data-model-validator-site' && github.ref == 'refs/heads/master' }}
concurrency:
group: validator-staging.openactive.io
cancel-in-progress: true
environment:
# Matches the name of the Heroku app
name: validator-staging.openactive.io
url: https://validator-staging.openactive.io/
runs-on: ubuntu-latest
steps:
- name: Checkout validator app
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Heroku authentication
uses: extractions/netrc@v2
with:
machine: git.heroku.com
password: ${{ secrets.HEROKU_API_KEY }}
- name: Deploy validator app to Heroku
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: |
heroku git:remote --app data-model-validator-staging
git push heroku master -f
- name: Smoke test with Lost Pixel
id: lp
uses: lost-pixel/lost-pixel@v3.16.0
env:
LOST_PIXEL_BASE_URL: https://validator-staging.openactive.io
- name: Upload Lost Pixel artefacts
uses: actions/upload-artifact@v3
if: ${{ failure() && steps.lp.conclusion == 'failure' }}
with:
name: lost-pixel-artefacts
path: .lostpixel
promote-site:
needs: deploy-site
if: ${{ github.repository == 'openactive/data-model-validator-site' && github.ref == 'refs/heads/master' }}
concurrency:
group: validator.openactive.io
cancel-in-progress: true
environment:
name: validator.openactive.io
url: https://validator.openactive.io/
runs-on: ubuntu-latest
steps:
- name: Promote validator app to production
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: |
heroku pipelines:promote --app data-model-validator-staging