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

Skip to content

feat(init-magento): add new init-magento action #73

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

Closed
wants to merge 1 commit into from
Closed
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
65 changes: 65 additions & 0 deletions .github/workflows/_internal_init_magento.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Init Magento Test

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

env:
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: all
id: supported-version
- run: echo ${{ steps.supported-version.outputs.matrix }}

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

- name: Set PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v${{ matrix.composer }}
coverage: none

- run: composer create-project --repository-url="https://mirror.mage-os.org" "${{ matrix.magento }}" ${{ env.magento_folder }} --no-install
shell: bash
name: Create Magento ${{ matrix.magento }} Project

- uses: ./init-magento
name: Init Magento
with:
magento_directory: ${{ env.magento_folder }}

- run: composer install
shell: bash
working-directory: ${{ env.magento_folder }}
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ Opinionated Github Actions and Workflows to make building, testing, and maintain

## Workflows

| Workflow Name | Description |
| -------------------------------------------------------- | ---------------------------------------------------------------------- |
| Workflow Name | Description |
| ------------------------------------------------------------- | ---------------------------------------------------------------------- |
| [Integration Test](./.github/workflows/integration-README.md) | A Github Workflow that runs the Integration Tests of a Magento Package |

## Actions

| Action Name | Description |
| ------------------------------------------------ | ------------------------------------------------------------------ |
| [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package |
| [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 |
| Action Name | Description |
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| [Init Magento](./init-magento/README.md) | A Github Action that initializes a Magento project up until `composer install` |
| [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package |
| [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 |
104 changes: 104 additions & 0 deletions init-magento/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Init Magento

A Github Action that initializes a Magento project up until `composer install`. This is extremely useful for getting Magento installations to a "common" point for further operations like Unit Tests, Installation Tests, and Integration Tests.

This action will:

- Apply "CI" hotfixes which interfere with common CI pipeline operations.
- Create, store, and pull a common composer cache for re-use across other actions.

## Inputs

See the [action.yml](./action.yml)


### Usage for an extension

```yml
name: Do Something with Magento

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
magento_directory: ../magento2

jobs:
compute_matrix:
runs-on: ubuntu-latest
steps:
steps:
- name: Set PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2

- run: composer create-project --repository-url="https://repo.magento.com" "v2.4.5-p1" ${{ env.magento_directory }} --no-install
shell: bash
env:
COMPOSER_AUTH: ${{ env.COMPOSER_AUTH }}
name: Create Magento Project

- uses: graycoreio/github-actions-magento2/init-magento@main
name: "Initialize Magento"
with:
magento_directory: ${{ env.magento_directory }}

- run: composer config repositories.local path $GITHUB_WORKSPACE
name: Add Github Repo for Testing
working-directory: ${{ env.magento_directory }}
shell: bash

- run: composer require my/package "@dev" --no-update && composer install
name: Require and attempt install
working-directory: ${{ env.magento_directory }}
shell: bash
env:
COMPOSER_AUTH: ${{ env.COMPOSER_AUTH }}
```

### Usage for a Magento 2 Project

```yml
name: Do Something with Magento

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
magento_directory: ./

jobs:
compute_matrix:
runs-on: ubuntu-latest
steps:
steps:
- name: Set PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2

- uses: graycoreio/github-actions-magento2/init-magento@main
name: "Initialize Magento"
with:
magento_directory: ${{ env.magento_directory }}

- run: composer install
working-directory: ${{ env.magento_directory }}
shell: bash
env:
COMPOSER_AUTH: ${{ env.COMPOSER_AUTH }}
```

84 changes: 84 additions & 0 deletions init-magento/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: "Init Magento"
author: "Graycore"
description: " A Github Action that initializes Magento up until (but not including) `composer install`"
inputs:
magento_directory:
required: true
description: "The folder where Magento will be installed"

apply_fixes:
required: false
default: 'true'
description: 'Whether or not to automatically apply fixes from the community to common CI problems.'

composer_cache_key:
required: false
default: '__graycore'
description: A key to version the composer cache. Can be incremented if you need to bust the cache.

runs:
using: "composite"
steps:
- uses: graycoreio/github-actions-magento2/get-magento-version@main
id: init-magento-get-magento-version
with:
working-directory: ${{ inputs.magento_directory }}

- run: echo "::set-output name=version::$(php -v | awk 'NR==1{print $2}')"
shell: bash
id: init-magento-get-php-version

- run: echo "::set-output name=version::$(composer --version | awk '{print $3}')"
shell: bash
name: Compute Composer Version
id: init-magento-get-composer-version

- name: Get Composer Cache Directory
shell: bash
working-directory: ${{ inputs.magento_directory }}
id: init-magento-composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: "Cache Composer Packages"
uses: actions/cache@v3
with:
key: "composer | v5 | ${{ inputs.composer_cache_key }} | ${{ steps.init-magento-get-composer-version.outputs.version }} | ${{ steps.init-magento-get-magento-version.outputs.version }} | ${{ steps.init-magento-get-php-version.outputs.version }}"
restore-keys: |
composer | v5 | ${{ inputs.composer_cache_key }} |
path: ${{ steps.init-magento-composer-cache.outputs.dir }}

- run: composer require monolog/monolog:"<2.7.0" --no-update
shell: bash
name: Fixup Monolog (https://github.com/magento/magento2/pull/35596)
working-directory: ${{ inputs.magento_directory }}
if: |
steps.init-magento-get-magento-version.outputs.version == '"2.4.4"' && inputs.apply_fixes == 'true'

- run: composer require "dotmailer/dotmailer-magento2-extension-package:4.6.0-p2 as 4.6.0" --no-update
shell: bash
name: Fixup Dotmailer (https://devdocs.magento.com/guides/v2.4/release-notes/release-notes-2-4-0-commerce.html#dotdigital-1)
working-directory: ${{ inputs.magento_directory }}
if: |
steps.init-magento-get-magento-version.outputs.version == '"2.4.0"' && inputs.apply_fixes == 'true'

- run: |
composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer config --no-interaction allow-plugins.laminas/laminas-dependency-plugin true
composer config --no-interaction allow-plugins.magento/* true
name: Fixup Composer Plugins
shell: bash
working-directory: ${{ inputs.magento_directory }}
if: |
!startsWith(steps.init-magento-get-composer-version.outputs.version, 1) && inputs.apply_fixes == 'true'

- run: |
composer global require hirak/prestissimo
name: Install composer plugin for parallel downloads
shell: bash
working-directory: ${{ inputs.magento_directory }}
if: ${{ startsWith(steps.init-magento-get-composer-version.outputs.version, '1') }}

branding:
icon: "code"
color: "green"