feat(setup-magento): add a new action to setup Magento (#76)

Adds a unified setup action for stores and extensions, making the CI
environment more consistent.
This commit is contained in:
Damien Retzinger
2022-10-31 08:51:28 -04:00
committed by GitHub
parent f5d43a5184
commit 7b74ff7386
4 changed files with 308 additions and 1 deletions
+79
View File
@@ -0,0 +1,79 @@
# Magento 2 Package Installation Test Action
A Github Action that sets Magento up to the point of composer install.
## Inputs
See the [action.yml](./action.yml)
## Usage
### Stores
```yml
name: Setup Magento Store
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
setup-magento-store:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./setup-magento
with:
php-version: 8.1
tools: composer:v2
mode: store
working-directory: $GITHUB_WORKSPACE
- run: composer install
name: Composer install
shell: bash
working-directory: ${{ steps.setup-magento.outputs.path }}
```
### Extensions
```yml
name: Setup Magento Store
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
setup-magento-extension:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./setup-magento
with:
php-version: 8.1
tools: composer:v2
mode: extension
magento_version: 2.4.5-p1
- run: composer config repositories.local path $GITHUB_WORKSPACE
name: Add Github Repo for Testing
working-directory: ${{ steps.setup-magento.outputs.path }}
shell: bash
- run: composer require my/package "@dev"
name: Attempt install
working-directory: ${{ steps.setup-magento.outputs.path }}
shell: bash
env:
COMPOSER_AUTH: ${{ secrets.composer_auth }}
```
+100
View File
@@ -0,0 +1,100 @@
name: "Setup Magento"
author: "Graycore"
description: "This action sets up a Magento instance for further actions like running tests, etc."
inputs:
php-version:
description: "Setup PHP version."
default: "8.1"
required: true
tools:
description: "Setup popular tools globally."
required: false
extensions:
description: "Setup PHP extensions."
required: false
coverage:
description: "Setup code coverage driver."
required: false
magento_repository:
required: false
default: "https://mirror.mage-os.org/"
description: "Where to install Magento from"
magento_version:
required: false
default: '~2.4.5'
description: "The version of Magento to use. This is only relevant if you are testing an extension."
apply_fixes:
required: false
default: 'false'
description: "Whether or not to apply fixes during setup."
mode:
required: true
default: 'extension'
description: "The mode for setup, one of: `extension` or `store`."
working-directory:
required: false
default: "."
description: "The working directory to run the action in."
outputs:
path:
description: "The absolute path to where Magento was set up."
value: ${{ steps.setup-magento-get-magento-path.outputs.path }}
runs:
using: "composite"
steps:
- name: Set PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
tools: ${{ inputs.tools }}
coverage: ${{ inputs.coverage }}
extensions: ${{ inputs.coverage }}
- run: |
MAGENTO_DIRECTORY=""
if [ "${{ inputs.mode }}" = 'extension' ]; then
MAGENTO_DIRECTORY="../magento2"
else
MAGENTO_DIRECTORY="${{ inputs.working-directory }}"
fi
echo "MAGENTO_DIRECTORY=$MAGENTO_DIRECTORY" >> $GITHUB_OUTPUT
id: setup-magento-compute-directory
shell: bash
- run: |
mkdir -p ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }}
name: Make a directory that may not exist.
shell: bash
if: inputs.mode == 'extension'
- run: composer create-project --repository-url="${{ inputs.magento_repository }}" "${{ inputs.magento_version }}" ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }} --no-install
working-directory: ${{ inputs.working-directory }}
shell: bash
name: Create Magento ${{ inputs.magento_version }} Project
if: inputs.mode == 'extension'
- uses: graycoreio/github-actions-magento2/fix-magento-install@main
name: Fix Magento Out of Box Install Issues
with:
magento_directory: ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }}
if: inputs.mode == 'extension' || inputs.apply_fixes == 'true'
- run: |
echo "path=$(realpath ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }})" >> $GITHUB_OUTPUT
shell: bash
id: setup-magento-get-magento-path
branding:
icon: "code"
color: "green"