Skip to content

Commit

Permalink
ACS-6300 Add a static-name flag for reportportal-prepare action (#386)
Browse files Browse the repository at this point in the history
Co-authored-by: Domenico Sibilio <[email protected]>
Co-authored-by: Anahide Tchertchian <[email protected]>
  • Loading branch information
3 people authored Nov 27, 2023
1 parent ae5cb88 commit 3b6fc84
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .github/actions/reportportal-prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions .github/actions/reportportal-prepare/get-rp-input.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,14 +75,34 @@ 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)"
[ "$(< $GITHUB_OUTPUT)" = "$expected" ]
[ "$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"

Expand All @@ -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)"
Expand All @@ -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)"
Expand All @@ -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)"
Expand Down
13 changes: 11 additions & 2 deletions .github/actions/reportportal-summarize/get-rp-output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v5.0.1
v5.1.0

0 comments on commit 3b6fc84

Please sign in to comment.