forked from withanage/pkp-github-actions
-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
418 lines (363 loc) · 17.7 KB
/
action.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
name:
pkp-github-actions
inputs:
application:
required: false
branch:
required: false
dataset_branch:
required: false
node_version:
default: 20
plugin:
required: false
dataset_inject:
required: false
repository:
required: false
test:
default: false
required: false
upgrade:
default: false
required: false
upgrade_test:
required: false
reset_commit:
required: false
DEBUG_IN_TMATE:
required: false
DATASETS_ACCESS_KEY:
required: false
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
with:
repository: 'pkp/pkp-github-actions'
path: pkp-github-actions
ref: v1
- name: Set environment variables
run: |
echo "Set environment variables"
echo "APPLICATION=${{matrix.application || inputs.application || github.event.pull_request.head.repo.name || github.event.repository.name }}" >> $GITHUB_ENV
echo "TEST=${{matrix.database}}" >> $GITHUB_ENV
echo "NODE_VERSION=${{inputs.node_version}}" >> $GITHUB_ENV
echo "DBTYPE=${{matrix.database == 'pgsql' && 'PostgreSQL' || 'MySQLi'}}" >> $GITHUB_ENV
echo "DBHOST=localhost" >> $GITHUB_ENV
echo "DBNAME=${{matrix.application || inputs.application || github.event.pull_request.head.repo.name || github.event.repository.name }}-ci" >> $GITHUB_ENV
echo "DBUSERNAME=${{matrix.application || inputs.application || github.event.pull_request.head.repo.name || github.event.repository.name }}-ci" >> $GITHUB_ENV
echo "DBPASSWORD=${{matrix.application || inputs.application || github.event.pull_request.head.repo.name || github.event.repository.name }}-ci" >> $GITHUB_ENV
echo "FILESDIR=files" >> $GITHUB_ENV
echo "DATABASEDUMP=database.sql.gz" >> $GITHUB_ENV
echo "FILESDUMP=files.tar.gz" >> $GITHUB_ENV
echo "BASEURL=http://localhost" >> $GITHUB_ENV
echo "CYPRESS_DBTYPE=${{matrix.database=='pgsql' && 'PostgreSQL' || 'MySQLi'}}" >> $GITHUB_ENV
shell: bash
- name: Run apt update
run: |
sudo apt-get update
sudo apt-get upgrade
shell: bash
- name: Install postgres server
if: ${{matrix.database == 'pgsql'}}
run: |
echo "Install postgres server"
sudo apt install postgresql postgresql-contrib
sudo dpkg-reconfigure locales
PSQL_MAJOR_VERSION=$(psql --version | awk '{print $3}' | cut -d'.' -f1)
sudo sed -i -E 's\peer|scram-sha-256\trust\g' /etc/postgresql/${PSQL_MAJOR_VERSION}/main/pg_hba.conf
sudo systemctl restart postgresql
shell: bash
- name: Install mysql server
if: ${{matrix.database == 'mysql'}}
run: |
echo "Install mysql server"
sudo apt install -q -y mysql-server-8.0 mysql-client-8.0
sudo service mysql start
sudo mysqladmin -u root -p'root' password ''
shell: bash
- name: Install mariadb server
if: ${{matrix.database == 'mariadb'}}
uses: ankane/setup-mariadb@v1
with:
mariadb-version: "10.11"
- name: Install php environment for versions larger than 8.0
if: ${{matrix.php-version >= 8.0}}
uses: shivammathur/setup-php@v2
with:
php-version: ${{matrix.php-version}}
extensions: bcmath, bz2, curl, gd, intl, mbstring, mysql,mysqlnd, mysqli, opcache, pdo_mysql, pgsql, json,soap, xml, zip
coverage: xdebug
ini-values: assert.exception=1,zend.assertions=1
env:
update: true
- name: Install php environment for versions smaller than 8.0
if: ${{matrix.php-version < 8.0}}
uses: shivammathur/setup-php@v2
with:
php-version: ${{matrix.php-version}}
extensions: bcmath, bz2, curl, gd, intl, mbstring, mysql,mysqlnd, mysqli, opcache, pdo_mysql, pgsql, json,soap, xml, zip
coverage: xdebug
env:
update: true
- name: Install PKP application for push
if: ${{ github.event_name == 'push' && (inputs.repository == '' && (matrix.application || inputs.application) == '' && inputs.branch == '')}}
run: |
echo "Install PKP application for push"
git clone -b ${{ github.head_ref || github.ref_name }} https://github.com/${{ github.repository}} ~/${{ github.event.repository.name }} --depth 3
shell: bash
- name: Install PKP application for pull_request
if: ${{github.event_name == 'pull_request' && (inputs.repository == '' && (matrix.application || inputs.application) == '' && inputs.branch == '')}}
run: |
echo "Install PKP application for pull_request"
git clone -b ${{ github.event.pull_request.head.ref}} ${{ github.event.pull_request.head.repo.html_url}} ~/${{ github.event.pull_request.head.repo.name }} --depth 3
shell: bash
- name: Install PKP application for schedule
if: ${{ github.event_name == 'schedule' && (inputs.repository == '' && (matrix.application || inputs.application) == '' && inputs.branch == '')}}
run: |
echo "Install PKP application for schedule"
git clone -b ${{ inputs.dataset_branch}} https://github.com/${{ github.repository}} ~/${{ github.event.repository.name }} --depth 3
shell: bash
- name: pkp-lib for push and pull_request
if: ${{ inputs.repository != '' && inputs.branch != '' && (matrix.application != '' || inputs.application == '') }}
run: |
echo "pkp-lib for push and pull_request"
git clone -b ${{inputs.branch}} https://github.com/${{inputs.repository}}/${{matrix.application || inputs.application}} ~/${{matrix.application || inputs.application}} --depth 3
shell: bash
- name: Reset to a specific commit
if: ${{ inputs.reset_commit}}
run: |
echo "Reset to a specific commit"
cd ~/${{(matrix.application || inputs.application) || github.event.pull_request.head.repo.name || github.event.repository.name }}
git reset --hard ${{ inputs.reset_commit}}
echo ":bulb: Reset to commit ${{ inputs.reset_commit}}"
shell: bash
- name: Install Submodules
run: |
echo "Install Submodules"
cd ~/${{matrix.application || inputs.application || github.event.pull_request.head.repo.name || github.event.repository.name }}
git submodule update --init --recursive
shell: bash
- name : Checkout for pkp-lib for Push
if: ${{ github.event_name == 'push' && github.event.repository.name =='pkp-lib'}}
run: |
echo "Checkout for pkp-lib for Push"
cd ~/${{matrix.application || inputs.application}}/lib/pkp
git remote add ${{ github.event.repository.full_name}} https://github.com/${{ github.repository}}
git fetch ${{ github.event.repository.full_name}} ${{github.ref_name}}
git checkout ${{ github.event.repository.full_name}}/${{github.ref_name}}
shell: bash
- name: Checkout for pkp-lib for Pull_request
if: ${{ github.event_name == 'pull_request' && github.event.repository.name =='pkp-lib'}}
run: |
echo "Checkout for pkp-lib for Pull_request"
cd ~/${{matrix.application || inputs.application}}/lib/pkp
git remote add ${{ github.event.pull_request.head.repo.full_name}} ${{ github.event.pull_request.head.repo.html_url}}
git fetch ${{ github.event.pull_request.head.repo.full_name}} ${{ github.event.pull_request.head.ref}}
git checkout ${{ github.event.pull_request.head.repo.full_name}}/${{ github.event.pull_request.head.ref}}
shell: bash
- name: Install dependencies
run: |
echo "Install dependencies"
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/install-dependencies.sh
shell: bash
- name: Create additional directories
run: |
echo "Create additional directories"
mkdir -p ~/bin
shell: bash
- name: Install validation tools
if: ${{ matrix.validate == 'validate'}}
run: |
echo "Install validation tools"
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/install-validation-tools.sh
shell: bash
- name: Run validation
if: ${{ matrix.validate == 'validate'}}
id: validation
run: |
echo "Run Validation"
start_time=$(date -u +%s)
echo "status=:red_circle:" >> $GITHUB_OUTPUT
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/validate-xml.sh
${{ github.workspace }}/pkp-github-actions/.github/actions/buildjs.sh -n
${{ github.workspace }}/pkp-github-actions/.github/actions/validate-json.sh
npm run lint
${{ github.workspace }}/pkp-github-actions/.github/actions/run-document-validation.sh
duration=$(date -d@$(($(date -u +%s) - $start_time)) -u +%H:%M:%S)
echo "duration=$duration" >> $GITHUB_OUTPUT
echo "status=:white_check_mark:" >> $GITHUB_OUTPUT
shell: bash
- name: Run HTTP Server
run: |
echo "Run HTTP Server"
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/run-http-server.sh
shell: bash
- name: Prepare test environment
run: |
echo "Prepare test environment"
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/prepare-tests.sh
shell: bash
- name: Run data integration tests
id: data-integration-tests
if: ${{ matrix.test == 'test'}}
run: |
echo "Run data integration tests"
start_time=$(date -u +%s)
echo "status=:red_circle:" >> $GITHUB_OUTPUT
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/run-data-integration-tests.sh
duration=$(date -d@$(($(date -u +%s) - $start_time)) -u +%H:%M:%S)
echo "duration=$duration" >> $GITHUB_OUTPUT
echo "status=:white_check_mark:" >> $GITHUB_OUTPUT
shell: bash
- name: Dump database
if: ${{ matrix.test == 'test' }}
run: |
echo "dump database"
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/dump-database.sh
shell: bash
- name: Upload datasets (SAVE Build)
if: ${{matrix.SAVE_BUILD == 'save_build' && github.repository_owner == 'pkp' && inputs.dataset_branch != '' }}
run: |
echo "Upload datasets for saving build"
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/upload-to-datasets-repository.sh
shell: bash
env:
DATASET_BRANCH: ${{inputs.dataset_branch}}
DATASETS_ACCESS_KEY: ${{inputs.DATASETS_ACCESS_KEY}}
- name: Run pkp-lib integration tests
id: pkp-lib-and-plugin-integration-tests
if: ${{ matrix.test == 'test'}}
run: |
echo ": Run pkp-lib integration tests"
start_time=$(date -u +%s)
echo "status=:red_circle:" >> $GITHUB_OUTPUT
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/run-pkp-lib-and-plugin-integration-tests.sh
duration=$(date -d@$(($(date -u +%s) - $start_time)) -u +%H:%M:%S)
echo "duration=$duration" >> $GITHUB_OUTPUT
echo "status=:white_check_mark:" >> $GITHUB_OUTPUT
shell: bash
- name: Run unit tests
id: unit-test
if: ${{ matrix.test == 'test' }}
run: |
echo "Run unit tests"
start_time=$(date -u +%s)
echo "status=:red_circle:" >> $GITHUB_OUTPUT
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
${{ github.workspace }}/pkp-github-actions/.github/actions/run-unit-tests.sh -CcPpd
duration=$(date -d@$(($(date -u +%s) - $start_time)) -u +%H:%M:%S)
echo "duration=$duration" >> $GITHUB_OUTPUT
echo "status=:white_check_mark:" >> $GITHUB_OUTPUT
shell: bash
- name: Download datasets
if: ${{ (matrix.upgrade== 'upgrade' && matrix.test == 'test') || inputs.plugin == 'true'}}
run: |
echo "Download datasets "
cd ~/
if [ -d "datasets" ]; then
rm -rf datasets
fi
git clone --depth 1 https://github.com/pkp/datasets datasets
shell: bash
env:
DATABASEDUMP: database.sql.gz
FILESDUMP: files.tar.gz
APP_BRANCH: ${{inputs.dataset_branch|| inputs.branch}}
- name: Ingest datasets
if: ${{inputs.plugin == 'true' && inputs.dataset_inject == 'true' }}
run: |
echo "Ingest datasets for plugin"
cd ~/${{matrix.application}}
source ${{ github.workspace }}/pkp-github-actions/.github/actions/ingest_datasets.sh
shell: bash
env:
APP_BRANCH: ${{inputs.branch}}
DATASET_BRANCH: ${{inputs.branch}}
- name: Run plugin actions for push
if: ${{ github.event_name == 'push' && inputs.plugin == 'true'}}
run: source ${{ github.workspace }}/pkp-github-actions/.github/actions/run-plugin-actions.sh
shell: bash
env:
DATASET_BRANCH: ${{inputs.branch}}
APP_BRANCH: ${{inputs.branch}}
GITHUB_EVENT_HEAD_REF: ${{ github.head_ref || github.ref_name }}
GITHUB_EVENT_HEAD_REPO_HTML_URL: 'https://github.com/${{ github.repository}}'
GITHUB_EVENT_HEAD_REPO_NAME: ${{ github.event.repository.name }}
- name: Run plugin actions for pull request
if: ${{github.event_name == 'pull_request' && inputs.plugin == 'true'}}
run: source ${{ github.workspace }}/pkp-github-actions/.github/actions/run-plugin-actions.sh
shell: bash
env:
DATASET_BRANCH: ${{inputs.branch}}
APP_BRANCH: ${{inputs.branch}}
GITHUB_EVENT_HEAD_REF: ${{github.event.pull_request.head.ref}}
GITHUB_EVENT_HEAD_REPO_HTML_URL: ${{ github.event.pull_request.head.repo.html_url}}
GITHUB_EVENT_HEAD_REPO_NAME: ${{ github.event.pull_request.head.repo.name }}
- name: Run upgrade tests
id: upgrade
if: ${{ matrix.test == 'test' && matrix.upgrade== 'upgrade' && matrix.upgrade_test != '' && (matrix.database == 'pgsql' || matrix.database == 'mysql' ) }}
run: |
echo "Run upgrade tests"
start_time=$(date -u +%s)
cd ~/${{matrix.application || inputs.application || github.event.repository.name }}
IFS=',' read -ra DATASET_BRANCHES <<< "${{matrix.upgrade_test}}"
for DATASET_BRANCH in "${DATASET_BRANCHES[@]}"
do
if [[ ("$DATASET_BRANCH" == "3.1.0" || "$DATASET_BRANCH" == "3.1.1-2" || "$DATASET_BRANCH" == "3.1.2") && ("$APPLICATION" == "omp" ||"$APPLICATION" == "ops" ) ]]; then
echo $APLICATION does not have a $DATASET_BRANCH dataset
else
source ${{ github.workspace }}/pkp-github-actions/.github/actions/prepare-tests.sh
source ${{ github.workspace }}/pkp-github-actions/.github/actions/upgrade-pkp-application.sh
fi
done
duration=$(date -d@$(($(date -u +%s) - $start_time)) -u +%H:%M:%S)
echo "duration=$duration" >> $GITHUB_OUTPUT
echo "status=:white_check_mark:" >> $GITHUB_OUTPUT
env:
DATASET_BRANCH: ${DATASET_BRANCH}
APP_BRANCH: ${{inputs.dataset_branch}}
shell: bash
- name: Print summary
if: always()
run: |
echo "Print summary"
values=("ojs" "ops" "omp")
current_repo=${{github.event.pull_request.head.repo.name || github.event.repository.name}}
for value in "${values[@]}"; do
if [ "$value" == "$current_repo" ]; then
cd ~/$APPLICATION
{
echo "| OS |PHP| DB| Node | ${{steps.validation.outputs.status}} Validation |${{steps.data-integration-tests.outputs.status}} Cypress data| ${{steps.pkp-lib-and-plugin-integration-tests.outputs.status}} Cypress integration |${{steps.unit-test.outputs.status}} Unit test | ${{steps.upgrade.outputs.status}} Upgrade| "
echo "| ---| --- | ---- | --- | --- | --- | --- | --- | --- |"
echo "| :penguin: ${{runner.os}} ${{runner.arch}} $( lsb_release -i | cut -c 17-) $( lsb_release -c | cut -c 11-) $( lsb_release -r | cut -c 10-) | ${{matrix.php-version}} | ${{matrix.database}} | ${{inputs.node_version}} | ${{steps.validation.outputs.duration}} |${{steps.data-integration-tests.outputs.duration}} |${{steps.pkp-lib-and-plugin-integration-tests.outputs.duration}} | ${{steps.unit-test.outputs.duration}} | ${{steps.upgrade.outputs.duration}} |"
} >> $GITHUB_STEP_SUMMARY
fi
done
shell: bash
- uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-${{matrix.database }}-${{ matrix.php-version }}
path: ~/${{ matrix.application || inputs.application || github.event.repository.name }}/cypress/screenshots
if-no-files-found: ignore
overwrite: false
- uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{matrix.database }}-${{ matrix.php-version }}-http-access.log
path: ~/${{ matrix.application || inputs.application || github.event.repository.name }}/access.log
overwrite: false
- name: Setup tmate session by failure
if: ${{ failure() && inputs.DEBUG_IN_TMATE == 'true' }}
uses: mxschmitt/action-tmate@v3