-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
319 lines (286 loc) · 10.9 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
name: "Setup Shopware"
description: "Install Shopware with specific versions in your CI"
author: "shopware AG"
branding:
color: "blue"
icon: "download"
inputs:
env:
description: "Environment for Shopware"
required: true
default: "test"
shopware-version:
description: "Shopware Version to use"
required: true
default: "v6.6.8.0"
shopware-repository:
description: The shopware repository to checkout
required: true
default: shopware/shopware
php-version:
description: "PHP Version to use"
required: true
default: "8.3"
php-extensions:
description: "PHP extensions to install"
required: true
default: "gd, xml, dom, curl, pdo, mysqli, mbstring, pdo_mysql, bcmath, pcov, zip"
composer-root-version:
description: "The COMPOSER_ROOT_VERSION that should be set"
required: false
default: ".auto"
install:
description: "Install Shopware"
required: true
default: "false"
install-locale:
description: "Locale to install"
required: true
default: "en-GB"
install-currency:
description: "Currency to install"
required: true
default: "EUR"
keep-composer-tools:
description: "Keep Shopware Composer tools (PHPStan, ECS, BC-Checker)"
required: true
default: "false"
mysql-version:
description: "MySQL Version to use"
required: true
default: "builtin"
node-version:
description: nodejs version to use
required: false
default: "20.x"
npm-version:
description: npm version to use
required: false
default: ""
install-admin:
description: Whether to install administration npm dependencies and prepare jest
required: false
default: ""
install-storefront:
description: Whether to install storefront npm dependencies
required: false
default: ""
path:
description: Relative path under $GITHUB_WORKSPACE to place the shopware repository
required: true
default: ""
runs:
using: "composite"
steps:
- name: Clone Shopware
uses: actions/checkout@v4
with:
repository: ${{ inputs.shopware-repository }}
ref: ${{ inputs.shopware-version }}
path: ${{ inputs.path }}
- name: Set COMPOSER_ROOT_VERSION
shell: bash
working-directory: ${{ inputs.path }}
run: |
if [[ "${{ inputs.composer-root-version }}" == ".auto" ]]; then
echo "COMPOSER_ROOT_VERSION=$(jq -r '.extra | .["branch-alias"] | .["dev-trunk"]' composer.json)" >> "$GITHUB_ENV"
else
echo "COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}" >> "$GITHUB_ENV"
fi
- name: Remove vendor-bin
if: inputs.keep-composer-tools == 'false'
shell: bash
working-directory: ${{ inputs.path }}
run: rm -rf vendor-bin
- name: Fix temporary PHPStan Failure
shell: bash
working-directory: ${{ inputs.path }}
run: |
if ! jq -e '.["require-dev"]["phpstan/phpdoc-parser"]' composer.json > /dev/null 2>&1; then
echo "phpstan/phpdoc-parser not found in require-dev, adding it..."
# Create a temporary file with the new content
jq '.["require-dev"]["phpstan/phpdoc-parser"] = "~1"' composer.json > composer.json.tmp
# Replace the original file
mv composer.json.tmp composer.json
fi
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
extensions: ${{ inputs.php-extensions }}
tools: symfony-cli
- name: Start Default MySQL
if: inputs.mysql-version == 'builtin'
shell: bash
run: |
sudo mv /var/lib/mysql /var/lib/mysql-old
sudo mkdir /var/lib/mysql
sudo mount -t tmpfs tmpfs /var/lib/mysql -o size=1G
sudo -u mysql mysqld --datadir=/var/lib/mysql --default-time-zone=SYSTEM --initialize-insecure
sudo systemctl start mysql
- name: Start External MySQL
if: inputs.mysql-version != 'builtin' && inputs.mysql-version != 'skip'
shell: bash
run: |
docker run \
--name mysql \
-p 3306:3306 \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
-e MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=yes \
--tmpfs /var/lib/mysql:rw,size=1G \
-d \
${{ inputs.mysql-version }}
- uses: "ramsey/composer-install@v3"
with:
custom-cache-key: ${{ runner.os }}-setup-shopware-composer-${{ inputs.php-version }}-${{ hashFiles('composer.json', 'custom/plugins/**/composer.json') }}
working-directory: ${{ inputs.path }}
- uses: actions/setup-node@v4
if: inputs.install-storefront || inputs.install-admin
with:
node-version: ${{ inputs.node-version }}
- name: Install npm version
if: inputs.npm-version
shell: bash
run: |
npm install -g npm@${{ inputs.npm-version }}
- name: Retrieve the cached "node_modules" directory (if present)
uses: actions/cache@v4
if: inputs.install-storefront
id: storefront-node-cache
with:
path: ${{ inputs.path || '.' }}/src/Storefront/Resources/app/storefront/node_modules
key: storefront-node-modules-${{ runner.os }}-${{ hashFiles(format('{0}/src/Storefront/Resources/app/storefront/package-lock.json', inputs.path || '.')) }}
- name: Install dependencies (if the cached directory was not found)
if: inputs.install-storefront && steps.storefront-node-cache.outputs.cache-hit != 'true'
working-directory: ${{ inputs.path }}
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true"
shell: bash
run: npm --prefix src/Storefront/Resources/app/storefront ci --no-audit --prefer-offline
- name: Retrieve the cached "node_modules" directory (if present)
uses: actions/cache@v4
if: inputs.install-admin
id: admin-node-cache
with:
path: ${{ inputs.path || '.' }}/src/Administration/Resources/app/administration/node_modules
key: admin-node-modules-${{ runner.os }}-${{ hashFiles(format('{0}/src/Administration/Resources/app/administration/package-lock.json', inputs.path || '.')) }}
- name: Install dependencies (if the cached directory was not found)
if: inputs.install-admin && steps.admin-node-cache.outputs.cache-hit != 'true'
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true"
shell: bash
working-directory: ${{ inputs.path }}
run: npm --prefix src/Administration/Resources/app/administration ci --no-audit --prefer-offline
- name: Prepare Jest environment
if: ${{ inputs.install-admin }}
shell: bash
working-directory: ${{ inputs.path || '.' }}/src/Administration/Resources/app/administration
run: npm run unit-setup --if-present
- name: Entity schema
if: ${{ inputs.install-admin }}
shell: bash
working-directory: ${{ inputs.path || '.' }}
run: |
composer run framework:schema:dump
composer run npm:admin run convert-entity-schema
- name: Setup Shopware Database URL
shell: bash
working-directory: ${{ inputs.path }}
run: |
echo "DATABASE_URL=mysql://[email protected]/shopware" >> "$GITHUB_ENV"
if: ${{ env.DATABASE_URL == '' }} # Don't override if already set
- name: Configure MySQL Client
if: inputs.mysql-version != 'builtin'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const os = require('os');
const uri = process.env.DATABASE_URL;
const regex = /^mysql:\/\/(?<user>[^:]+)(:(?<password>[^@]+))?@(?<host>[^:\/]+)(:(?<port>\d+))?(\/(?<database>[^\?]+))?/;
const match = uri.match(regex);
if (!match || !match.groups) {
console.error("DATABASE_URL is invalid!");
process.exit(1);
}
const { user, password, host, port, database } = match.groups;
const myFileContent = [
"[client]",
`host=${host}`,
`user=${user}`,
password ? `password=${password}` : null,
port ? `port=${port}` : null,
database ? `database=${database}` : null,
].filter(Boolean).join("\n");
fs.writeFileSync(`${os.homedir()}/.my.cnf`, myFileContent);
- name: Wait for MySQL
if: inputs.mysql-version != 'builtin' && inputs.mysql-version != 'skip'
shell: bash
run: |
if docker exec mysql mariadb --version; then
while ! docker exec mysql mariadb-admin ping -h localhost --silent; do
sleep 1
done
else
while ! docker exec mysql mysqladmin ping -h localhost --silent; do
sleep 1
done
fi
- name: Setup Shopware Environment Variables
shell: bash
working-directory: ${{ inputs.path }}
run: |
echo "APP_ENV=${{ inputs.env }}" >> "$GITHUB_ENV"
echo "APP_SECRET=def00000bb5acb32b54ff8ee130270586eec0e878f7337dc7a837acc31d3ff00f93a56b595448b4b29664847dd51991b3314ff65aeeeb761a133b0ec0e070433bff08e48" >> "$GITHUB_ENV"
echo "APP_URL=http://localhost:8000" >> "$GITHUB_ENV"
- name: Configure HMAC JWT
shell: bash
working-directory: ${{ inputs.path }}
run: |
yq -n '.shopware.api.jwt_key.use_app_secret = true' | tee config/packages/zz-shopware.yaml
if: ${{ hashFiles(format('{0}/src/Core/Framework/Api/OAuth/JWTConfigurationFactory.php', (inputs.path || '.' ))) != '' }}
- name: Install Shopware
if: inputs.install == 'true'
shell: bash
working-directory: ${{ inputs.path }}
run: |
composer run init:db -- --shop-locale=${{ inputs.install-locale }} --shop-currency=${{ inputs.install-currency }}
- name: Build JS Admin
if: inputs.install-admin == 'true'
shell: bash
working-directory: ${{ inputs.path }}
run: |
composer run build:js:admin
- name: Build JS Storefront
if: inputs.install-storefront == 'true'
shell: bash
working-directory: ${{ inputs.path }}
run: |
composer run build:js:storefront
- name: Copy assets
if: inputs.install-storefront == 'true' || inputs.install-admin == 'true'
shell: bash
working-directory: ${{ inputs.path }}
run: |
bin/console assets:install
- name: Assign default Storefront theme to all sales channels
if: inputs.install-storefront == 'true'
shell: bash
working-directory: ${{ inputs.path }}
run: |
if bin/console theme:change --help | egrep -q '^\s+--sync'; then
bin/console theme:change --sync --all Storefront
else
bin/console theme:change --all Storefront
fi
- name: Start Webserver
if: inputs.install == 'true'
shell: bash
working-directory: ${{ inputs.path }}
env:
SYMFONY_DAEMON: "1"
SYMFONY_NO_TLS: "1"
SYMFONY_ALLOW_HTTP: "1"
SYMFONY_PORT: "8000"
SYMFONY_ALLOW_ALL_IP: "1"
run: symfony server:start