-
Notifications
You must be signed in to change notification settings - Fork 3
93 lines (79 loc) · 3.43 KB
/
run-visual-regression-tests-manual.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Run Visual Regression Tests
on:
workflow_dispatch:
inputs:
BASE_URL:
description: 'Base URL: (ex. https://www.nysenate.gov or https://pr-###-nysenate-2022.pantheonsite.io). Setting to https://www.nysenate.gov will refresh the baseline images. Any other URL will compare against the baseline images.'
required: true
type: string
jobs:
deploy:
runs-on: ubuntu-latest
env:
TEST_PATH: 'tests/cypress/'
PERCY_TARGET_BRANCH: 'main'
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
steps:
- name: Clone the github repo in the Github Action container
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.PERCY_TARGET_BRANCH }}
- name: Setup PHP for Terminus
uses: shivammathur/setup-php@v2
with:
php-version: ${{ vars.PHP_VERSION }}
- name: Add SSH Key for Terminus
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.PANTHEON_SSH_PRIVATE_KEY }}
- name: Disable Pantheon SSH strict host key checking
run: 'printf "\nHost *\n\tStrictHostKeyChecking no" >> ~/.ssh/config'
- name: Install Terminus so we can wakeup environments
uses: pantheon-systems/terminus-github-actions@main
with:
pantheon-machine-token: ${{ secrets.PANTHEON_MACHINE_TOKEN }}
- name: Set PERCY_BRANCH environment variable
run: |
BASE_URL=${{ inputs.BASE_URL }}
BASE_URL=${BASE_URL%/}
if [[ "$BASE_URL" == "https://www.nysenate.gov" ]]; then
echo "PERCY_BRANCH=main" >> $GITHUB_ENV
echo "PANTHEON_ENV=live" >> $GITHUB_ENV
elif [[ "$BASE_URL" =~ nysenate-2022.pantheonsite.io ]]; then
SUBDOMAIN=${BASE_URL#http://}
SUBDOMAIN=${SUBDOMAIN#https://}
SUBDOMAIN=${SUBDOMAIN%%-nysenate-2022*}
echo "PERCY_BRANCH=$SUBDOMAIN" >> $GITHUB_ENV
echo "PANTHEON_ENV=$SUBDOMAIN" >> $GITHUB_ENV
else
echo "No match found for BASE_URL"
echo "PERCY_REVIEW_URL=The base url was invalid." >> $GITHUB_ENV
fi
- name: Wake up the Pantheon site
run: terminus env:wake ${{ vars.PANTHEON_SITE }}.${{ env.PANTHEON_ENV }}
- name: Stop if PERCY_BRANCH is not set
if: ${{ !env.PERCY_BRANCH }}
run: exit 1
- name: Setup Node with the version set in .nvmrc
uses: actions/setup-node@v3
with:
node-version-file: '${{ env.TEST_PATH }}.nvmrc'
cache: 'npm'
cache-dependency-path: '${{ env.TEST_PATH }}package-lock.json'
- name: Run Visual Regression Tests
run: |
cd ${{ env.TEST_PATH }}
npm install
OUTPUT=$(npx percy exec -- cypress run --config baseUrl=${{ inputs.BASE_URL }} --spec "cypress/e2e/visual-regression.cy.js" | tee /dev/fd/2)
PERCY_REVIEW_URL=$(echo "$OUTPUT" | grep -o 'https://percy.io/[^ ]*')
echo "PERCY_REVIEW_URL=$PERCY_REVIEW_URL" >> $GITHUB_ENV
- name: Post to a Slack channel
if: always()
id: slack
uses: slackapi/[email protected]
with:
channel-id: '${{ vars.SLACK_CHANNEL }}'
slack-message: "@${{ github.actor }} ran visual regression tests against ${{ inputs.BASE_URL }}. Percy results can be viewed at ${{ env.PERCY_REVIEW_URL }}."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}