refactor(_internal-setup-magento): replace bespoke cache with cache-magento stamp (#250)

Drop the actions/cache + create-project + cp pattern in favor of
running cache-magento with stamp:true directly against the work
directory. The PSEUDO_REPO_FOLDER staging directory is removed
entirely; create-project lands in `_ghamagento` and stays there.

To keep the cache lean, the workflow writes Magento's stock
.gitignore before `git init && git clean -fdx` so vendor/, var/,
generated/, and pub/static/ are stripped from the snapshot that
seeds the test fixture. The stamp cache then handles vendor/.

Adds `compute_matrix_latest` so setup-magento-extension runs
across the supported matrix (kind: latest) instead of being
hard-coded to 8.4 / composer 2.8 / 2.4.8-p3.
This commit is contained in:
Damien Retzinger
2026-05-09 16:16:26 -04:00
committed by GitHub
parent c78e635688
commit 0cbc4297b1
+125 -33
View File
@@ -20,8 +20,7 @@ on:
- "!(**/*.md)" - "!(**/*.md)"
env: env:
PSEUDO_REPO_FOLDER: ../magento_repo magento_folder: _ghamagento
magento_folder: ../magento2
MAGENTO_COMPOSER_REPO: "https://mirror.mage-os.org/" MAGENTO_COMPOSER_REPO: "https://mirror.mage-os.org/"
jobs: jobs:
@@ -38,6 +37,18 @@ jobs:
id: supported-version id: supported-version
- run: echo ${{ steps.supported-version.outputs.matrix }} - run: echo ${{ steps.supported-version.outputs.matrix }}
compute_matrix_latest:
if: "!startsWith(github.head_ref, 'release-please')"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.supported-version.outputs.matrix }}
steps:
- uses: actions/checkout@v6
- uses: ./supported-version
with:
kind: latest
id: supported-version
setup-magento-store: setup-magento-store:
needs: compute_matrix needs: compute_matrix
strategy: strategy:
@@ -47,51 +58,122 @@ jobs:
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- run: |
PSEUDO_STORE_FULL_PATH=$(realpath "${{ env.PSEUDO_REPO_FOLDER }}")
echo "PSEUDO_STORE_FULL_PATH=$PSEUDO_STORE_FULL_PATH" >> $GITHUB_ENV
name: Generate Full Pseudo Store Path
shell: bash
- name: Set PHP Version - name: Set PHP Version
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php }} php-version: ${{ matrix.php }}
tools: composer:v${{ matrix.composer }} tools: composer:v${{ matrix.composer }}
- uses: actions/cache@v5 - run: composer create-project --repository-url="${{ env.MAGENTO_COMPOSER_REPO }}" "${{ matrix.magento }}" "${{ env.magento_folder }}" --no-install
id: setup-magento-store-cache
with:
key: setup-magento-ci | ${{ runner.os }} | ${{ matrix.magento }}
path: ${{ env.PSEUDO_STORE_FULL_PATH }}
- run: composer create-project --repository-url="${{ env.MAGENTO_COMPOSER_REPO }}" "${{ matrix.magento }}" "${{ env.PSEUDO_REPO_FOLDER }}" --no-install
name: Create Store to simulate a real Magento store in a real repo. name: Create Store to simulate a real Magento store in a real repo.
if: steps.setup-magento-store-cache.outputs.cache-hit != 'true'
env: env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
- uses: ./fix-magento-install - uses: ./fix-magento-install
name: Fix Magento Out of Box Install Issues name: Fix Magento Out of Box Install Issues
with: with:
magento_directory: ${{ env.PSEUDO_REPO_FOLDER }} magento_directory: ${{ env.magento_folder }}
if: steps.setup-magento-store-cache.outputs.cache-hit != 'true'
env: env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
- run: composer update --no-install
working-directory: ${{ env.magento_folder }}
- uses: ./cache-magento
with:
composer_cache_key: ${{ matrix.magento }}
working-directory: ${{ env.magento_folder }}
stamp: true
- run: composer install - run: composer install
shell: bash shell: bash
working-directory: "${{ env.PSEUDO_REPO_FOLDER }}" working-directory: "${{ env.magento_folder }}"
if: steps.setup-magento-store-cache.outputs.cache-hit != 'true'
env: env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
- run: git init && git config user.email "you@example.com" && git config user.name "Your Name" && git add . && git commit -m "init" && git clean -fdx - name: Write Magento .gitignore so git clean strips vendor/generated/var from the cached tree
working-directory: "${{ env.PSEUDO_REPO_FOLDER }}" working-directory: "${{ env.magento_folder }}"
if: steps.setup-magento-store-cache.outputs.cache-hit != 'true'
- run: cp -R ${{ env.PSEUDO_REPO_FOLDER }} ${{ env.magento_folder }}
shell: bash shell: bash
run: |
cat > .gitignore <<'EOF'
/.buildpath
/.cache
/.metadata
/.project
/.settings
/.vscode
atlassian*
/nbproject
/robots.txt
/pub/robots.txt
/sitemap
/sitemap.xml
/pub/sitemap
/pub/sitemap.xml
/.idea
/.gitattributes
/app/config_sandbox
/app/etc/config.php
/app/etc/env.php
/app/code/Magento/TestModule*
/lib/internal/flex/uploader/.actionScriptProperties
/lib/internal/flex/uploader/.flexProperties
/lib/internal/flex/uploader/.project
/lib/internal/flex/uploader/.settings
/lib/internal/flex/varien/.actionScriptProperties
/lib/internal/flex/varien/.flexLibProperties
/lib/internal/flex/varien/.project
/lib/internal/flex/varien/.settings
/node_modules
/.grunt
/Gruntfile.js
/package.json
/.php_cs
/.php_cs.cache
/.php-cs-fixer.php
/.php-cs-fixer.cache
/grunt-config.json
/pub/media/*.*
!/pub/media/.htaccess
/pub/media/attribute/*
!/pub/media/attribute/.htaccess
/pub/media/analytics/*
/pub/media/catalog/*
!/pub/media/catalog/.htaccess
/pub/media/customer/*
!/pub/media/customer/.htaccess
/pub/media/downloadable/*
!/pub/media/downloadable/.htaccess
/pub/media/favicon/*
/pub/media/import/*
!/pub/media/import/.htaccess
/pub/media/logo/*
/pub/media/custom_options/*
!/pub/media/custom_options/.htaccess
/pub/media/theme/*
/pub/media/theme_customization/*
!/pub/media/theme_customization/.htaccess
/pub/media/wysiwyg/*
!/pub/media/wysiwyg/.htaccess
/pub/media/tmp/*
!/pub/media/tmp/.htaccess
/pub/media/captcha/*
/pub/media/sitemap/*
!/pub/media/sitemap/.htaccess
/pub/static/*
!/pub/static/.htaccess
/var/*
!/var/.htaccess
/vendor/*
!/vendor/.htaccess
/generated/*
!/generated/.htaccess
.DS_Store
EOF
- run: git init && git config user.email "you@example.com" && git config user.name "Your Name" && git add . && git commit -m "init" && git clean -fdx
working-directory: "${{ env.magento_folder }}"
- uses: ./setup-magento - uses: ./setup-magento
id: setup-magento id: setup-magento
@@ -101,10 +183,12 @@ jobs:
mode: store mode: store
working-directory: ${{ env.magento_folder }} working-directory: ${{ env.magento_folder }}
composer_auth: ${{ secrets.COMPOSER_AUTH }} composer_auth: ${{ secrets.COMPOSER_AUTH }}
- uses: ./cache-magento - uses: ./cache-magento
with: with:
composer_cache_key: '${{ matrix.magento }}' composer_cache_key: ${{ matrix.magento }}
working-directory: ${{ env.magento_folder }}
stamp: true
- run: composer install - run: composer install
name: Composer install name: Composer install
@@ -114,24 +198,32 @@ jobs:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
setup-magento-extension: setup-magento-extension:
if: "!startsWith(github.head_ref, 'release-please')" needs: compute_matrix_latest
strategy:
matrix: ${{ fromJSON(needs.compute_matrix_latest.outputs.matrix) }}
fail-fast: false
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: ./setup-magento - uses: ./setup-magento
id: setup-magento id: setup-magento
with: with:
php-version: 8.4 php-version: ${{ matrix.php }}
tools: composer:v2.8 tools: composer:v${{ matrix.composer }}
mode: extension mode: extension
magento_repository: ${{ env.MAGENTO_COMPOSER_REPO }} magento_repository: ${{ env.MAGENTO_COMPOSER_REPO }}
composer_auth: ${{ secrets.COMPOSER_AUTH }} composer_auth: ${{ secrets.COMPOSER_AUTH }}
magento_version: magento/project-community-edition:2.4.8-p3 magento_version: ${{ matrix.magento }}
- run: composer update --no-install
working-directory: ${{ steps.setup-magento.outputs.path }}
- uses: ./cache-magento - uses: ./cache-magento
with: with:
composer_cache_key: 'magento/project-community-edition:2.4.8-p3' composer_cache_key: ${{ matrix.magento }}
working-directory: ${{ steps.setup-magento.outputs.path }}
stamp: true
- run: composer install - run: composer install
name: Composer install name: Composer install