feat: plugin skeleton for Shopware 6.6 and 6.7 with CI and release pipeline
- composer.json (MIT, shopware/core ~6.6.0 || ~6.7.0, PHP ^8.2), plugin class, placeholder icon - PR checks and release workflow taken over from AeonDumpManager; phpunit runs as a 6.6/6.7 matrix - CHANGELOG, LICENSE, README, CLAUDE.md, smoke test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fb6bdf6e8d
commit
be549d4a51
21 files changed
+997
-48
No files matched your search
@@ -0,0 +1,35 @@
|
||||
name: package-extension
|
||||
description: >-
|
||||
Package the Shopware extension with shopware-cli (builds admin/storefront assets), validate the
|
||||
zip and assert it contains the built JS. Shared by the PR checks and the release workflow.
|
||||
Must run in the ghcr.io/shopware/shopware-cli image, after actions/checkout.
|
||||
|
||||
inputs:
|
||||
filename:
|
||||
description: Name of the zip written to .build/
|
||||
default: package.zip
|
||||
build:
|
||||
description: "'false' skips packaging (a prebuilt zip is already in .build/) and only validates it"
|
||||
default: 'true'
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- uses: actions/cache@v4
|
||||
if: inputs.build == 'true'
|
||||
with:
|
||||
path: |
|
||||
~/.npm
|
||||
~/.cache/shopware-cli
|
||||
key: swcli-${{ runner.os }}-${{ hashFiles('composer.json', 'src/Resources/app/**/package*.json') }}
|
||||
restore-keys: swcli-${{ runner.os }}-
|
||||
- name: Package extension
|
||||
if: inputs.build == 'true'
|
||||
shell: bash
|
||||
run: shopware-cli extension package . --output-directory .build --filename "${{ inputs.filename }}" --git-commit "$GITHUB_SHA"
|
||||
- name: Validate packaged zip
|
||||
shell: bash
|
||||
run: shopware-cli extension validate ".build/${{ inputs.filename }}"
|
||||
- name: Assert built JS is in the zip
|
||||
shell: bash
|
||||
run: scripts/ci/assert-built-assets.sh ".build/${{ inputs.filename }}"
|
||||
@@ -0,0 +1,195 @@
|
||||
name: plugin-checks
|
||||
|
||||
# Plugin-agnostic: nothing below names this plugin. Name, version and paths come from composer.json.
|
||||
# shopware-cli runs from its official Docker image, intentionally unpinned (latest); a red build
|
||||
# after a CLI release means fix the config.
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A new push to the PR cancels the superseded run.
|
||||
concurrency:
|
||||
group: plugin-checks-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
# Every PR into main must bump the version and document it in CHANGELOG.md.
|
||||
version-changelog:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# The version must be higher than the latest *published release* (not just higher than main), so main can
|
||||
# carry a version whose release failed or was withdrawn without blocking the next PR.
|
||||
- name: Check version is unreleased and changelog entry exists
|
||||
env:
|
||||
TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||
run: |
|
||||
set -e
|
||||
PR_VERSION=$(grep -m1 '"version"' composer.json | sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')
|
||||
LATEST=$(curl -sf -H "Authorization: token ${TOKEN}" "${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases?limit=100" \
|
||||
| jq -r '.[].tag_name' | sed 's/^v//' | sort -V | tail -n1)
|
||||
LATEST="${LATEST:-0.0.0}"
|
||||
|
||||
echo "latest release: $LATEST"
|
||||
echo "PR version: $PR_VERSION"
|
||||
|
||||
if [ "$PR_VERSION" = "$LATEST" ] || [ "$(printf '%s\n%s\n' "$LATEST" "$PR_VERSION" | sort -V | tail -n1)" != "$PR_VERSION" ]; then
|
||||
echo "::error::composer.json version ($PR_VERSION) is not greater than the latest release ($LATEST)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -qF "## [$PR_VERSION]" CHANGELOG.md; then
|
||||
echo "::error::CHANGELOG.md is missing a '## [$PR_VERSION]' heading"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "OK: $PR_VERSION is unreleased and documented in CHANGELOG.md"
|
||||
|
||||
# Packages the extension (builds admin/storefront assets) and validates the resulting zip,
|
||||
# which is the artifact that ships. A separate directory validate would only repeat these checks.
|
||||
package:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/shopware/shopware-cli:latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: ./.gitea/actions/package
|
||||
# The release workflow reuses this tested zip when main ends up with the same tree
|
||||
# (it falls back to packaging again otherwise).
|
||||
- name: Tree hash of the packaged commit
|
||||
id: tree
|
||||
run: echo "hash=$(git rev-parse "${GITHUB_SHA}^{tree}")" >> "$GITHUB_OUTPUT"
|
||||
- name: Save tested zip for the release
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: .build/package.zip
|
||||
key: plugin-zip-${{ steps.tree.outputs.hash }}
|
||||
|
||||
# One run per supported Shopware minor (keep in sync with require.shopware/core in composer.json).
|
||||
phpunit:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
shopware: ['6.6', '6.7']
|
||||
# Same image as above: it already ships PHP, Composer and Node, so no apt install.
|
||||
container:
|
||||
image: ghcr.io/shopware/shopware-cli:latest
|
||||
services:
|
||||
database:
|
||||
# Shopware 6.6 and 6.7 both support MariaDB 10.11; 11.4 broke 6.6's own migrations.
|
||||
image: mariadb:10.11
|
||||
env:
|
||||
MARIADB_ROOT_PASSWORD: root
|
||||
env:
|
||||
# Already the *_test name: Shopware's TestBootstrapper would otherwise append _test and run every migration a second time.
|
||||
DATABASE_URL: mysql://root:root@database:3306/shopware_test
|
||||
APP_ENV: test
|
||||
APP_URL: http://localhost
|
||||
APP_SECRET: ci-secret-not-for-production
|
||||
INSTANCE_ID: ci
|
||||
COMPOSER_MEMORY_LIMIT: '-1'
|
||||
COMPOSER_ALLOW_SUPERUSER: '1'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
path: plugin-src
|
||||
# The cache key follows the Shopware version: a new release inside the plugin's supported range changes
|
||||
# the key, so the old project + database are never reused. Bump -v1 to force a refresh by hand.
|
||||
- name: Resolve the latest Shopware Version
|
||||
id: sw
|
||||
run: |
|
||||
set -e
|
||||
# The matrix minor (e.g. ~6.6.0) decides which versions are acceptable;
|
||||
# Composer lists the matching ones newest first, the first stable one is the latest.
|
||||
CONSTRAINT="~${{ matrix.shopware }}.0"
|
||||
VERSION=$(composer show shopware/core "$CONSTRAINT" --all --format=json --no-interaction 2>/dev/null \
|
||||
| php -r '$d = json_decode(stream_get_contents(STDIN), true); foreach ($d["versions"] as $v) { if (preg_match("/^v?\d+(\.\d+)+$/", $v)) { echo ltrim($v, "v"); exit; } }')
|
||||
test -n "$VERSION" || { echo "::error::could not resolve a Shopware version for ${CONSTRAINT}"; exit 1; }
|
||||
echo "Shopware ${VERSION} (constraint ${CONSTRAINT})"
|
||||
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||
echo "constraint=${CONSTRAINT}" >> "$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
|
||||
!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
|
||||
# shopware/production pins one exact core version and is not tagged for every core patch
|
||||
# (e.g. core 6.6.10.31, template only up to 6.6.10.30): take the newest template inside the
|
||||
# constraint, then require the resolved core version on top of it.
|
||||
composer create-project "shopware/production:${{ steps.sw.outputs.constraint }}" shopware --no-interaction --no-scripts --no-install
|
||||
composer require "shopware/core:${{ steps.sw.outputs.version }}" --no-update -d shopware
|
||||
composer require --dev phpunit/phpunit:^10 --no-update -d shopware
|
||||
composer update -W --no-interaction --no-scripts -d shopware
|
||||
- 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
|
||||
(echo > /dev/tcp/database/3306) 2>/dev/null && exit 0
|
||||
sleep 2
|
||||
done
|
||||
echo "::error::database service did not come up"; exit 1
|
||||
- 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
|
||||
CLASS=$(php -r 'echo json_decode(file_get_contents("plugin-src/composer.json"), true)["extra"]["shopware-plugin-class"];')
|
||||
PLUGIN_NAME="${CLASS##*\\}"
|
||||
echo "PLUGIN_NAME=${PLUGIN_NAME}" >> "$GITHUB_ENV"
|
||||
rm -rf "shopware/custom/plugins/${PLUGIN_NAME}"
|
||||
cp -r plugin-src "shopware/custom/plugins/${PLUGIN_NAME}"
|
||||
- name: Run phpunit
|
||||
working-directory: shopware
|
||||
run: vendor/bin/phpunit -c "custom/plugins/${PLUGIN_NAME}/phpunit.xml"
|
||||
@@ -0,0 +1,154 @@
|
||||
name: release
|
||||
|
||||
# Plugin-agnostic: owner, repo, host, package name and version come from the `github` context
|
||||
# and composer.json. shopware-cli runs from its official Docker image, intentionally unpinned (latest).
|
||||
# RELEASE_TOKEN is the single token used for releases, assets and the Composer registry.
|
||||
#
|
||||
# Every step is idempotent (release/asset reuse, registry 409 = already published), so a failed run can
|
||||
# simply be re-run and picks up where it stopped. There is deliberately no "tag exists -> skip" guard:
|
||||
# it made a half-finished release (tag + release but no registry package) impossible to heal.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
# Never run two releases at once; a second push waits instead of racing on the tag.
|
||||
concurrency:
|
||||
group: release
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/shopware/shopware-cli:latest
|
||||
steps:
|
||||
- name: Ensure helper tools (jq, curl, unzip, zip, git)
|
||||
run: |
|
||||
command -v jq >/dev/null && command -v curl >/dev/null && command -v unzip >/dev/null && command -v zip >/dev/null && command -v git >/dev/null && exit 0
|
||||
(apt-get update -q && apt-get install -y -q --no-install-recommends jq curl unzip zip git) || apk add --no-cache jq curl unzip zip git
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.RELEASE_TOKEN }}
|
||||
|
||||
- name: Determine version, tag and file names
|
||||
id: meta
|
||||
run: |
|
||||
set -e
|
||||
VERSION=$(jq -r .version composer.json)
|
||||
PACKAGE_NAME=$(jq -r .name composer.json)
|
||||
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||
TAG="v${VERSION}"
|
||||
{
|
||||
echo "version=${VERSION}"
|
||||
echo "package_name=${PACKAGE_NAME}"
|
||||
echo "tag=${TAG}"
|
||||
echo "zip=${REPO_NAME}-${TAG}.zip"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Reuse the zip the PR workflow already built and tested for this exact tree.
|
||||
- name: Tree hash of this commit
|
||||
id: tree
|
||||
run: echo "hash=$(git rev-parse "${GITHUB_SHA}^{tree}")" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Restore the tested zip from the PR run
|
||||
id: prebuilt
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: .build/package.zip
|
||||
key: plugin-zip-${{ steps.tree.outputs.hash }}
|
||||
|
||||
- name: Name the prebuilt zip
|
||||
if: steps.prebuilt.outputs.cache-hit == 'true'
|
||||
run: mv .build/package.zip ".build/${{ steps.meta.outputs.zip }}"
|
||||
|
||||
# Packages only on a cache miss; always validates and asserts what ships (guards a bad cache entry).
|
||||
- uses: ./.gitea/actions/package
|
||||
with:
|
||||
filename: ${{ steps.meta.outputs.zip }}
|
||||
build: ${{ steps.prebuilt.outputs.cache-hit != 'true' }}
|
||||
|
||||
- name: Extract changelog section
|
||||
run: |
|
||||
awk -v ver="${{ steps.meta.outputs.version }}" '
|
||||
BEGIN { found=0 }
|
||||
/^## \[/ {
|
||||
if (found) exit
|
||||
if ($0 ~ "\\[" ver "\\]") { found=1; next }
|
||||
}
|
||||
found { print }
|
||||
' CHANGELOG.md > release-notes.md
|
||||
cat release-notes.md
|
||||
|
||||
- name: Create Gitea release (creates the tag) and upload the zip
|
||||
env:
|
||||
TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||
run: |
|
||||
set -e
|
||||
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
TAG="${{ steps.meta.outputs.tag }}"
|
||||
ZIP="${{ steps.meta.outputs.zip }}"
|
||||
CODE=$(curl -s -o /tmp/release.json -w "%{http_code}" -H "Authorization: token ${TOKEN}" "${API}/releases/tags/${TAG}")
|
||||
if [ "$CODE" = "200" ]; then
|
||||
echo "Release ${TAG} already exists, reusing it."
|
||||
else
|
||||
BODY=$(jq -n --arg tag "$TAG" --arg sha "$GITHUB_SHA" --rawfile notes release-notes.md \
|
||||
'{tag_name:$tag, target_commitish:$sha, name:$tag, body:$notes}')
|
||||
curl -sf -H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" -d "$BODY" "${API}/releases" > /tmp/release.json
|
||||
fi
|
||||
RELEASE_ID=$(jq -r .id /tmp/release.json)
|
||||
echo "release id: ${RELEASE_ID}"
|
||||
if jq -e --arg n "$ZIP" '.assets[]? | select(.name == $n)' /tmp/release.json > /dev/null; then
|
||||
echo "Asset ${ZIP} already uploaded."
|
||||
else
|
||||
curl -sf -H "Authorization: token ${TOKEN}" -F "attachment=@.build/${ZIP}" \
|
||||
"${API}/releases/${RELEASE_ID}/assets?name=${ZIP}" > /dev/null
|
||||
fi
|
||||
|
||||
# Gitea's Composer registry needs composer.json at the zip root, but shopware-cli zips wrap
|
||||
# everything in one top-level folder (the registry answers 400 "composer.json file is missing").
|
||||
# Same prebuilt content, repacked root-level.
|
||||
- name: Repack the zip for the Composer registry
|
||||
run: |
|
||||
set -e
|
||||
rm -rf /tmp/repack && mkdir /tmp/repack
|
||||
unzip -q ".build/${{ steps.meta.outputs.zip }}" -d /tmp/repack
|
||||
if [ -f /tmp/repack/composer.json ]; then
|
||||
ROOT=/tmp/repack
|
||||
else
|
||||
ROOT=$(find /tmp/repack -mindepth 1 -maxdepth 1 -type d | head -1)
|
||||
fi
|
||||
test -f "$ROOT/composer.json" || { echo "::error::no composer.json found in the packaged zip"; exit 1; }
|
||||
OUT="$PWD/.build/composer-${{ steps.meta.outputs.zip }}"
|
||||
# explicit file list with the leading "./" stripped, so entries are stored as "composer.json", "src/..."
|
||||
(cd "$ROOT" && find . -mindepth 1 | sed 's|^\./||' | zip -q "$OUT" -@)
|
||||
unzip -l "$OUT" | grep -E ' composer\.json$' > /dev/null || { echo "::error::repacked zip has no root-level composer.json"; exit 1; }
|
||||
echo "repacked: $OUT"
|
||||
|
||||
- name: Publish to the Composer registry
|
||||
run: |
|
||||
STATUS=$(curl -s -o /tmp/composer-publish.log -w "%{http_code}" \
|
||||
-u "${GITHUB_REPOSITORY_OWNER}:${{ secrets.RELEASE_TOKEN }}" \
|
||||
-T ".build/composer-${{ steps.meta.outputs.zip }}" \
|
||||
"${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/composer")
|
||||
cat /tmp/composer-publish.log
|
||||
if [ "$STATUS" != "201" ] && [ "$STATUS" != "409" ]; then
|
||||
echo "Unexpected HTTP status $STATUS publishing to the Composer registry"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Link Composer package to this repository
|
||||
run: |
|
||||
ENCODED_NAME=$(printf '%s' "${{ steps.meta.outputs.package_name }}" | sed 's#/#%2F#g')
|
||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u "${GITHUB_REPOSITORY_OWNER}:${{ secrets.RELEASE_TOKEN }}" -X POST \
|
||||
"${GITHUB_SERVER_URL}/api/v1/packages/${GITHUB_REPOSITORY_OWNER}/composer/${ENCODED_NAME}/-/link/${GITHUB_REPOSITORY#*/}")
|
||||
echo "link status: $STATUS"
|
||||
if [ "$STATUS" != "201" ] && [ "$STATUS" != "400" ]; then
|
||||
echo "::warning::Unexpected status linking the Composer package to this repository (HTTP $STATUS) - not fatal, release already published"
|
||||
fi
|
||||
Reference in new issue
Block a user