From d638c02ecab005d2541d0480522d4c5e823156f2 Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Sat, 25 Jun 2022 21:15:05 -0400 Subject: [PATCH] feat: add integration test workflow (#3) --- .github/workflows/_internal-integration.yaml | 27 +++ .github/workflows/integration.yaml | 162 ++++++++++++++++++ _test/demo-package/.gitignore | 3 +- .../{TestItWorks.php => ItWorksTest.php} | 2 +- .../Unit/{TestItWorks.php => ItWorksTest.php} | 2 +- 5 files changed, 193 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/_internal-integration.yaml create mode 100644 .github/workflows/integration.yaml rename _test/demo-package/Test/Integration/{TestItWorks.php => ItWorksTest.php} (73%) rename _test/demo-package/Test/Unit/{TestItWorks.php => ItWorksTest.php} (72%) diff --git a/.github/workflows/_internal-integration.yaml b/.github/workflows/_internal-integration.yaml new file mode 100644 index 0000000..457685c --- /dev/null +++ b/.github/workflows/_internal-integration.yaml @@ -0,0 +1,27 @@ +name: Integration Test + +on: + push: + branches: + - main + paths: + - "_test/demo-package/**" + - ".github/workflows/_internal-integration.yaml" + - ".github/workflows/integration.yaml" + pull_request: + branches: + - main + paths: + - "_test/demo-package/**" + - ".github/workflows/_internal-integration.yaml" + - ".github/workflows/integration.yaml" + +jobs: + integration-workflow: + uses: ./.github/workflows/integration.yaml + with: + package_name: graycore/magento2-demo-package + source_folder: $GITHUB_WORKSPACE/_test/demo-package + test_command: ../../../vendor/bin/phpunit ../../../vendor/graycore/magento2-demo-package/Test/Integration + secrets: + composer_auth: ${{ secrets.COMPOSER_AUTH }} diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml new file mode 100644 index 0000000..8823412 --- /dev/null +++ b/.github/workflows/integration.yaml @@ -0,0 +1,162 @@ +on: + workflow_call: + inputs: + + source_folder: + type: string + required: false + default: $GITHUB_WORKSPACE + description: "The source folder of the package" + + package_name: + 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 + required: false + default: "../magento2" + description: "The folder where Magento will be installed" + + magento_repository: + type: string + 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: + type: string + default: rabbitmq:3.10-alpine + description: The RabbitMQ image to use. + required: false + + 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 + default: ../../../vendor/bin/phpunit + description: "The integration test command to run" + + secrets: + composer_auth: + required: true + +jobs: + integration_test: + runs-on: ubuntu-latest + services: + elasticsearch: + image: ${{ inputs.elasticsearch_image }} + env: + discovery.type: single-node + options: >- + --health-cmd "curl http://localhost:9200/_cluster/health" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + ports: + - 9200:9200 + + mysql: + image: ${{ inputs.mysql_image }} + env: + MYSQL_DATABASE: magento_integration_tests + MYSQL_USER: user + MYSQL_PASSWORD: password + MYSQL_ROOT_PASSWORD: rootpassword + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + rabbitmq: + image: ${{ inputs.rabbitmq_image }} + env: + RABBITMQ_DEFAULT_USER: guest + RABBITMQ_DEFAULT_PASS: guest + ports: + - 5672:5672 + steps: + - uses: actions/checkout@v2 + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php_version }} + + - run: composer self-update --${{ inputs.composer_version }} + name: Pin to Composer Version ${{ inputs.composer_version }} + shell: bash + + - run: composer create-project --repository-url="${{ inputs.magento_repository }}" "${{ inputs.magento_version }}" ${{ inputs.magento_directory }} --no-install + shell: bash + env: + COMPOSER_AUTH: ${{ secrets.composer_auth }} + name: Create Magento ${{ inputs.magento_version }} Project + + - name: Get Composer Cache Directory + shell: bash + working-directory: ${{ inputs.magento_directory }} + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - 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 }}' + 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 ${{ inputs.package_name }} "@dev" --no-update && composer install + name: Require and attempt install + working-directory: ${{ inputs.magento_directory }} + shell: bash + env: + COMPOSER_CACHE_DIR: ${{ steps.composer-cache.outputs.dir }} + COMPOSER_AUTH: ${{ secrets.composer_auth }} + + - name: Replace Configuration Settings for env + working-directory: ${{ inputs.magento_directory }}/dev/tests/integration + run: | + sed -i "s/'db-host' => 'localhost'/'db-host' => '127.0.0.1'/" etc/install-config-mysql.php.dist + sed -i "s/'db-user' => 'root'/'db-user' => 'user'/" etc/install-config-mysql.php.dist + sed -i "s/'db-password' => '123123q'/'db-password' => 'password'/" etc/install-config-mysql.php.dist + sed -i "s/'elasticsearch-host' => 'localhost'/'elasticsearch-host' => '127.0.0.1'/" etc/install-config-mysql.php.dist + sed -i "s/'amqp-host' => 'localhost'/'amqp-host' => '127.0.0.1'/" etc/install-config-mysql.php.dist + + - run: ${{ inputs.test_command }} + working-directory: ${{ inputs.magento_directory }}/dev/tests/integration + name: Run Integration Tests \ No newline at end of file diff --git a/_test/demo-package/.gitignore b/_test/demo-package/.gitignore index a725465..aa30d8b 100644 --- a/_test/demo-package/.gitignore +++ b/_test/demo-package/.gitignore @@ -1 +1,2 @@ -vendor/ \ No newline at end of file +vendor/ +.phpunit.result.cache \ No newline at end of file diff --git a/_test/demo-package/Test/Integration/TestItWorks.php b/_test/demo-package/Test/Integration/ItWorksTest.php similarity index 73% rename from _test/demo-package/Test/Integration/TestItWorks.php rename to _test/demo-package/Test/Integration/ItWorksTest.php index 2931354..a0a5d8c 100644 --- a/_test/demo-package/Test/Integration/TestItWorks.php +++ b/_test/demo-package/Test/Integration/ItWorksTest.php @@ -2,7 +2,7 @@ namespace Graycore\DemoPackage\Test\Integration; -class TestItWorks extends \PHPUnit\Framework\TestCase +class ItWorksTest extends \PHPUnit\Framework\TestCase { public function testItWorks() diff --git a/_test/demo-package/Test/Unit/TestItWorks.php b/_test/demo-package/Test/Unit/ItWorksTest.php similarity index 72% rename from _test/demo-package/Test/Unit/TestItWorks.php rename to _test/demo-package/Test/Unit/ItWorksTest.php index 7fb5821..7e839ab 100644 --- a/_test/demo-package/Test/Unit/TestItWorks.php +++ b/_test/demo-package/Test/Unit/ItWorksTest.php @@ -2,7 +2,7 @@ namespace Graycore\DemoPackage\Test\Unit; -class TestItWorks extends \PHPUnit\Framework\TestCase +class ItWorksTest extends \PHPUnit\Framework\TestCase { public function testItWorks()