From 3b6fc845ab020bf794ea9e75577662c9c54d2e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojtek=20=C5=9Awi=C4=99to=C5=84?= Date: Mon, 27 Nov 2023 11:04:36 +0100 Subject: [PATCH] ACS-6300 Add a static-name flag for reportportal-prepare action (#386) Co-authored-by: Domenico Sibilio Co-authored-by: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> --- .../actions/reportportal-prepare/action.yml | 5 ++++ .../reportportal-prepare/get-rp-input.sh | 6 ++-- .../tests/reportportal-prepare.bats | 29 ++++++++++++++++--- .../reportportal-summarize/get-rp-output.sh | 13 +++++++-- docs/README.md | 7 +++-- version.txt | 2 +- 6 files changed, 51 insertions(+), 11 deletions(-) diff --git a/.github/actions/reportportal-prepare/action.yml b/.github/actions/reportportal-prepare/action.yml index 9db4d28ba..fb7b1412a 100644 --- a/.github/actions/reportportal-prepare/action.yml +++ b/.github/actions/reportportal-prepare/action.yml @@ -17,6 +17,10 @@ inputs: rp-extra-attributes: description: Extra attributes for Report Portal required: false + rp-use-static-launch-name: + description: If set, the rp-launch-prefix will be used as the full launch name in Report Portal + required: false + default: "false" auto-configure: description: >- Enables automated default configuration (adds default GitHub context @@ -54,4 +58,5 @@ runs: RP_PROJECT: ${{ inputs.rp-project }} RP_EXTRA_ATTRIBUTES: ${{ inputs.rp-extra-attributes }} AUTO: ${{ inputs.auto-configure }} + USE_STATIC_LAUNCH_NAME: ${{ inputs.rp-use-static-launch-name }} run: ${{ github.action_path }}/get-rp-input.sh diff --git a/.github/actions/reportportal-prepare/get-rp-input.sh b/.github/actions/reportportal-prepare/get-rp-input.sh index 937c0f7aa..f6a9a6a5f 100755 --- a/.github/actions/reportportal-prepare/get-rp-input.sh +++ b/.github/actions/reportportal-prepare/get-rp-input.sh @@ -4,7 +4,7 @@ if [[ -n "$RP_LAUNCH_PREFIX" && -n "$RP_TOKEN" && -n "$RP_URL" && -n "$RP_PROJEC echo "enabled=true" >> $GITHUB_OUTPUT RP_LAUNCH_KEY="$RP_LAUNCH_PREFIX" - if [[ "$AUTO" == "true" ]]; then + if [[ "$AUTO" == "true" && "$USE_STATIC_LAUNCH_NAME" == "false" ]]; then RP_LAUNCH_KEY="$RP_LAUNCH_PREFIX-$GITHUB_EVENT_NAME-$GITHUB_RUN_ID" fi echo "key=$RP_LAUNCH_KEY" >> $GITHUB_OUTPUT @@ -23,7 +23,9 @@ if [[ -n "$RP_LAUNCH_PREFIX" && -n "$RP_TOKEN" && -n "$RP_URL" && -n "$RP_PROJEC OPTS+=' "'-Drp.project="$RP_PROJECT"'"' if [[ "$AUTO" == "true" ]]; then OPTS+=' "'-Drp.description=["$RUN_TITLE"]\("$RUN_URL"\)'"' - OPTS+=' "'-Drp.attributes='branch:'"$BRANCH_NAME"';event:'"$GITHUB_EVENT_NAME"';repository:'"$GITHUB_REPOSITORY"';run:'"$RP_LAUNCH_KEY$RP_EXTRA_ATTRIBUTES"'"' + OPTS+=' "'-Drp.attributes='branch:'"$BRANCH_NAME"';event:'"$GITHUB_EVENT_NAME"';repository:'"$GITHUB_REPOSITORY"';ghrun:'"$GITHUB_RUN_ID"';run:'"$RP_LAUNCH_KEY$RP_EXTRA_ATTRIBUTES"'"' + else + OPTS+=' "'-Drp.attributes='ghrun:'"$GITHUB_RUN_ID$RP_EXTRA_ATTRIBUTES"'"' fi echo "mvn-opts=$OPTS" >> $GITHUB_OUTPUT diff --git a/.github/actions/reportportal-prepare/tests/reportportal-prepare.bats b/.github/actions/reportportal-prepare/tests/reportportal-prepare.bats index f1e48e840..5d95c3b87 100644 --- a/.github/actions/reportportal-prepare/tests/reportportal-prepare.bats +++ b/.github/actions/reportportal-prepare/tests/reportportal-prepare.bats @@ -11,6 +11,7 @@ setup() { export RP_URL=https://rpserver:8080 export RP_PROJECT=my-project export AUTO=true + export USE_STATIC_LAUNCH_NAME=false export BRANCH_NAME=main export GITHUB_SERVER_URL=https://github.com @@ -74,7 +75,7 @@ teardown() { enabled=true key=my-tests-push-3665876492 url=https://rpserver:8080/ui/#my-project/launches/all -mvn-opts="-Drp.launch=my-tests-push-3665876492" "-Drp.uuid=tok" "-Drp.endpoint=https://rpserver:8080" "-Drp.project=my-project" "-Drp.description=[Run on GitHub Actions 3665876492](https://github.com/mygh/repo/actions/runs/3665876492)" "-Drp.attributes=branch:main;event:push;repository:mygh/repo;run:my-tests-push-3665876492" +mvn-opts="-Drp.launch=my-tests-push-3665876492" "-Drp.uuid=tok" "-Drp.endpoint=https://rpserver:8080" "-Drp.project=my-project" "-Drp.description=[Run on GitHub Actions 3665876492](https://github.com/mygh/repo/actions/runs/3665876492)" "-Drp.attributes=branch:main;event:push;repository:mygh/repo;ghrun:3665876492;run:my-tests-push-3665876492" BATS ) echo "$(< $GITHUB_OUTPUT)" @@ -82,6 +83,26 @@ BATS [ "$output" = "$ECHO_ENABLED" ] } +@test "rp enabled static" { + export USE_STATIC_LAUNCH_NAME="true" + + run get-rp-input.sh + [ "$status" -eq 0 ] + + expected=$(cat << BATS +enabled=true +key=my-tests +url=https://rpserver:8080/ui/#my-project/launches/all +mvn-opts="-Drp.launch=my-tests" "-Drp.uuid=tok" "-Drp.endpoint=https://rpserver:8080" "-Drp.project=my-project" "-Drp.description=[Run on GitHub Actions 3665876492](https://github.com/mygh/repo/actions/runs/3665876492)" "-Drp.attributes=branch:main;event:push;repository:mygh/repo;ghrun:3665876492;run:my-tests" +BATS +) + echo "$(< $GITHUB_OUTPUT)" + [ "$(< $GITHUB_OUTPUT)" = "$expected" ] + expected_echo="Report Portal key=my-tests, url=https://rpserver:8080/ui/#my-project/launches/all" + echo "$output" + [ "$output" = "$expected_echo" ] +} + @test "rp enabled extra" { export RP_EXTRA_ATTRIBUTES=";metafilter:+smoke" @@ -92,7 +113,7 @@ BATS enabled=true key=my-tests-push-3665876492 url=https://rpserver:8080/ui/#my-project/launches/all -mvn-opts="-Drp.launch=my-tests-push-3665876492" "-Drp.uuid=tok" "-Drp.endpoint=https://rpserver:8080" "-Drp.project=my-project" "-Drp.description=[Run on GitHub Actions 3665876492](https://github.com/mygh/repo/actions/runs/3665876492)" "-Drp.attributes=branch:main;event:push;repository:mygh/repo;run:my-tests-push-3665876492;metafilter:+smoke" +mvn-opts="-Drp.launch=my-tests-push-3665876492" "-Drp.uuid=tok" "-Drp.endpoint=https://rpserver:8080" "-Drp.project=my-project" "-Drp.description=[Run on GitHub Actions 3665876492](https://github.com/mygh/repo/actions/runs/3665876492)" "-Drp.attributes=branch:main;event:push;repository:mygh/repo;ghrun:3665876492;run:my-tests-push-3665876492;metafilter:+smoke" BATS ) echo "$(< $GITHUB_OUTPUT)" @@ -112,7 +133,7 @@ BATS enabled=true key=my-tests-with-id url=https://rpserver:8080/ui/#my-project/launches/all -mvn-opts="-Drp.launch=my-tests-with-id" "-Drp.uuid=tok" "-Drp.endpoint=https://rpserver:8080" "-Drp.project=my-project" +mvn-opts="-Drp.launch=my-tests-with-id" "-Drp.uuid=tok" "-Drp.endpoint=https://rpserver:8080" "-Drp.project=my-project" "-Drp.attributes=ghrun:3665876492;metafilter:+smoke" BATS ) echo "$(< $GITHUB_OUTPUT)" @@ -137,7 +158,7 @@ BATS enabled=true key=my launch prefix with spaces-weird event-3665876492 url=https://rpserver:8080 with spaces too/ui/#my project with spaces/launches/all -mvn-opts="-Drp.launch=my launch prefix with spaces-weird event-3665876492" "-Drp.uuid=with some more spaces" "-Drp.endpoint=https://rpserver:8080 with spaces too" "-Drp.project=my project with spaces" "-Drp.description=[Run on GitHub Actions 3665876492](https://github.com/mygh/repo/actions/runs/3665876492)" "-Drp.attributes=branch:main;event:weird event;repository:mygh/repo;run:my launch prefix with spaces-weird event-3665876492" +mvn-opts="-Drp.launch=my launch prefix with spaces-weird event-3665876492" "-Drp.uuid=with some more spaces" "-Drp.endpoint=https://rpserver:8080 with spaces too" "-Drp.project=my project with spaces" "-Drp.description=[Run on GitHub Actions 3665876492](https://github.com/mygh/repo/actions/runs/3665876492)" "-Drp.attributes=branch:main;event:weird event;repository:mygh/repo;ghrun:3665876492;run:my launch prefix with spaces-weird event-3665876492" BATS ) echo "$(< $GITHUB_OUTPUT)" diff --git a/.github/actions/reportportal-summarize/get-rp-output.sh b/.github/actions/reportportal-summarize/get-rp-output.sh index 5e4542647..962d5b2a5 100755 --- a/.github/actions/reportportal-summarize/get-rp-output.sh +++ b/.github/actions/reportportal-summarize/get-rp-output.sh @@ -3,12 +3,21 @@ CONTENT='' URL='' +# support spaces on launch key +urlEncode() { + echo $1 | curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" | sed -E 's/..(.*).../\1/' +} + if [[ -n "$RP_LAUNCH_KEY" && -n "$RP_TOKEN" && -n "$RP_URL" && -n "$RP_PROJECT" ]] then echo "enabled=true" >> $GITHUB_OUTPUT - SEARCH_URL="$RP_URL/api/v1/$RP_PROJECT/launch?filter.cnt.name=$RP_LAUNCH_KEY&page.sort=startTime%2Cnumber%2CDESC" - CONTENT=$(curl -s -X GET "$SEARCH_URL" -H "accept: */*" -H "Authorization: bearer $RP_TOKEN") || CONTENT='' + CONTENT=$(curl -s -G -X GET "$RP_URL/api/v1/$RP_PROJECT/launch" \ + -d "filter.cnt.name=$(urlEncode "$RP_LAUNCH_KEY")" \ + -d "filter.has.compositeAttribute=ghrun:$GITHUB_RUN_ID" \ + -d "page.sort=startTime,number,DESC" \ + -H "Authorization: bearer $RP_TOKEN" \ + ) || CONTENT='' URL="$RP_URL/ui/#$RP_PROJECT/launches/all" else diff --git a/docs/README.md b/docs/README.md index f14fc7eba..1710948f8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -949,16 +949,19 @@ This action is usually used in combination with [reportportal-summarize](#report In particular, this prepares maven command line options for Report Portal integration, building the endpoint, authentication, launch key, description. Default context information is also added (launch attributes), unless the `auto-configure` input is set to `false`. +By using the `rp-use-static-launch-name` flag, you can determine whether the launch name in Report Portal should be static or unique for each execution. By default, it is set to `false`. +Setting it to `true` means that the value from 'rp-launch-prefix' will be used as the full launch name. + Sample options with auto-configuration: ```bash -"-Drp.launch=short-run-push-3674979523" "-Drp.uuid=***" "-Drp.endpoint=http://localhost:8080" "-Drp.project=my-project" "-Drp.description=[Run on GitHub Actions 3674979523](https://github.com/Alfresco/alfresco-build-tools/actions/runs/3674979523)" "-Drp.attributes=branch:my-branch;event:push;repository:Alfresco/alfresco-build-tools;run:short-run-push-3674979523;myattribute:my-filter" +"-Drp.launch=short-run-push-3674979523" "-Drp.uuid=***" "-Drp.endpoint=http://localhost:8080" "-Drp.project=my-project" "-Drp.description=[Run on GitHub Actions 3674979523](https://github.com/Alfresco/alfresco-build-tools/actions/runs/3674979523)" "-Drp.attributes=branch:my-branch;event:push;repository:Alfresco/alfresco-build-tools;ghrun:3674979523;run:short-run-push-3674979523;myattribute:my-filter" ``` Sample options without auto-configuration: ```bash -"-Drp.launch=short-run-push" "-Drp.uuid=***" "-Drp.endpoint=http://localhost:8080" "-Drp.project=my-project" +"-Drp.launch=short-run-push" "-Drp.uuid=***" "-Drp.endpoint=http://localhost:8080" "-Drp.project=my-project" "-Drp.attributes=ghrun:3674979523" ``` Sample usage: diff --git a/version.txt b/version.txt index 4bccc27e8..6b7ace3e9 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v5.0.1 +v5.1.0