-
Notifications
You must be signed in to change notification settings - Fork 28
194 lines (167 loc) · 5.97 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
##############################
#### AUTOGENERATED ####
#### DO NOT MODIFY! ####
##############################
# Workflow for PR checks in module repositories
name: CI
on:
# Start workflow on each pull request
pull_request:
concurrency:
# There should be only one in-progress run of this workflow at a time for a specific PR
group: ${{ github.event.number }}
# Cancel runs of this workflow that are currently in progess.
cancel-in-progress: true
jobs:
# Runs the unit test suite
unit-tests:
name: Run unit test suite
# Define plenty-used variables
env:
# CI variables
APP_ENV: testing
IS_JENKINS: true
PLENTY_ID_HASH: 1000
WORKSPACE: ${{ github.workspace }}
INC_DIR: ${{ github.workspace }}/pl/packages/plentymarkets/plugin-test-suite/tests/includes
TEST_SUITE_DIR: ${{ github.workspace }}/pl/packages/plentymarkets/plugin-test-suite
# Database variables
DB_HOST: "127.0.0.1"
DB_USERNAME: root
DB_PASSWORD: test
DB_DATABASE: mysql-test
# Synonym database variable names (only defined because of inconsistency within plenty code)
DB_USER: root
DB_PASS: test
DB_NAME: mysql-test
# AWS environment variables
AWS_REGION: eu-central-1
#STATUS FILE
STATUS_FILE: test.plugins.${{ matrix.php.version }}.status
strategy:
fail-fast: false
matrix:
php:
- version: "8.0"
required: true
- version: "8.2"
required: true
runs-on: ubuntu-latest
# Start containers with specific services that are needed to run the unit test suite.
# In this case we need mariadb and redis.
# The used versions match the ones used in production.
services:
mariadb:
# Uses a prewarmed db image here to speedup the migrations https://github.com/plentymarkets/prewarm-db
image: ghcr.io/plentymarkets/prewarm-db:stable7
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.PUBLIC_PAT_CICD4_PUBLIC }}
ports:
- 127.0.0.1:3306:3306
env:
MARIADB_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
MARIADB_DATABASE: ${{ env.DB_DATABASE }}
redis:
image: redis:4.0.8
ports:
- 127.0.0.1:6379:6379
steps:
- name: Cleanup Runner
uses: plentymarkets/github-runner-cleanup@main
- name: Checkout github-actions repository
uses: actions/checkout@v4
with:
repository: plentymarkets/github-actions
ref: main
token: ${{ secrets.PUBLIC_PAT_CICD4_PUBLIC }}
path: .tmp/github-actions
- name: Prepare PHP main code
uses: ./.tmp/github-actions/prepare_php/
with:
token: ${{ secrets.PUBLIC_PAT_CICD4_PUBLIC }}
php-version: ${{ matrix.php.version }}
branch-forced: stable7
- name: Build plugin api
working-directory: pl
run: |
composer dump-autoload
php artisan plugin:buildinterface --without-docs --target=./storage/plugin-interface
- name: Checkout plugin test suite
uses: actions/checkout@v4
with:
repository: "plentymarkets/plugin-test-suite"
token: ${{ secrets.PUBLIC_PAT_CICD4_PUBLIC }}
path: "pl/packages/plentymarkets/plugin-test-suite/"
ref: stable7
- name: Install test suite dependencies
working-directory: pl/packages/plentymarkets/plugin-test-suite
run: |
composer install
rm .env
touch .env
- name: Checkout IO branch
uses: actions/checkout@v4
with:
path: pl/packages/plentymarkets/plugin-test-suite/vendor/plentymarkets/plugin-io
- name: Run plugin migrations
working-directory: pl
run: php artisan plugin:install --database=mysql-test --env=testing
- name: Run tests
working-directory: pl/packages/plentymarkets/plugin-test-suite
run: vendor/bin/phpunit vendor/plentymarkets/plugin-io
- name: Set job status
if: always()
run: |
echo "${{ job.status }}" > "${RUNNER_TEMP}/${STATUS_FILE}"
# add "optional" if test is not required
if ! ${{ matrix.php.required }}; then
echo " optional" >> "${RUNNER_TEMP}/${STATUS_FILE}"
fi
- name: Upload matrix status artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: job-status-${{ matrix.test.id }}-php${{ matrix.php.version }}
path: ${{ runner.temp }}/${{ env.STATUS_FILE }}
retention-days: 1
collect-results:
# checks results of all previous jobs for failures
needs: [unit-tests]
name: Test overall status
runs-on: ubuntu-latest
if: always()
steps:
- uses: plentymarkets/github-runner-cleanup@main
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/job-status
pattern: job-status-*
merge-multiple: true
- name: Summarize jobs status
shell: bash
run: |
FILES=$(find "${{ runner.temp }}/job-status" -type f -name "test.*.status")
OVERALL_STATUS="success"
RED='\033[0;31m'
NC='\033[0m'
while IFS="" read -r FILE; do
FILENAME=$(basename "${FILE}")
STATUS=$(cat "$FILE" | xargs)
printf "${FILENAME}: "
if [[ "$STATUS" != "success"* ]]; then
printf "${RED}${STATUS}${NC}\n"
if [[ "$STATUS" != *"optional"* ]]; then
OVERALL_STATUS=$STATUS
fi
else
echo "${STATUS}"
fi
done <<< "$FILES"
if [[ "$OVERALL_STATUS" != "success" ]]; then
printf "\n${RED}At least one required job failed!${NC}\n"
exit 1
else
printf "\nAll required jobs were successful.\n"
fi