Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
code

GitHub Action

Magento 2 installation with DDEV

v1.1.0

Magento 2 installation with DDEV

code

Magento 2 installation with DDEV

A Github Action for installing Magento 2 with DDEV

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Magento 2 installation with DDEV

uses: julienloizelet/[email protected]

Learn more about this action in julienloizelet/magento2-ddev-installation

Choose a version

Magento 2 installation with DDEV

Version Installation with Varnish Installation with Static and Unit tests End-to-end tests

A GitHub Action for installing Magento 2 with DDEV.

Table of Contents

Quick start

We will suppose here that you want to test on a Magento 2.4.5 instance with PHP 8.1.

You can add the following step in your workflow:

- uses: julienloizelet/[email protected]
  with:
    php_version: "8.1"
    magento_version: "2.4.5"

This step will install a Magento 2.4.5 instance with PHP 8.1.

In the steps that follow, you will be able to run any DDEV commands to interact with the Magento 2 environment.

Settings

Available keys

The following keys are available as step.with keys:


  • php_version (String): PHP version to use in the web container. Default: 8.1.

Allowed values are: 7.2, 7.3, 7.4, 8.1.

Please choose a PHP version that is compatible with the magento_version below.


  • magento_repository (String): Where to install Magento from. Default: https://mirror.mage-os.org/.

Could be "https://mirror.mage-os.org/", "https://repo.magento.com/" or any available repository.

Please choose a repository that handle the magento_version below.


  • magento_edition (String): The edition of Magento to install. Default: magento/project-community-edition

Could be "magento/project-community-edition", "magento/project-enterprise-edition" or any available edition.


  • magento_version (String): The Magento release version to install. Default: 2.4.5.

You can use X.Y.Z format or X.Y.Z-pN format for patch release.

Allowed versions are 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.3.6, 2.3.7, 2.4.0, 2.4.1, 2.4.2, 2.4.3,2.4.4, 2.4.5 and any of their patches versions.

Please note that available versions depend on the chosen magento_repository.


  • composer_auth (String): Composer authentication credentials. Default: "".

You have to pass a JSON string. For example:

{
  "http-basic": {
    "repo.magento.com": {
      "username": "**********************",
      "password": "**********************"
    }
  }
}

As GitHub allows saving multiline secret, you can use a secret to store this sensitive value. Just copy/paste the json in a M2_COMPOSER_AUTH secret and use it like this: composer_auth: ${{ secrets.M2_COMPOSER_AUTH }}.


  • varnish_setup (Boolean): Install with ready-to-use Varnish. Default: false.

    You should use quote to set true: varnish_setup: "true".


  • ddev_repository_ref (String): The branch, tag or SHA for checkout the DDEV repository. Default: v2.4.0.

    The Magento 2 DDEV specific repo is https://github.com/julienloizelet/ddev-m2, and you can set here a specific reference (vx.y.z, main, etc.)


Examples

  • Magento 2.3.7-p4 (magento/project-community-edition) , from https://repo.magento.com/, with PHP 7.4 and without Varnish:
with:
  php_version: "7.4"
  magento_version: "2.3.7-p4"
  magento_repository: "https://repo.magento.com/"
  composer_auth: ${{ secrets.M2_COMPOSER_AUTH }}
  • Magento 2.4.4 (magento/project-community-edition) , from https://mirror.mage-os.org/, with PHP 8.1 and with Varnish:
with:
  php_version: "8.1"
  magento_version: "2.4.4"
  varnish_setup: "true"

Usage

Use DDEV to interact with your Magento 2 instance

You could run all the DDEV basic commands and some specific ones coming from my M2/DDEV repo.

For example, you could run these commands in some other steps:

ddev magento config:set admin/security/password_is_forced 0
ddev magento config:set admin/security/password_lifetime 0
ddev magento module:disable Magento_TwoFactorAuth
ddev magento indexer:reindex
ddev magento c:c

Test a module

Once you have run this action, you will be able to install and activate a module. Thus, you will be able to run all kind of tests : static tests (coding standards), unit tests, integration tests, or any other end-to-end tests.

Examples

Before reading below, you could read the examples here:

How to

To do that, you could use the following folder structure :

$GITHUB_WORKSPACE
│   
│ (Magento 2 sources installed with composer)    
│
└───.ddev
│   │   
│   │ (Cloned sources of a Magento 2 DDEV specific repo)
│   
└───my-own-modules
    │   
    │
    └───<some-path>
       │   
       │ (Sources of a module)
         

by adapting the following steps:

- name: Clone module files
  uses: actions/checkout@v3
  with:
    path: my-own-modules/<some-path>
- name: Prepare composer repositories
  run: |
      ddev composer config --unset repositories.0
      ddev composer config repositories.0 '{"type": "path", "url":"my-own-modules/<some-path>",  "canonical": true, "options": {"symlink": false}}'
      ddev composer config repositories.1 '{"type": "composer", "url":"<the-magento-repository>",  "exclude": ["<some-package-name>"]}'
- name: Add module as composer dependency
  run: ddev composer require <some-package-name>:@dev --no-interaction
- name: Install module
  run: |
    ddev magento module:enable <some-extension-name>
    ddev magento setup:upgrade

Then, you could run:

  • PHP Code Sniffer: ddev phpcs my-own-modules/<some-path>
  • PHP Mess Detector: ddev phpmd my-own-modules/<some-path>
  • PHP Stan: ddev phpstan my-own-modules/<some-path>
  • Unit test: ddev phpunit my-own-modules/<some-path>/Test/Unit

Technical details

For you information, the setup of Magento 2 is launch with the following settings:

bin/magento setup:install \
   --base-url=https://m245.ddev.site \
   --db-host=db \
   --db-name=db \
   --db-user=db \
   --db-password=db \
   --backend-frontname=admin \
   --admin-firstname=admin \
   --admin-lastname=admin \
   [email protected] \
   --admin-user=admin \
   --admin-password=admin123 \
   --language=en_US \
   --currency=USD \
   --timezone=America/Chicago \
   --use-rewrites=1 \
   --elasticsearch-host=elasticsearch

The Magento 2 environment is a Docker environment created with DDEV and comes with the following services:

  • web: PHP 8.1, nginx-fpm, NodeJs
  • db: MariaDb
  • elastisearch
  • memcached
  • redis
  • mailhog

Finally, the structure of your $GITHUB_WORKSPACE will look like below.

$GITHUB_WORKSPACE
│   
│ (Magento 2 sources installed with composer)    
│
└───.ddev
    │   
    │ (Cloned sources of a Magento 2 DDEV specific repo)

The Magento 2 DDEV specific repo is https://github.com/julienloizelet/ddev-m2: it includes some others DDEV custom commands and files.

License

MIT