Skip to content

Commit

Permalink
Use patch rather than sed to patch reportportal/basic
Browse files Browse the repository at this point in the history
  • Loading branch information
carine-bonnafous committed Nov 29, 2024
1 parent 574d06b commit df07bb3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
37 changes: 37 additions & 0 deletions tests/reportportal/ReportPortalHTTPService.php.patch
Original file line number Diff line number Diff line change
@@ -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(
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# 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 </phpunit> 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
Expand All @@ -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
# 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

0 comments on commit df07bb3

Please sign in to comment.