-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (116 loc) · 4.33 KB
/
check-before-merging.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Automated checks
# on:
# workflow_dispatch:
# pull_request:
# branches:
# - main # TODO uncomment lines 2-6
env:
application-name: <application name> # #UPDATE name to application name.
jobs:
format:
name: "Check code formatting"
runs-on: ubuntu-20.04
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
activate-environment: ${{ env.application-name }}
environment-file: environment.yml
- name: Run formatter
run: black --check ./
lint:
name: "Check code for linting errors"
runs-on: ubuntu-20.04
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
activate-environment: ${{ env.application-name }}
environment-file: environment.yml
- name: Run linter
run: pylint $(pwd)
test:
name: "Run tests"
runs-on: ubuntu-20.04
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
activate-environment: ${{ env.application-name }}
environment-file: environment.yml
- name: Execute tests
run: python -u -m pytest --headless tests --ignore=tests/visual/
# this runs visual tests as Github actions, they have been more stable (less machine dependent - GitHub Actions provides a consistent and isolated environment) this way.
visual-tests:
name: "Run visual regression tests"
runs-on: ubuntu-20.04
permissions: write-all
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
activate-environment: ${{ env.application-name }}
environment-file: environment.yml
- name: Ensure browsers are installed
run: python -m playwright install --with-deps chromium
- name: Execute visual tests
id: visual-tests
run: python -u -m pytest --headless --update-snapshots tests/visual
- name: Set snapshots-updated variable
run: |
if [[ `git status --porcelain` ]]; then
echo "snapshots-updated=true" >> $GITHUB_ENV
else
echo "snapshots-updated=false" >> $GITHUB_ENV
fi
- name: Upload snapshot failures folder
uses: actions/upload-artifact@v4
if: env.snapshots-updated == 'true'
with:
name: snapshots_failure_folder
path: /home/runner/work/*TEMPLATE* #UPDATE for correct runner path
- name: Push up updated snapshots
if: env.snapshots-updated == 'true'
run: |
git add .
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -m "Add new snapshots"
git push
- name: Post comment on PR
if: env.snapshots-updated == 'true'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:warning: **The visual tests failed and the snapshots have been updated**
Please view the differences in the [snapshots_failure folder in the Action summary](https://github.com/communitiesuk/*REPO_NAME*/actions/runs/${context.runId}). #UPDATE
If you are happy with the changes, you need to pull down the changes locally and then run the following commands in your terminal:
*git commit --allow-empty -m "Trigger Build"*
*git push*
This will run the checks again to allow the PR to be merged (this is needed as although the Action pushes changes to the branch, it does not force a new workflow run).
**Note:** If you wish to make further changes, please pull from the branch to get the pushed snapshots.`
})