From f132dd991ae221f44c26787295659239e967037c Mon Sep 17 00:00:00 2001 From: Carine Bonnafous Date: Mon, 18 Nov 2024 14:51:09 +0100 Subject: [PATCH 1/6] Send unit tests results to ReportPortal --- .github/workflows/ci.yml | 9 +++++++++ tests/reportportal_conf.sh | 21 ++++++++++++++++++++ tests/reportportal_phpunit_conf_template.xml | 12 +++++++++++ 3 files changed, 42 insertions(+) create mode 100755 tests/reportportal_conf.sh create mode 100644 tests/reportportal_phpunit_conf_template.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae228866..c4705923 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,15 @@ jobs: string=': void' grep -r -l "$string" tests/ | xargs sed -i "s/$string//g" + - name: Set ReportPortal configuration + # ReportPortal agent only works for PHP 7.1, 7.2, 7.3 and 7.4 + if: github.ref_name == 'main' && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) + run: ./tests/reportportal_conf.sh + env: + REPORT_PORTAL_API_KEY: ${{ secrets.REPORT_PORTAL_API_KEY }} + REPORT_PORTAL_ENDPOINT: ${{ vars.REPORT_PORTAL_ENDPOINT }} + PHP_VERSION: ${{ matrix.php }} + - name: PHPUnit run: | case ${{ matrix.php }} in diff --git a/tests/reportportal_conf.sh b/tests/reportportal_conf.sh new file mode 100755 index 00000000..ace52e1b --- /dev/null +++ b/tests/reportportal_conf.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Remove /api/v1 from REPORT_PORTAL_ENDPOINT (reportportal/agent-php-PHPUnit requires only host) +export REPORT_PORTAL_HOST=${REPORT_PORTAL_ENDPOINT/\/api\/v1/} + +# Add secrets values in tests/reportportal_phpunit_conf_template.xml +# Following environment variables are required: +# REPORT_PORTAL_API_KEY +# REPORT_PORTAL_HOST +# PHP_VERSION +envsubst < tests/reportportal_phpunit_conf_template.xml > tests/reportportal_phpunit_conf.xml + +# Add conf for ReportPortal extension in phpunit.ci.xml +# Inserts content of file tests/reportportal_phpunit_conf.xml before end tag in phpunit.ci.xml +sed -i $'/<\/phpunit>/{e cat tests/reportportal_phpunit_conf.xml\n}' phpunit.ci.xml + +# Add ReportPortal extension to composer.json +# reportportal/phpunit has no stable version, so we set minimum stability to dev only when running tests +composer config minimum-stability dev +# This is not supported by all versions of PHP, so we need to install it separately +composer require --dev reportportal/phpunit diff --git a/tests/reportportal_phpunit_conf_template.xml b/tests/reportportal_phpunit_conf_template.xml new file mode 100644 index 00000000..2b60049a --- /dev/null +++ b/tests/reportportal_phpunit_conf_template.xml @@ -0,0 +1,12 @@ + + + + ${REPORT_PORTAL_API_KEY} + ${REPORT_PORTAL_HOST} + integrations + .000+00:00 + alma-php-client PHPUnit tests + PHP version: ${PHP_VERSION} + + + From 2396eabc20225b0a6a3e2efb386999bd6cb8f396 Mon Sep 17 00:00:00 2001 From: Carine Bonnafous Date: Thu, 28 Nov 2024 17:42:28 +0100 Subject: [PATCH 2/6] Patch reportportal/basic to make it compliant with ReportPortal api/v2 --- tests/reportportal_conf.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/reportportal_conf.sh b/tests/reportportal_conf.sh index ace52e1b..59d4581f 100755 --- a/tests/reportportal_conf.sh +++ b/tests/reportportal_conf.sh @@ -1,5 +1,11 @@ #!/usr/bin/env bash +# exit if REPORT_PORTAL_API_KEY or REPORT_PORTAL_ENDPOINT is not set +if [ -z "$REPORT_PORTAL_API_KEY" ] || [ -z "$REPORT_PORTAL_ENDPOINT" ]; then + echo "Please set REPORT_PORTAL_API_KEY and REPORT_PORTAL_ENDPOINT environment variables" + exit 1 +fi + # Remove /api/v1 from REPORT_PORTAL_ENDPOINT (reportportal/agent-php-PHPUnit requires only host) export REPORT_PORTAL_HOST=${REPORT_PORTAL_ENDPOINT/\/api\/v1/} @@ -19,3 +25,9 @@ sed -i $'/<\/phpunit>/{e cat tests/reportportal_phpunit_conf.xml\n}' phpunit.ci. composer config minimum-stability dev # This is not supported by all versions of PHP, so we need to install it separately composer require --dev reportportal/phpunit + +# Patch reportportal/basic to make it compatible with api/v2 +# Use api/v2 instead of api/v1 (hardcoded in reportportal/basic) +sed -i 's/v1\//v2\//g' vendor/reportportal/basic/src/service/ReportPortalHTTPService.php +# Add launchUuid to finishItem method in reportportal/basic to make it compatible with api/v2 +sed -i "/function finishItem/,/}/s/\('status' => \$status\)/\1,\n'launchUuid' => self::\$launchID/" vendor/reportportal/basic/src/service/ReportPortalHTTPService.php \ No newline at end of file From 574d06b7bd35a7630787cbea72cba2b0e756d3aa Mon Sep 17 00:00:00 2001 From: Carine Bonnafous Date: Thu, 28 Nov 2024 17:47:41 +0100 Subject: [PATCH 3/6] test: commit to be removed --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4705923..d50df52d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,8 @@ jobs: - name: Set ReportPortal configuration # ReportPortal agent only works for PHP 7.1, 7.2, 7.3 and 7.4 - if: github.ref_name == 'main' && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) + #if: github.ref_name == 'main' && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) + if: vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) run: ./tests/reportportal_conf.sh env: REPORT_PORTAL_API_KEY: ${{ secrets.REPORT_PORTAL_API_KEY }} From 0c686f281383766ea3004c272f7a13a519a0a67b Mon Sep 17 00:00:00 2001 From: Carine Bonnafous Date: Fri, 29 Nov 2024 10:56:48 +0100 Subject: [PATCH 4/6] Use patch rather than sed to patch reportportal/basic --- .github/workflows/ci.yml | 2 +- .../ReportPortalHTTPService.php.patch | 37 +++++++++++++++++++ tests/{ => reportportal}/reportportal_conf.sh | 18 ++++----- .../reportportal_phpunit_conf_template.xml | 0 4 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 tests/reportportal/ReportPortalHTTPService.php.patch rename tests/{ => reportportal}/reportportal_conf.sh (54%) rename tests/{ => reportportal}/reportportal_phpunit_conf_template.xml (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d50df52d..4d886bb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: # ReportPortal agent only works for PHP 7.1, 7.2, 7.3 and 7.4 #if: github.ref_name == 'main' && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) if: vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) - run: ./tests/reportportal_conf.sh + run: ./tests/reportportal/reportportal_conf.sh env: REPORT_PORTAL_API_KEY: ${{ secrets.REPORT_PORTAL_API_KEY }} REPORT_PORTAL_ENDPOINT: ${{ vars.REPORT_PORTAL_ENDPOINT }} diff --git a/tests/reportportal/ReportPortalHTTPService.php.patch b/tests/reportportal/ReportPortalHTTPService.php.patch new file mode 100644 index 00000000..23bdfdc7 --- /dev/null +++ b/tests/reportportal/ReportPortalHTTPService.php.patch @@ -0,0 +1,37 @@ +312c312 +< $result = self::$client->post('v1/' . self::$projectName . '/launch', array( +--- +> $result = self::$client->post('v2/' . self::$projectName . '/launch', array( +337c337 +< $result = self::$client->put('v1/' . self::$projectName . '/launch/' . self::$launchID . '/finish', array( +--- +> $result = self::$client->put('v2/' . self::$projectName . '/launch/' . self::$launchID . '/finish', array( +358c358 +< $result = self::$client->put('v1/' . self::$projectName . '/launch/' . self::$launchID . '/stop', array( +--- +> $result = self::$client->put('v2/' . self::$projectName . '/launch/' . self::$launchID . '/stop', array( +383c383 +< $result = self::$client->post('v1/' . self::$projectName . '/item', array( +--- +> $result = self::$client->post('v2/' . self::$projectName . '/item', array( +425c425 +< $result = self::$client->post('v1/' . self::$projectName . '/log', array( +--- +> $result = self::$client->post('v2/' . self::$projectName . '/log', array( +478c478 +< 'v1/' . self::$projectName . '/log', +--- +> 'v2/' . self::$projectName . '/log', +500c500 +< $result = self::$client->put('v1/' . self::$projectName . '/item/' . $itemID, array( +--- +> $result = self::$client->put('v2/' . self::$projectName . '/item/' . $itemID, array( +507c507,508 +< 'status' => $status +--- +> 'status' => $status, +> 'launchUuid' => self::$launchID +544c545 +< $result = self::$client->post('v1/' . self::$projectName . '/item/' . $parentItemID, array( +--- +> $result = self::$client->post('v2/' . self::$projectName . '/item/' . $parentItemID, array( diff --git a/tests/reportportal_conf.sh b/tests/reportportal/reportportal_conf.sh similarity index 54% rename from tests/reportportal_conf.sh rename to tests/reportportal/reportportal_conf.sh index 59d4581f..99d7c331 100755 --- a/tests/reportportal_conf.sh +++ b/tests/reportportal/reportportal_conf.sh @@ -6,19 +6,19 @@ if [ -z "$REPORT_PORTAL_API_KEY" ] || [ -z "$REPORT_PORTAL_ENDPOINT" ]; then exit 1 fi -# Remove /api/v1 from REPORT_PORTAL_ENDPOINT (reportportal/agent-php-PHPUnit requires only host) -export REPORT_PORTAL_HOST=${REPORT_PORTAL_ENDPOINT/\/api\/v1/} +# Remove /api/v1 or api/v2 from REPORT_PORTAL_ENDPOINT (reportportal/agent-php-PHPUnit requires only host) +export REPORT_PORTAL_HOST=${REPORT_PORTAL_ENDPOINT/\/api\/v[12]/} # Add secrets values in tests/reportportal_phpunit_conf_template.xml -# Following environment variables are required: +# Following environment variables are used: # REPORT_PORTAL_API_KEY # REPORT_PORTAL_HOST # PHP_VERSION -envsubst < tests/reportportal_phpunit_conf_template.xml > tests/reportportal_phpunit_conf.xml +envsubst < tests/reportportal/reportportal_phpunit_conf_template.xml > tests/reportportal/reportportal_phpunit_conf.xml # Add conf for ReportPortal extension in phpunit.ci.xml # Inserts content of file tests/reportportal_phpunit_conf.xml before end tag in phpunit.ci.xml -sed -i $'/<\/phpunit>/{e cat tests/reportportal_phpunit_conf.xml\n}' phpunit.ci.xml +sed -i $'/<\/phpunit>/{e cat tests/reportportal/reportportal_phpunit_conf.xml\n}' phpunit.ci.xml # Add ReportPortal extension to composer.json # reportportal/phpunit has no stable version, so we set minimum stability to dev only when running tests @@ -27,7 +27,7 @@ composer config minimum-stability dev composer require --dev reportportal/phpunit # Patch reportportal/basic to make it compatible with api/v2 -# Use api/v2 instead of api/v1 (hardcoded in reportportal/basic) -sed -i 's/v1\//v2\//g' vendor/reportportal/basic/src/service/ReportPortalHTTPService.php -# Add launchUuid to finishItem method in reportportal/basic to make it compatible with api/v2 -sed -i "/function finishItem/,/}/s/\('status' => \$status\)/\1,\n'launchUuid' => self::\$launchID/" vendor/reportportal/basic/src/service/ReportPortalHTTPService.php \ No newline at end of file +# Patch content: +# * Replace api/v1 (hardcoded in reportportal/basic) by api/v2 +# * Add launchUuid to finishItem method (otherwise all tests will be marked as "interrupted") +patch vendor/reportportal/basic/src/service/ReportPortalHTTPService.php tests/reportportal/ReportPortalHTTPService.php.patch diff --git a/tests/reportportal_phpunit_conf_template.xml b/tests/reportportal/reportportal_phpunit_conf_template.xml similarity index 100% rename from tests/reportportal_phpunit_conf_template.xml rename to tests/reportportal/reportportal_phpunit_conf_template.xml From 53c0cb81558b68a56668447476d8f95cc3a3dbd6 Mon Sep 17 00:00:00 2001 From: Carine Bonnafous Date: Fri, 29 Nov 2024 12:00:54 +0100 Subject: [PATCH 5/6] Revert "test: commit to be removed" This reverts commit 574d06b7bd35a7630787cbea72cba2b0e756d3aa. --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d886bb7..c677a405 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,8 +61,7 @@ jobs: - name: Set ReportPortal configuration # ReportPortal agent only works for PHP 7.1, 7.2, 7.3 and 7.4 - #if: github.ref_name == 'main' && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) - if: vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) + if: github.ref_name == 'main' && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) run: ./tests/reportportal/reportportal_conf.sh env: REPORT_PORTAL_API_KEY: ${{ secrets.REPORT_PORTAL_API_KEY }} From a20e4be82360426a730e28a0758bf1aa155f5498 Mon Sep 17 00:00:00 2001 From: Carine Bonnafous Date: Fri, 13 Dec 2024 09:56:41 +0100 Subject: [PATCH 6/6] Include develop branch --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c677a405..fd8b681b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: - name: Set ReportPortal configuration # ReportPortal agent only works for PHP 7.1, 7.2, 7.3 and 7.4 - if: github.ref_name == 'main' && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) + if: (github.ref_name == 'main' || github.ref_name == 'develop') && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php) run: ./tests/reportportal/reportportal_conf.sh env: REPORT_PORTAL_API_KEY: ${{ secrets.REPORT_PORTAL_API_KEY }}