Skip to content

Instantly share code, notes, and snippets.

@michielgerritsen
Created May 1, 2024 08:55
Show Gist options
  • Save michielgerritsen/f82f9a7650fe175e66c2d4d8211fcd46 to your computer and use it in GitHub Desktop.
Save michielgerritsen/f82f9a7650fe175e66c2d4d8211fcd46 to your computer and use it in GitHub Desktop.
Create patch helper files

What is this?

This file allows you to create a GitHub Actions workflow that can be triggered manually. When triggered, this workflow will run the Ampersand Patch Helper for you. The files generated are compatible with the Magento 2 Upgrade GUI.

It will save you the hassle of having 2 vendor folders (and PHPStorm indexing both 🫨), installing the Ampersand Patch Helper locally, and executing all related commands.

How to install?

  • Place the create-patch-helper-files.yml in your .github/workflows folder.
  • Commit the file to your repository.
  • When this file becomes available in your master/main branch, you are done!

How to use?

  1. On your local machine, execute the Magento update through Composer. Update whatever is required (extensions, themes, etc). Push this branch to GitHub.
  2. Open your repository and go to Actions > Create patch helper files. Click Run Workflow and select your new branch.
image 3. A new job is added to the queue (you might need to refresh to see it). Wait until the job finishes. 4. When the job is done, open the summary. Here you can download the artifact that contains your files. image

Now you have 2 options:

  1. Extract the files and inspect the contents of patch-helper-output.txt.
  2. Extract the files and place them in your project. Open Magento 2 Upgrade GUI and point it to your project. You might also need to extract the vendor.tar.gz and vendor_orig.tar.gz files too.
name: "Create patch helper files"
on:
workflow_dispatch:
inputs:
defaultBranch:
description: 'Select the branch that is used as a base (old version)'
required: true
default: 'main'
phpVersion:
description: 'Select the PHP version to use'
required: true
default: '8.2'
jobs:
create-patch-helper-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: 'feature/upgrade-2.4.7' #${{ github.event.workflow_run.head_branch }}
path: 'new-version'
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.defaultBranch }}
path: 'old-version'
- uses: actions/checkout@v4
with:
repository: 'AmpersandHQ/ampersand-magento2-upgrade-patch-helper'
path: 'ampersand-patch-helper'
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ github.event.inputs.phpVersion }}'
- name: Install Composer dependencies for old version
run: |
cd old-version
composer install --prefer-dist
- name: Install Composer dependencies for new version
run: |
cd new-version
composer install --prefer-dist
- name: Install Composer dependencies for patch helper
run: |
composer install --prefer-dist --working-dir=ampersand-patch-helper
- name: Create vendor.patch
continue-on-error: true
run: |
mv old-version/vendor new-version/vendor_orig
cd new-version
diff -urN vendor_orig vendor > vendor.patch
- name: Create patch helper files
run: |
php ampersand-patch-helper/bin/patch-helper.php analyse new-version | tee patch-helper-output.txt
- name: Create classmap
run: |
cd new-version
composer dump --classmap-authoritative
php -r "\$classmap=require_once('vendor/composer/autoload_classmap.php'); echo json_encode(\$classmap);" > classmap.json
sed -i "s|${GITHUB_WORKSPACE//\//\\\\\\/}\\\\/new-version|.|g" classmap.json
- name: Prepare archive
run: |
mkdir archive
mv new-version/vendor_files_to_check.patch archive/vendor_files_to_check.patch
mv patch-helper-output.txt archive/patch-helper-output.txt
mv new-version/vendor archive/vendor
mv new-version/vendor_orig archive/vendor_orig
tar -czf archive/vendor.tar.gz -C archive vendor
tar -czf archive/vendor_orig.tar.gz -C archive vendor_orig
rm -rf archive/vendor archive/vendor_orig
mv new-version/vendor.patch archive/vendor.patch
mv new-version/classmap.json archive/classmap.json
- name: Archive files
uses: actions/upload-artifact@v3
with:
name: patch-helper-files
path: |
archive/vendor_files_to_check.patch
archive/patch-helper-output.txt
archive/vendor.tar.gz
archive/vendor_orig.tar.gz
archive/vendor.patch
archive/classmap.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment