-
Notifications
You must be signed in to change notification settings - Fork 11
234 lines (204 loc) · 8.04 KB
/
ci.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
229
230
231
232
233
234
name: CI
on:
push:
branches:
- main
tags:
- "*"
pull_request:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
drupal_codequality:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Drupal Code Quality
uses: hussainweb/drupalqa-action@v2
id: drupalqa
with:
php-version: 8.2
checks: |
grumphp:
tasks:
- phplint
- yamllint
- jsonlint
- phpcs
- phpmd
- twigcs
frontend_codequality:
runs-on: ubuntu-latest
container: node:lts
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Get Cache Directories
id: cache-dir
run: echo "npm-dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: |
**/node_modules
${{ steps.cache-dir.outputs.npm-dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Frontend Code Quality
run: |
cd web/themes/custom/contribtracker
npm ci --prefer-offline --no-audit
npm run lint
drupal_test:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
env:
# For Cypress.
CYPRESS_ADMIN_USERNAME: ct-admin
CYPRESS_ADMIN_PASSWORD: ct-admin
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Get Cache Directories
id: cache-dir
run: |
echo "composer-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
echo "npm-dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: |
vendor
web/core
web/modules/contrib
web/themes/contrib
web/profiles/contrib
${{ steps.cache-dir.outputs.composer-dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- uses: actions/cache@v4
with:
path: |
**/node_modules
${{ steps.cache-dir.outputs.npm-dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup DDEV
uses: ddev/github-action-setup-ddev@v1
with:
# We will start DDEV after setting the environment
autostart: false
- name: Get DDEV version
id: ddev_version
run: echo "ddev_version=$(ddev --version | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
- name: Cache Docker images
uses: ScribeMD/[email protected]
with:
key: ddev-images-${{ runner.os }}-${{ steps.ddev_version.outputs.ddev_version }}-${{ hashFiles('.ddev/config.yaml', '.ddev/docker-compose.cypress.yaml', '.ddev/docker-compose.redis.yaml') }}
# This disables the cache for PRs and tag events.
read-only: ${{ github.event_name == 'pull_request' || github.ref_type == 'tag' }}
- name: Set the platform.sh token
run: |
ddev config global --web-environment-add="PLATFORMSH_CLI_TOKEN=${{ secrets.PLATFORMSH_CLI_TOKEN }}"
ddev start
- name: Install the site
run: |
ddev composer install
ddev pull platform -y
- name: Run updates and Validate Config
id: validate_config
run: |
# Rebuild cache so that config cache is not obsolete
ddev drush cache:rebuild -y
# Identify set of configuration changes before running updatedb and store it in a text file.
# awk NF is used to filter blank lines.
ddev drush config:status --fields name --format list | awk NF > ${{ runner.temp }}/initial_config.txt
# Run updates and rebuild cache
ddev drush updatedb --yes
ddev drush cache:rebuild --yes
# Identify set of configuration changes after running updatedb and store it in a text file.
ddev drush config:status --fields name --format list | awk NF > ${{ runner.temp }}/updated_config.txt
# Compare the sorted files and write unique lines from the second list that are not present in the first list.
comm -13 ${{ runner.temp }}/initial_config.txt ${{ runner.temp }}/updated_config.txt > ${{ runner.temp }}/mismatched_config.txt
# If mismatched_config is not empty, it means we have missing config export. We store it in GITHUB_OUTPUT for the next steps.
if [ -s ${{ runner.temp }}/mismatched_config.txt ]; then
echo "Config export has differences"
cat ${{ runner.temp }}/mismatched_config.txt
# We are using EOF-based output as mismatched_config.txt may contain multiple lines
status_output=$(cat ${{ runner.temp }}/mismatched_config.txt)
echo "status_output<<EOF" >> $GITHUB_OUTPUT
echo "$status_output" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "Config has no differences"
echo "status_output=No differences between DB and sync directory" >> $GITHUB_OUTPUT
fi
- name: Add/Update PR Comment
uses: mshick/add-pr-comment@v2
with:
# This will add or update the comment if there are config differences, but will only update the comment on success.
# We do not want to add the comment when there are no config differences on the initial push.
update-only: ${{ contains(steps.validate_config.outputs.status_output, 'No differences') }}
message: |
${{ !contains(steps.validate_config.outputs.status_output, 'No differences') && '**Config export has differences**' || ' ' }}
```
${{ steps.validate_config.outputs.status_output }}
```
- name: Warn if Config Export is not clean
if: ${{ !contains(steps.validate_config.outputs.status_output, 'No differences') }}
run: |
echo "::warning::Config export has differences"
echo ${{ steps.validate_config.outputs.status_output }}
- name: Deploy the site
run: |
ddev drush deploy -y
- name: Build front-end
run: |
cd web/themes/custom/contribtracker
npm ci --prefer-offline --no-audit
gulp
- name: Run phpstan
run: ddev php ./vendor/bin/grumphp run --tasks=phpstan --no-interaction
- name: Test
run: |
ddev phpunit --testsuite unit
ddev phpunit --bootstrap=./vendor/weitzman/drupal-test-traits/src/bootstrap-fast.php --configuration ./phpunit.xml --testsuite existing-site
- name: Change admin password to make it easier for Cypress tests
run: ddev drush upwd "$CYPRESS_ADMIN_USERNAME" "$CYPRESS_ADMIN_PASSWORD"
- name: Cypress Test
run: ddev cypress-run
- name: Save Cypress recordings
if: always()
uses: actions/upload-artifact@v4
with:
name: cypress-recordings
path: |
web/themes/custom/contribtracker/cypress/screenshots
web/themes/custom/contribtracker/cypress/videos
retention-days: 3
deploy:
environment:
name: ${{ github.ref_name == 'main' && 'production' || 'feature' }}
needs:
- drupal_codequality
- drupal_test
runs-on: ubuntu-latest
# Dependabot PR's can't access secrets, so we can't deploy.
if: github.actor != 'dependabot[bot]'
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Deploy to platform.sh
uses: axelerant/platformsh-action@v1
with:
action: 'deploy'
project-id: "brbqplxd7ycq6"
cli-token: ${{ secrets.PLATFORMSH_CLI_TOKEN }}
force-push: true