ci(phpunit): cache the installed database, key the cache on the Shopware version
plugin-checks / version-changelog (pull_request) Successful in 16s
plugin-checks / phpunit (pull_request) Failing after 27s
plugin-checks / package (pull_request) Successful in 59s

- resolve the latest 6.6.x from Packagist; cache key shopware-<version>-installed-v1
- cache the project plus a SQL dump of the installed shopware_test database; on a hit restore
  the dump instead of running system:install (~4.6 min)
- rename the step 'Install Shopware (once)' to 'Install Shopware'

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
haylanandClaude Bot committed 2026-10-04 01:01:21 +02:00
1 parent eb2a3172e5
commit 18844718d2
2 files changed
+66 -26

No files matched your search

+61 -23
View File
@@ -98,28 +98,41 @@ jobs:
- uses: actions/checkout@v4
with:
path: plugin-src
- name: Month stamp (refreshes the cached project monthly)
id: stamp
run: echo "month=$(date +%Y-%m)" >> "$GITHUB_OUTPUT"
# The project (incl. vendor/ and phpunit) does not depend on the plugin, so it is cached on its own.
- name: Restore prepared Shopware project
id: project
# The cache key follows the Shopware version: a new 6.6.x release changes the key, so the old
# project + database are never reused. Bump -v1 to force a refresh by hand.
- name: Resolve the latest Shopware 6.6 version
id: sw
run: |
VERSION=$(php -r '
$all = json_decode(file_get_contents("https://repo.packagist.org/p2/shopware/production.json"), true)["packages"]["shopware/production"];
$v = [];
foreach ($all as $p) { if (preg_match("/^6\.6\.\d+(\.\d+)*$/", $p["version"])) { $v[] = $p["version"]; } }
usort($v, "version_compare");
echo end($v);')
test -n "$VERSION" || { echo "::error::could not resolve the Shopware 6.6 version"; exit 1; }
echo "Shopware ${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
# Project (vendor/, phpunit, config) and the installed database as a SQL dump. Neither depends on the plugin.
- name: Restore Shopware project and database
id: shopware
uses: actions/cache/restore@v4
with:
path: shopware
key: shopware-6.6-prepared-${{ steps.stamp.outputs.month }}
- name: Create Shopware 6.6 project
if: steps.project.outputs.cache-hit != 'true'
path: |
shopware
!shopware/var/cache
!shopware/var/log
shopware-db.sql.gz
key: shopware-${{ steps.sw.outputs.version }}-installed-v1
- name: Create Shopware project
if: steps.shopware.outputs.cache-hit != 'true'
run: |
set -e
composer create-project shopware/production:6.6.* shopware --no-interaction --no-scripts
composer create-project "shopware/production:${{ steps.sw.outputs.version }}" shopware --no-interaction --no-scripts
composer require --dev phpunit/phpunit:^10 --no-interaction --no-scripts -d shopware
- name: Save prepared Shopware project
if: steps.project.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: shopware
key: shopware-6.6-prepared-${{ steps.stamp.outputs.month }}
- name: Ensure the MariaDB client
run: |
command -v mariadb-dump >/dev/null || command -v mysqldump >/dev/null && exit 0
(apt-get update -q && apt-get install -y -q --no-install-recommends mariadb-client) || apk add --no-cache mariadb-client
- name: Wait for the database
run: |
for i in $(seq 60); do
@@ -127,9 +140,39 @@ jobs:
sleep 2
done
echo "::error::database service did not come up"; exit 1
- name: Relax database durability (throwaway CI database, speeds up the migrations)
- name: Relax database durability (throwaway CI database, speeds up the install and the restore)
run: |
php -r '$p = new PDO("mysql:host=database;port=3306", "root", "root"); $p->exec("SET GLOBAL innodb_flush_log_at_trx_commit=0"); $p->exec("SET GLOBAL sync_binlog=0");'
# One install into shopware_test; the bootstrapper then sees an installed DB, skips its own install and
# only activates the plugin (tests/TestBootstrap.php forces plugin installation).
- name: Install Shopware
if: steps.shopware.outputs.cache-hit != 'true'
working-directory: shopware
run: bin/console system:install --basic-setup --create-database --force --no-interaction
- name: Dump the installed database
if: steps.shopware.outputs.cache-hit != 'true'
run: |
set -e
DUMP=$(command -v mariadb-dump || command -v mysqldump)
"$DUMP" -h database -P 3306 -u root -proot --skip-ssl --single-transaction --routines --triggers \
--databases shopware_test | gzip > shopware-db.sql.gz
ls -l shopware-db.sql.gz
- name: Save Shopware project and database
if: steps.shopware.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
shopware
!shopware/var/cache
!shopware/var/log
shopware-db.sql.gz
key: shopware-${{ steps.sw.outputs.version }}-installed-v1
- name: Restore the database from the cache
if: steps.shopware.outputs.cache-hit == 'true'
run: |
set -e
CLIENT=$(command -v mariadb || command -v mysql)
gunzip -c shopware-db.sql.gz | "$CLIENT" -h database -P 3306 -u root -proot --skip-ssl
- name: Resolve plugin name and install the plugin sources
run: |
# plugin directory name = short class name of extra.shopware-plugin-class
@@ -138,11 +181,6 @@ jobs:
echo "PLUGIN_NAME=${PLUGIN_NAME}" >> "$GITHUB_ENV"
rm -rf "shopware/custom/plugins/${PLUGIN_NAME}"
cp -r plugin-src "shopware/custom/plugins/${PLUGIN_NAME}"
# One install into shopware_test; the bootstrapper sees an installed DB, skips its own install and
# only activates the plugin (tests/TestBootstrap.php forces plugin installation).
- name: Install Shopware (once)
working-directory: shopware
run: bin/console system:install --basic-setup --create-database --force --no-interaction
- name: Run phpunit
working-directory: shopware
run: vendor/bin/phpunit -c "custom/plugins/${PLUGIN_NAME}/phpunit.xml"