Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions .github/workflows/_internal-setup-magento.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Setup Magento Test

on:
workflow_dispatch: {}
push:
branches:
- main
paths:
- "setup-magento/**"
- ".github/workflows/_internal-setup-magento.yaml"
- "supported-version/**"
- "!(**/*.md)"
pull_request:
branches:
- main
paths:
- "setup-magento/**"
- ".github/workflows/_internal-setup-magento.yaml"
- "supported-version/**"
- "!(**/*.md)"

env:
PSEUDO_REPO_FOLDER: ../magento_repo
magento_folder: ../magento2

jobs:
compute_matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.supported-version.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- uses: ./supported-version
with:
kind: currently-supported
id: supported-version
- run: echo ${{ steps.supported-version.outputs.matrix }}

setup-magento-store:
needs: compute_matrix
strategy:
matrix: ${{ fromJSON(needs.compute_matrix.outputs.matrix) }}
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- 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
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v${{ matrix.composer }}

- uses: actions/cache@v3
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="https://mirror.mage-os.org" "${{ matrix.magento }}" "${{ env.PSEUDO_REPO_FOLDER }}" --no-install
name: Create Store to simulate a real Magento store in a real repo.
if: steps.setup-magento-store-cache.outputs.cache-hit != 'true'

- uses: ./fix-magento-install
name: Fix Magento Out of Box Install Issues
with:
magento_directory: ${{ env.PSEUDO_REPO_FOLDER }}
if: steps.setup-magento-store-cache.outputs.cache-hit != 'true'

- run: composer install
shell: bash
working-directory: "${{ env.PSEUDO_REPO_FOLDER }}"
if: steps.setup-magento-store-cache.outputs.cache-hit != 'true'

- run: git init && git config user.email "[email protected]" && git config user.name "Your Name" && git add . && git commit -m "init" && git clean -fdx
working-directory: "${{ env.PSEUDO_REPO_FOLDER }}"
if: steps.setup-magento-store-cache.outputs.cache-hit != 'true'

- run: cp -R ${{ env.PSEUDO_REPO_FOLDER }} ${{ env.magento_folder }}
shell: bash

- uses: ./setup-magento
id: setup-magento
with:
php-version: ${{ matrix.php }}
tools: composer:v${{ matrix.composer }}
mode: store
working-directory: ${{ env.magento_folder }}

- uses: graycoreio/github-actions-magento2/cache-magento@main
with:
mode: 'store'
composer_cache_key: '${{ matrix.magento }}'

- run: composer install
name: Composer install
shell: bash
working-directory: ${{ steps.setup-magento.outputs.path }}

setup-magento-extension:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: ./setup-magento
id: setup-magento
with:
php-version: 8.1
tools: composer:v2
mode: extension
magento_version: magento/project-community-edition:2.4.5-p1

- uses: graycoreio/github-actions-magento2/cache-magento@main
with:
mode: 'extension'
composer_cache_key: 'magento/project-community-edition:2.4.5-p1'

- run: composer install
name: Composer install
shell: bash
working-directory: ${{ steps.setup-magento.outputs.path }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Opinionated Github Actions and Workflows to make building, testing, and maintain
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package |
| [Fix Magento Install](./fix-magento-install/README.md) | A Github Action that fixes Magento before `composer install` |
| [Cache Magento](./cache-magento/README.md) | A Github Action that creates a composer cache for a Magento extension or store. |
| [Cache Magento](./cache-magento/README.md) | A Github Action that creates a composer cache for a Magento extension or store. |
| [Setup Magento](./setup-magento/README.md) | A Github Action that sets up Magento before `composer install` for an extension or store. |
| [Get Magento Version](./get-magento-version/README.md) | A Github Action that computes the installed Magento version. |
| [Installation Test](./installation-test/README.md) | A Github Action that tests the installability of a Magento Package |
| [Supported Version](./supported-version/README.md) | A Github Action that computes the currently supported Github Actions Matrix for Magento 2 |
79 changes: 79 additions & 0 deletions setup-magento/README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 100 additions & 0 deletions setup-magento/action.yml
Original file line number Diff line number Diff line change
@@ -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"