Skip to content

Commit d638c02

Browse files
authored
feat: add integration test workflow (#3)
1 parent 72b1f25 commit d638c02

File tree

5 files changed

+193
-3
lines changed

5 files changed

+193
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Integration Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "_test/demo-package/**"
9+
- ".github/workflows/_internal-integration.yaml"
10+
- ".github/workflows/integration.yaml"
11+
pull_request:
12+
branches:
13+
- main
14+
paths:
15+
- "_test/demo-package/**"
16+
- ".github/workflows/_internal-integration.yaml"
17+
- ".github/workflows/integration.yaml"
18+
19+
jobs:
20+
integration-workflow:
21+
uses: ./.github/workflows/integration.yaml
22+
with:
23+
package_name: graycore/magento2-demo-package
24+
source_folder: $GITHUB_WORKSPACE/_test/demo-package
25+
test_command: ../../../vendor/bin/phpunit ../../../vendor/graycore/magento2-demo-package/Test/Integration
26+
secrets:
27+
composer_auth: ${{ secrets.COMPOSER_AUTH }}

.github/workflows/integration.yaml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
5+
source_folder:
6+
type: string
7+
required: false
8+
default: $GITHUB_WORKSPACE
9+
description: "The source folder of the package"
10+
11+
package_name:
12+
type: string
13+
required: true
14+
description: "The name of the package"
15+
16+
composer_version:
17+
type: string
18+
default: "2"
19+
description: The composer version to use.
20+
required: false
21+
22+
php_version:
23+
type: string
24+
default: "7.4"
25+
description: The php version to use.
26+
required: false
27+
28+
magento_version:
29+
type: string
30+
default: magento/project-community-edition:>2.4.3 <2.4.4
31+
description: The magento version to use.
32+
required: false
33+
34+
magento_directory:
35+
type: string
36+
required: false
37+
default: "../magento2"
38+
description: "The folder where Magento will be installed"
39+
40+
magento_repository:
41+
type: string
42+
required: false
43+
default: "https://repo.magento.com/"
44+
description: "Where to install Magento from"
45+
46+
mysql_image:
47+
type: string
48+
default: mysql:8.0
49+
description: The mysql image to use.
50+
required: false
51+
52+
rabbitmq_image:
53+
type: string
54+
default: rabbitmq:3.10-alpine
55+
description: The RabbitMQ image to use.
56+
required: false
57+
58+
elasticsearch_image:
59+
type: string
60+
default: docker.elastic.co/elasticsearch/elasticsearch:7.16.3
61+
description: The elasticsearch image to use.
62+
required: false
63+
64+
test_command:
65+
type: string
66+
required: false
67+
default: ../../../vendor/bin/phpunit
68+
description: "The integration test command to run"
69+
70+
secrets:
71+
composer_auth:
72+
required: true
73+
74+
jobs:
75+
integration_test:
76+
runs-on: ubuntu-latest
77+
services:
78+
elasticsearch:
79+
image: ${{ inputs.elasticsearch_image }}
80+
env:
81+
discovery.type: single-node
82+
options: >-
83+
--health-cmd "curl http://localhost:9200/_cluster/health"
84+
--health-interval 10s
85+
--health-timeout 5s
86+
--health-retries 10
87+
ports:
88+
- 9200:9200
89+
90+
mysql:
91+
image: ${{ inputs.mysql_image }}
92+
env:
93+
MYSQL_DATABASE: magento_integration_tests
94+
MYSQL_USER: user
95+
MYSQL_PASSWORD: password
96+
MYSQL_ROOT_PASSWORD: rootpassword
97+
ports:
98+
- 3306:3306
99+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
100+
101+
rabbitmq:
102+
image: ${{ inputs.rabbitmq_image }}
103+
env:
104+
RABBITMQ_DEFAULT_USER: guest
105+
RABBITMQ_DEFAULT_PASS: guest
106+
ports:
107+
- 5672:5672
108+
steps:
109+
- uses: actions/checkout@v2
110+
- name: Set PHP Version
111+
uses: shivammathur/setup-php@v2
112+
with:
113+
php-version: ${{ inputs.php_version }}
114+
115+
- run: composer self-update --${{ inputs.composer_version }}
116+
name: Pin to Composer Version ${{ inputs.composer_version }}
117+
shell: bash
118+
119+
- run: composer create-project --repository-url="${{ inputs.magento_repository }}" "${{ inputs.magento_version }}" ${{ inputs.magento_directory }} --no-install
120+
shell: bash
121+
env:
122+
COMPOSER_AUTH: ${{ secrets.composer_auth }}
123+
name: Create Magento ${{ inputs.magento_version }} Project
124+
125+
- name: Get Composer Cache Directory
126+
shell: bash
127+
working-directory: ${{ inputs.magento_directory }}
128+
id: composer-cache
129+
run: |
130+
echo "::set-output name=dir::$(composer config cache-files-dir)"
131+
132+
- name: "Cache Composer Packages"
133+
uses: actions/cache@v3
134+
with:
135+
key: 'composer | v3 | "$(Agent.OS)" | composer.lock | ${{ inputs.composer_version }} | ${{ inputs.php_version }} | ${{ inputs.magento_version }}'
136+
path: ${{ steps.composer-cache.outputs.dir }}
137+
138+
- run: composer config repositories.local path ${{ inputs.source_folder }}
139+
name: Add Github Repo for Testing
140+
working-directory: ${{ inputs.magento_directory }}
141+
shell: bash
142+
143+
- run: composer require ${{ inputs.package_name }} "@dev" --no-update && composer install
144+
name: Require and attempt install
145+
working-directory: ${{ inputs.magento_directory }}
146+
shell: bash
147+
env:
148+
COMPOSER_CACHE_DIR: ${{ steps.composer-cache.outputs.dir }}
149+
COMPOSER_AUTH: ${{ secrets.composer_auth }}
150+
151+
- name: Replace Configuration Settings for env
152+
working-directory: ${{ inputs.magento_directory }}/dev/tests/integration
153+
run: |
154+
sed -i "s/'db-host' => 'localhost'/'db-host' => '127.0.0.1'/" etc/install-config-mysql.php.dist
155+
sed -i "s/'db-user' => 'root'/'db-user' => 'user'/" etc/install-config-mysql.php.dist
156+
sed -i "s/'db-password' => '123123q'/'db-password' => 'password'/" etc/install-config-mysql.php.dist
157+
sed -i "s/'elasticsearch-host' => 'localhost'/'elasticsearch-host' => '127.0.0.1'/" etc/install-config-mysql.php.dist
158+
sed -i "s/'amqp-host' => 'localhost'/'amqp-host' => '127.0.0.1'/" etc/install-config-mysql.php.dist
159+
160+
- run: ${{ inputs.test_command }}
161+
working-directory: ${{ inputs.magento_directory }}/dev/tests/integration
162+
name: Run Integration Tests

_test/demo-package/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
vendor/
1+
vendor/
2+
.phpunit.result.cache

_test/demo-package/Test/Integration/TestItWorks.php renamed to _test/demo-package/Test/Integration/ItWorksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Graycore\DemoPackage\Test\Integration;
44

5-
class TestItWorks extends \PHPUnit\Framework\TestCase
5+
class ItWorksTest extends \PHPUnit\Framework\TestCase
66
{
77

88
public function testItWorks()

_test/demo-package/Test/Unit/TestItWorks.php renamed to _test/demo-package/Test/Unit/ItWorksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Graycore\DemoPackage\Test\Unit;
44

5-
class TestItWorks extends \PHPUnit\Framework\TestCase
5+
class ItWorksTest extends \PHPUnit\Framework\TestCase
66
{
77

88
public function testItWorks()

0 commit comments

Comments
 (0)