From 592303d004b1a92bc6835385d28e222e98d69fb5 Mon Sep 17 00:00:00 2001 From: tinect Date: Sun, 10 Dec 2023 20:44:07 +0100 Subject: [PATCH] feat: build multiple php versions per shopware version --- .github/workflows/build-docker-images.yaml | 13 ++++- alpine/Dockerfile.base | 2 +- bin/generate-matrix.js | 68 ++++++++++++---------- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-docker-images.yaml b/.github/workflows/build-docker-images.yaml index 36331dd..a81357c 100644 --- a/.github/workflows/build-docker-images.yaml +++ b/.github/workflows/build-docker-images.yaml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.1', '8.2'] + php-version: ['8.1', '8.2', '8.3'] flavour: ['alpine', 'bullseye'] steps: @@ -124,13 +124,20 @@ jobs: [ "${shopware_version_tag}" == "" ] && exit 1 - tag="${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}-${{ matrix.flavour }}" + tag="${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}-${{ matrix.php-version }}-${{ matrix.flavour }}" if [[ "${{ matrix.flavour }}" == "alpine" ]]; then - tag="$tag, ${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}" + tag="$tag, ${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}-${{ matrix.php-version }}" + + if [[ "${{ matrix.is-main }}" == "true" ]]; then + tag="$tag, ${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}" + fi + elif [[ "${{ matrix.is-main }}" == "true" ]]; then + tag="$tag, ${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}-${{ matrix.flavour }}" fi echo "Shopware version ${{ matrix.shopware-version }}" + echo "PHP version ${{ matrix.php-version }}" echo "Image Tag: ${tag}" echo "tag=${tag}" >> $GITHUB_OUTPUT diff --git a/alpine/Dockerfile.base b/alpine/Dockerfile.base index 7cb1b74..77d4a8b 100644 --- a/alpine/Dockerfile.base +++ b/alpine/Dockerfile.base @@ -1,5 +1,5 @@ ARG PHP_VERSION -FROM php:${PHP_VERSION}-cli-alpine3.16 +FROM php:${PHP_VERSION}-cli-alpine3.18 COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/ diff --git a/bin/generate-matrix.js b/bin/generate-matrix.js index 3157d22..b6184aa 100644 --- a/bin/generate-matrix.js +++ b/bin/generate-matrix.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -const FLAVORS = [ +const FLAVOURS = [ "alpine", "bullseye", ]; @@ -10,19 +10,16 @@ const FLAVORS = [ */ const HARDCODED_MATRIX = [ { - "shopware-version": "6.4", - "php-version": "8.1", - "template": "https://github.com/shopware/shopware", + "shopwareVersion": "6.4", + "phpVersions": ["8.1", "8.2"], }, { - "shopware-version": "6.5.x", - "php-version": "8.1", - "template": "https://github.com/shopware/shopware", + "shopwareVersion": "6.5.x", + "phpVersions": ["8.1", "8.2", "8.3"], }, { - "shopware-version": "trunk", - "php-version": "8.2", - "template": "https://github.com/shopware/shopware", + "shopwareVersion": "trunk", + "phpVersions": ["8.2", "8.3"], }, ]; @@ -50,16 +47,32 @@ const parseMinorVersion = (version) => { } const getTemplate = (version) => { - const minor = parseMinorVersion(version); + try { + const minor = parseMinorVersion(version); - // For everything below 6.5, we need the shopware/production template. - if (minor <= 4) { - return "https://github.com/shopware/production"; + // For everything below 6.5, we need the shopware/production template. + if (minor <= 4) { + return "https://github.com/shopware/production"; + } + } catch (e) { + // Ignore } return "https://github.com/shopware/shopware"; } +function addMatrixEntries(matrix, shopwareVersion, phpVersion, isMain) { + FLAVOURS.forEach((flavour) => { + matrix.push({ + "shopware-version": shopwareVersion, + "php-version": phpVersion, + "flavour": flavour, + "template": getTemplate(shopwareVersion), + "is-main": isMain, + }); + }); +} + async function main() { const minPHPVersion = await loadMinPHPVersion(); @@ -84,22 +97,17 @@ async function main() { } - let matrix = []; + if (Object.entries(shopwareMinorVersions).length === 0) { + throw new Error("No shopwareMinorVersions entries generated."); + } - for (const [_, line] of Object.entries(shopwareMinorVersions)) { - const minPhpVersions = line.phpVersions.filter((phpVersion) => phpVersion >= minPHPVersion); + let matrix = []; - if (minPhpVersions.length === 0) { - continue; - } + for (const [_, entry] of Object.entries(shopwareMinorVersions)) { + const supportedPhpVersions = entry.phpVersions.filter((phpVersion) => phpVersion >= minPHPVersion); - FLAVORS.forEach((flavor) => { - matrix.push({ - "shopware-version": 'v' + line.shopwareVersion, - "php-version": minPhpVersions[0], - "flavour": flavor, - "template": getTemplate(line.shopwareVersion), - }); + supportedPhpVersions.forEach((phpVersion, i) => { + addMatrixEntries(matrix, 'v' + entry.shopwareVersion, phpVersion, i === supportedPhpVersions.length - 1); }); } @@ -108,10 +116,10 @@ async function main() { } HARDCODED_MATRIX.forEach((entry) => { - FLAVORS.forEach((flavor) => { - entry.flavour = flavor; + const supportedPhpVersions = entry.phpVersions.filter((phpVersion) => phpVersion >= minPHPVersion); - matrix.push(entry); + supportedPhpVersions.forEach((phpVersion, i) => { + addMatrixEntries(matrix, entry.shopwareVersion, phpVersion, i === supportedPhpVersions.length - 1); }); });