Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
diffy: diffy/diffy@0.0.5
Use diffy
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Compare two URLs and post a message back to Github
1
2
3
4
5
6
7
8
version: 2.1
workflows:
version: 2.1
visual_regression_testing:
jobs:
- diffy/compare_multidev_dev
orbs:
diffy: diffy/diffy@1.0
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
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Use CircleCI to trigger a Diffy compare job between two URLs. Maintained at https://github.com/DiffyWebsite/diffy-circleci-orb
executors:
diffy_executor:
docker:
- image: cimg/php:8.1.21
commands:
trigger_compare:
steps:
- run:
name: Run compare job and post a github comment
command: |
BUILD_DIR=$(pwd)
GITHUB_API_URL="https://api.github.com/repos/$CI_PROJECT_USERNAME/$CI_PROJECT_REPONAME"
if [ -z "$DIFFY_API_KEY" ]
then
echo "Diffy integration is not configured. Add DIFFY_API_KEY to CircleCI variables."
exit 1;
fi
if [ -z "$DIFFY_PROJECT_ID" ]
then
echo "Diffy integration is not configured. Add DIFFY_PROJECT_ID to CircleCI variables."
exit 1;
fi
LAST_GIT_COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ ${LAST_GIT_COMMIT_MESSAGE} == *"--skip-vr"* ]]
then
echo -e "\nVisual regression tests skipped because the last commit contains --skip-vr"
exit 0
fi
# Always run visual tests if "[vr]" is in the last commit message
if [[ ${LAST_GIT_COMMIT_MESSAGE} != *"[vr]"* ]]
then
exit 0
else
echo -e "\nRunning visual regression tests because the latest commit message demands it"
fi
# Ping the multidev environment to wake it from sleep
echo -e "\nPinging the ${TERMINUS_ENV} multidev environment to wake it from sleep..."
curl -I "$MULTIDEV_SITE_URL" >/dev/null
# Ping the live environment to wake it from sleep
echo -e "\nPinging the dev environment to wake it from sleep..."
curl -I "$DEV_SITE_URL" >/dev/null
# Download Diffy-CLI.
wget https://github.com/diffywebsite/diffy-cli/releases/latest/download/diffy.phar
# Authenticate.
php diffy.phar auth:login $DIFFY_API_KEY
# Compare with commit sha so Diffy's github check posts the results.
LAST_GIT_COMMIT_HASH=$(git log -1 --pretty=%H)
php diffy.phar project:compare $DIFFY_PROJECT_ID dev custom --env2Url="${MULTIDEV_SITE_URL}" --commit-sha="${LAST_GIT_COMMIT_HASH}"
jobs:
compare_multidev_dev:
executor: diffy_executor
steps:
- checkout
- attach_workspace:
at: /tmp/workspace
- run: cp /tmp/workspace/bash_env.txt $BASH_ENV
- run: source $BASH_ENV
- trigger_compare
examples:
compare:
description: Compare two URLs and post a message back to Github
usage:
version: 2.1
workflows:
version: 2.1
visual_regression_testing:
jobs:
- diffy/compare_multidev_dev
orbs:
diffy: diffy/diffy@1.0