-
Notifications
You must be signed in to change notification settings - Fork 168
228 lines (199 loc) · 7.84 KB
/
qualityChecks.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: Quality checks
on:
pull_request: { }
# Trigger workflow for release branches.
push:
branches:
- main
- "[0-9]+.[0-9]+.x"
# We use the default concurrency grouping of allowing a single workflow per branch/PR/tag to run at the same time.
# In case of PRs we only care about the results for the last workflow run, so we cancel workflows already in progress
# when new code is pushed, in all other cases (branches/tags) we want to have a history for commits so it's easier to
# find breakages when they occur (head_ref is non-empty only when the workflow is triggered from a PR).
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.head_ref != '' }}
jobs:
setup:
name: Project Setup
runs-on: ubuntu-22.04
strategy:
matrix:
php:
- 8.1
steps:
# We want to reuse our project setup to run different jobs at once.
- uses: actions/cache@v4
id: opensocial-project-build
with:
path: ./*
key: ${{ github.sha }}-${{ matrix.php }}
# Set PHP {{ matrix.php }} as default.
# https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
# We check out the code in a separate folder since we want to use the
# result of the merge rather than the pre-merged code.
# A separate path is used to keep our working directory clean.
- name: Setup a temporary repository
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/tmp/repository
# Since composer must clone from this we require all the history.
fetch-depth: 0
# Create a branch for the specific commit so that composer can check it
# out.
- name: Checkout out to current commit in temporary repository
run: cd $GITHUB_WORKSPACE/tmp/repository && git checkout -b $GITHUB_SHA
# Prepare our composer.json to do a full project set-up.
- name: Copy tests/composer.json to root of workspace
run: cp $GITHUB_WORKSPACE/tmp/repository/tests/composer.json composer.json
# Set up composer with our desired PHP version.
- name: Setup Composer Config similar to temporary repository
run: composer config repositories.social vcs $GITHUB_WORKSPACE/tmp/repository
# Install the version of Open Social under test.
- name: Composer require Open Social of current branch's latest commit.
run: composer require goalgorilla/open_social:dev-${{ github.sha }}#${{ github.sha }}
- name: Set file permissions
run: mkdir -p $GITHUB_WORKSPACE/sites/default/files && sudo chmod -R 664 $GITHUB_WORKSPACE/sites/default/files
phpstan:
needs: setup
name: PHPStan check
runs-on: ubuntu-22.04
strategy:
matrix:
php:
- 8.1
steps:
- uses: actions/cache/restore@v4
id: opensocial-project-build-load
with:
path: ./*
key: ${{ github.sha }}-${{ matrix.php }}
fail-on-cache-miss: true
# Set PHP {{ matrix.php }} as default.
# https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: cs2pr
- name: PHPStan Version
run: $GITHUB_WORKSPACE/vendor/bin/phpstan --version
# Run PHPStan
- name: Run PHPStan analysis
run: $GITHUB_WORKSPACE/vendor/bin/phpstan analyse -c $GITHUB_WORKSPACE/html/profiles/contrib/social/phpstan.neon --error-format=checkstyle | cs2pr
phpcs:
needs: setup
name: PHPCS check
runs-on: ubuntu-22.04
steps:
- uses: actions/cache/restore@v4
id: opensocial-project-build-load
with:
path: ./*
key: ${{ github.sha }}-8.1
fail-on-cache-miss: true
# Set PHP {{ matrix.php }} as default.
# https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none
tools: cs2pr
# Copy phpcs.xml folder to root.
- name: Copy PHPCS.xml file from temporary repository to root of workspace.
run: cp $GITHUB_WORKSPACE/tmp/repository/phpcs.xml phpcs.xml
- name: Run PHPCS checks
id: phpcs
run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml
# https://github.com/staabm/annotate-pull-request-from-checkstyle#using-php_codesniffer
- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml
phpunit:
needs: setup
name: PHPUnit Tests
runs-on: ubuntu-22.04
strategy:
matrix:
php:
- 8.1
steps:
- uses: actions/cache/restore@v4
id: opensocial-project-build-load
with:
path: ./*
key: ${{ github.sha }}-${{ matrix.php }}
fail-on-cache-miss: true
# Set PHP {{ matrix.php }} as default.
# https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: zend.assertions=1
coverage: none
tools: cs2pr
# https://github.com/shivammathur/setup-php#phpunit
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
# Run PHPUnit testing.
- name: Run PHPUnit test suite
run: $GITHUB_WORKSPACE/vendor/bin/phpunit -c $GITHUB_WORKSPACE/html/profiles/contrib/social/phpunit.xml.dist --log-junit $GITHUB_WORKSPACE/test-reports/phpunit.xml
env:
SIMPLETEST_DB: sqlite://tmp/db.sqlite
spellcheck:
name: Spell Check
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: streetsidesoftware/cspell-action@v6
behat-linting:
name: Behat Linting
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install developer tooling
run: composer install --no-interaction --no-progress --working-dir=tests
- name: Find changed test files
run: |
git fetch origin $BRANCH_NAME
# We change the way we create the TEST_FILES env in the GITHUB_ENV file depending on whether we actually have
# test files that were changed in this PR. This is needed to avoid the TEST_FILES variable from containing a
# single blank line in case no files are changed.
TEST_FILES=`git diff --name-only --diff-filter=d origin/$BRANCH_NAME..HEAD -- 'tests/behat/features/capabilities/*.feature'`
if [ "$TEST_FILES" == '' ]; then
echo 'TEST_FILES=' >> $GITHUB_ENV
else
{
echo 'TEST_FILES<<EOF'
echo "$TEST_FILES"
echo EOF
} >> "$GITHUB_ENV"
fi
env:
BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
- name: Ensure behat folder and filenames are kebab-case
if: ${{ env.TEST_FILES != '' }}
run: |
# We must invert the exit code because we want to have no matches, but grep treats no matches as failure.
! MISNAMED_FILES=`grep -v -E '^([a-z\-]+\/)+[a-z0-9\-]+\.feature$' <<<"$TEST_FILES"`
EXIT_CODE=$?
while read -r file && [ ! -z "$file" ]; do
echo "::error file=$file::File and folder names for Behat tests must be kebab-case and alphanumeric."
done <<< "$MISNAMED_FILES"
exit $EXIT_CODE
- name: Lint modified test files
if: ${{ env.TEST_FILES != '' }}
run: xargs tests/vendor/bin/cucumber-linter <<<"$TEST_FILES"