Skip to content

Commit

Permalink
feat: add matrix to integration-test workflow (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
damienwebdev committed Jun 26, 2022
1 parent dd1a36b commit fb1ac5f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 49 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/_internal-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ on:
- ".github/workflows/integration.yaml"

jobs:
compute_matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.supported-version.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- uses: ./supported-version
id: supported-version
- run: echo ${{ steps.supported-version.outputs.matrix }}
integration-workflow:
needs: compute_matrix
uses: ./.github/workflows/integration.yaml
with:
package_name: graycore/magento2-demo-package
source_folder: $GITHUB_WORKSPACE/_test/demo-package
matrix: ${{ needs.compute_matrix.outputs.matrix }}
test_command: ../../../vendor/bin/phpunit ../../../vendor/graycore/magento2-demo-package/Test/Integration
secrets:
composer_auth: ${{ secrets.COMPOSER_AUTH }}
37 changes: 34 additions & 3 deletions .github/workflows/integration-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ A Github Workflow that runs the Integration Tests of a Magento Package

See the [integration.yaml](./integration.yaml)

| Input | Description | Required | Default |
| ------------------ | ------------------------------------------------------------- | -------- | ----------------------------- |
| matrix | JSON string of [version matrix for Magento](#./matrix-format) | true | NULL |
| package_name | The name of the package | true | NULL |
| source_folder | The source folder of the package | false | $GITHUB_WORKSPACE |
| magento_directory | The folder where Magento will be installed | false | ../magento2 |
| magento_repository | Where to install Magento from | false | https://repo.magento.com/ |
| test_command | The integration test command to run | false | "../../../vendor/bin/phpunit" |

## Secrets
| Input | Description | Required | Default |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------- |
| composer_auth | JSON string of [composer credentials]([#./matrix-format](https://devdocs.magento.com/guides/v2.4/install-gde/prereq/connect-auth.html)) | true | NULL |

### Matrix Format

The Magento matrix format outlined by the [supported versions action.](https://github.com/graycoreio/github-actions-magento2/tree/main/supported-version/supported.json
)


## Usage

```yml
Expand All @@ -20,12 +40,23 @@ on:
- main

jobs:
compute_matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.supported-version.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- uses: graycoreio/github-actions-magento2/supported-version@main
id: supported-version
- run: echo ${{ steps.supported-version.outputs.matrix }}
integration-workflow:
needs: compute_matrix
uses: graycoreio/github-actions-magento2/.github/workflows/integration.yaml@main
with:
package_name: YOUR_PACKAGE_NAME
source_folder: $GITHUB_WORKSPACE
test_command: ../../../vendor/bin/phpunit ../../../vendor/YOUR_VENDOR/YOUR_PACKAGE_NAME/Test/Integration
package_name: graycore/magento2-demo-package
source_folder: $GITHUB_WORKSPACE/_test/demo-package
matrix: ${{ needs.compute_matrix.outputs.matrix }}
test_command: ../../../vendor/bin/phpunit ../../../vendor/graycore/magento2-demo-package/Test/Integration
secrets:
composer_auth: ${{ secrets.COMPOSER_AUTH }}
```
67 changes: 21 additions & 46 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ on:
type: string
required: true
description: "The name of the package"

composer_version:
type: string
default: "2"
description: The composer version to use.
required: false

php_version:
type: string
default: "7.4"
description: The php version to use.
required: false

magento_version:
type: string
default: magento/project-community-edition:>2.4.3 <2.4.4
description: The magento version to use.
required: false

magento_directory:
type: string
Expand All @@ -42,25 +24,12 @@ on:
required: false
default: "https://repo.magento.com/"
description: "Where to install Magento from"

mysql_image:
type: string
default: mysql:8.0
description: The mysql image to use.
required: false

rabbitmq_image:

matrix:
type: string
default: rabbitmq:3.10-alpine
description: The RabbitMQ image to use.
required: false
required: true
description: "The matrix of Magento versions to test against"

elasticsearch_image:
type: string
default: docker.elastic.co/elasticsearch/elasticsearch:7.16.3
description: The elasticsearch image to use.
required: false

test_command:
type: string
required: false
Expand All @@ -73,10 +42,12 @@ on:

jobs:
integration_test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{ fromJSON(inputs.matrix) }}
services:
elasticsearch:
image: ${{ inputs.elasticsearch_image }}
image: ${{ matrix.elasticsearch }}
env:
discovery.type: single-node
options: >-
Expand All @@ -88,7 +59,7 @@ jobs:
- 9200:9200

mysql:
image: ${{ inputs.mysql_image }}
image: ${{ matrix.mysql }}
env:
MYSQL_DATABASE: magento_integration_tests
MYSQL_USER: user
Expand All @@ -99,7 +70,7 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

rabbitmq:
image: ${{ inputs.rabbitmq_image }}
image: ${{ matrix.rabbitmq }}
env:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
Expand All @@ -110,17 +81,17 @@ jobs:
- name: Set PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
php-version: ${{ matrix.php }}

- run: composer self-update --${{ inputs.composer_version }}
name: Pin to Composer Version ${{ inputs.composer_version }}
- run: composer self-update --${{ matrix.composer }}
name: Pin to Composer Version ${{ matrix.composer }}
shell: bash

- run: composer create-project --repository-url="${{ inputs.magento_repository }}" "${{ inputs.magento_version }}" ${{ inputs.magento_directory }} --no-install
- run: composer create-project --repository-url="${{ inputs.magento_repository }}" "${{ matrix.magento }}" ${{ inputs.magento_directory }} --no-install
shell: bash
env:
COMPOSER_AUTH: ${{ secrets.composer_auth }}
name: Create Magento ${{ inputs.magento_version }} Project
name: Create Magento ${{ matrix.magento }} Project

- name: Get Composer Cache Directory
shell: bash
Expand All @@ -132,14 +103,18 @@ jobs:
- name: "Cache Composer Packages"
uses: actions/cache@v3
with:
key: 'composer | v3 | "$(Agent.OS)" | composer.lock | ${{ inputs.composer_version }} | ${{ inputs.php_version }} | ${{ inputs.magento_version }}'
key: 'composer | v3 | "$(Agent.OS)" | composer.lock | ${{ matrix.composer }} | ${{ matrix.php }} | ${{ matrix.magento }}'
path: ${{ steps.composer-cache.outputs.dir }}

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


- run: composer require monolog/monolog:"!=2.7.0" --no-update
name: Fixup Monolog (https://github.com/magento/magento2/pull/35596)
working-directory: ${{ inputs.magento_directory }}

- run: composer require ${{ inputs.package_name }} "@dev" --no-update && composer install
name: Require and attempt install
working-directory: ${{ inputs.magento_directory }}
Expand Down

0 comments on commit fb1ac5f

Please sign in to comment.