From 8b63a83799ace5eba42dc727e7559803ee6d04a4 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Wed, 24 Jul 2024 17:31:19 +0200 Subject: [PATCH 1/5] chore(workflows):[#828] add new cucumber workflow with integration to Xray --- ...mber-integration-test-INT-association.yaml | 62 ++++++++ .../cucumber-integration-test-xray.yaml | 140 ++++++++++++++++++ .../irs/cucumber/RunCucumberTest.java | 2 +- 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cucumber-integration-test-INT-association.yaml create mode 100644 .github/workflows/cucumber-integration-test-xray.yaml diff --git a/.github/workflows/cucumber-integration-test-INT-association.yaml b/.github/workflows/cucumber-integration-test-INT-association.yaml new file mode 100644 index 0000000000..9d7c7baa9d --- /dev/null +++ b/.github/workflows/cucumber-integration-test-INT-association.yaml @@ -0,0 +1,62 @@ +name: IRS Association INT Cucumber Integration test execution + +on: + workflow_dispatch: # Trigger manually + +# Cancel previous Test executions if a new one is triggered. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + + check-config: + runs-on: ubuntu-latest + steps: + - name: Check if INT_REGULAR_USER_API_KEY is defined + run: | + if [[ -z "${{ secrets.INT_REGULAR_USER_API_KEY }}" ]]; then + echo "Error: Missing secret: Please configure INT_REGULAR_USER_API_KEY." + exit 1 + fi + - name: Check if INT_ADMIN_USER_API_KEY is defined + run: | + if [[ -z "${{ secrets.INT_ADMIN_USER_API_KEY }}" ]]; then + echo "Error: Missing secret: Please configure INT_ADMIN_USER_API_KEY." + exit 1 + fi + - name: Check if IRS_CUCUMBER_PUBLISH_TOKEN is defined + run: | + if [[ -z "${{ secrets.IRS_CUCUMBER_PUBLISH_TOKEN }}" ]]; then + echo "Error: Missing secret: Please configure IRS_CUCUMBER_PUBLISH_TOKEN." + exit 1 + fi + shell: bash + - name: Check if is defined jiraUser is defined + run: | + if [[ -z "${{ secrets.IRS_XRAY_JIRA_USER }}" ]]; then + echo "Error: Missing secret: Please configure IRS_XRAY_JIRA_USER." + exit 1 + fi + - name: Check if is defined jiraUser is defined + run: | + if [[ -z "${{ secrets.IRS_XRAY_JIRA_SECRET }}" ]]; then + echo "Error: Missing secret: Please configure IRS_XRAY_JIRA_SECRET." + exit 1 + fi + + trigger-integration-test: + needs: check-config + uses: ./.github/workflows/cucumber-integration-test-xray.yaml + secrets: + # TODO set secrets in GH + regularUserApiKey: ${{ secrets.INT_REGULAR_USER_API_KEY }} + adminUserApiKey: ${{ secrets.INT_ADMIN_USER_API_KEY }} + cucumberPublishToken: ${{ secrets.IRS_CUCUMBER_PUBLISH_TOKEN }} + jiraUser: ${{ secrets.jiraUser }} + jiraPassword: ${{ secrets.jiraPassword }} + with: + executionFilter: "!Ignore & !INACTIVE & INTEGRATION_TEST & INT" + # JIRA filter 10001: project = TRI AND type = Test AND "Test Type" = Cucumber TODO set correct filter description + exportFilter: 10001 + diff --git a/.github/workflows/cucumber-integration-test-xray.yaml b/.github/workflows/cucumber-integration-test-xray.yaml new file mode 100644 index 0000000000..38d6c39c02 --- /dev/null +++ b/.github/workflows/cucumber-integration-test-xray.yaml @@ -0,0 +1,140 @@ +name: IRS Cucumber Integration Test execution with Xray + +on: + workflow_call: # Trigger by another workflow + secrets: + regularUserApiKey: + required: true + adminUserApiKey: + required: true + cucumberPublishToken: + required: true + jiraUser: + required: true + jiraPassword: + required: true + inputs: + executionFilter: + required: true + type: string + exportFilter: + required: true + type: string + +jobs: + + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Cache maven packages + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + + - name: Download Feature Files + id: download + env: + JIRA_USERNAME: ${{ secrets.jiraUser }} + JIRA_PASSWORD: ${{ secrets.jiraPassword }} + EXPORT_FILTER: ${{ inputs.exportFilter }} + # Downloads all feature files of cucumber tests inside TRI project + run: | + token=$(curl -H "Content-Type: application/json" -X POST \ + --data "{ \"client_id\": \"$JIRA_USERNAME\",\"client_secret\": \"$JIRA_PASSWORD\" }" \ + https://xray.cloud.getxray.app/api/v2/authenticate | tr -d '"') + + export HTTP_RESULT=$(curl -s --show-error -w "%{http_code}" --header "Authorization: Bearer $token" \ + "https://xray.cloud.getxray.app/api/v2/export/cucumber?filter=$EXPORT_FILTER&fz=true" -o features.zip) + + [[ $HTTP_RESULT == 200 || $HTTP_RESULT == 400 ]] + echo "::set-output name=http_response::$HTTP_RESULT" + + - name: Build with Maven + if: ${{ steps.download.outputs.http_response == '200' }} + env: + KEYCLOAK_HOST: ${{ secrets.keycloakTokenUrl }} + KEYCLOAK_CLIENT_ID: ${{ secrets.clientId }} + KEYCLOAK_CLIENT_SECRET: ${{ secrets.clientSecret }} + ISSUE_FILTER: ${{ inputs.executionFilter }} + run: | + unzip -o features.zip -d irs-cucumber-tests/src/test/resources/org/eclipse/tractusx/irs/cucumber/features + mvn --batch-mode clean install -pl irs-cucumber-tests,irs-models -D"cucumber.filter.tags"="$ISSUE_FILTER" + + - name: Submit results to Xray + if: ${{ always() && steps.download.outputs.http_response == '200' }} + env: + JIRA_USERNAME: ${{ secrets.jiraUser }} + JIRA_PASSWORD: ${{ secrets.jiraPassword }} + run: | + token=$(curl -H "Content-Type: application/json" -X POST \ + --data "{ \"client_id\": \"$JIRA_USERNAME\",\"client_secret\": \"$JIRA_PASSWORD\" }" \ + https://xray.cloud.getxray.app/api/v2/authenticate | tr -d '"') + + curl --request POST \ + --header 'Content-Type: application/json' \ + --header "Authorization: Bearer $token" \ + --data-binary '@irs-cucumber-tests/target/report.json' \ + "https://xray.cloud.getxray.app/api/v2/import/execution/cucumber" + + - name: Run Tests with Maven + env: + REGULAR_USER_API_KEY: ${{ secrets.regularUserApiKey }} + ADMIN_USER_API_KEY: ${{ secrets.adminUserApiKey }} + ISSUE_FILTER: ${{ inputs.executionFilter }} + CUCUMBER_PUBLISH_TOKEN: ${{ secrets.cucumberPublishToken }} + run: | + # workaround replacement since injecting the token via environment variable does not work + sed -i "s/CUCUMBER_TOKEN_IRS_PLACEHOLDER/${CUCUMBER_PUBLISH_TOKEN}/g" irs-cucumber-tests/src/test/java/org/eclipse/tractusx/irs/cucumber/RunCucumberTest.java + + mvn clean verify -P cucumber -Dgroups="$ISSUE_FILTER" -pl irs-cucumber-tests -am --batch-mode 2> irs-cucumber-tests/report-banner.txt + + - name: Publish Cucumber Results + uses: EnricoMi/publish-unit-test-result-action@v2.17.0 + if: always() + with: + files: | + irs-cucumber-tests/target/cucumber-junit-report.xml + + - name: Get Cucumber Report + if: always() + id: get-cucumber-report + run: | + grep -E "^│.*│$" irs-cucumber-tests/report-banner.txt > irs-cucumber-tests/cucumber-report.txt + sed -i 's/│//g' irs-cucumber-tests/cucumber-report.txt + cat irs-cucumber-tests/cucumber-report.txt + cat irs-cucumber-tests/cucumber-report.txt >> $GITHUB_STEP_SUMMARY + + - name: Find previous comment in PR + if: always() && github.event_name == 'pull_request' + uses: peter-evans/find-comment@v3 + id: find-comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: 'View your Cucumber Report at' + + - name: Create or update comment in PR + if: always() && github.event_name == 'pull_request' + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.find-comment.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body-path: 'irs-cucumber-tests/cucumber-report.txt' + edit-mode: replace + + - name: Upload Report + if: always() + uses: actions/upload-artifact@v4 + with: + path: 'irs-cucumber-tests/target/report.html' diff --git a/irs-cucumber-tests/src/test/java/org/eclipse/tractusx/irs/cucumber/RunCucumberTest.java b/irs-cucumber-tests/src/test/java/org/eclipse/tractusx/irs/cucumber/RunCucumberTest.java index ac1fd087f3..8476a2111d 100644 --- a/irs-cucumber-tests/src/test/java/org/eclipse/tractusx/irs/cucumber/RunCucumberTest.java +++ b/irs-cucumber-tests/src/test/java/org/eclipse/tractusx/irs/cucumber/RunCucumberTest.java @@ -36,6 +36,6 @@ @ConfigurationParameter(key = PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME, value = "CUCUMBER_TOKEN_IRS_PLACEHOLDER") @ConfigurationParameter(key = ANSI_COLORS_DISABLED_PROPERTY_NAME, value = "true") @ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, - value = "pretty,junit:target/cucumber-junit-report.xml,html:target/report.html") + value = "pretty,junit:target/cucumber-junit-report.xml,html:target/report.html,json:target/report.json") public class RunCucumberTest { } From daba686a79113bdce0f31918b1779adf57bebcbf Mon Sep 17 00:00:00 2001 From: jhartmann Date: Thu, 25 Jul 2024 15:04:48 +0200 Subject: [PATCH 2/5] chore(workflows):[#828] update Jira filter --- .../workflows/cucumber-integration-test-INT-association.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cucumber-integration-test-INT-association.yaml b/.github/workflows/cucumber-integration-test-INT-association.yaml index 9d7c7baa9d..3a12d46397 100644 --- a/.github/workflows/cucumber-integration-test-INT-association.yaml +++ b/.github/workflows/cucumber-integration-test-INT-association.yaml @@ -49,14 +49,13 @@ jobs: needs: check-config uses: ./.github/workflows/cucumber-integration-test-xray.yaml secrets: - # TODO set secrets in GH regularUserApiKey: ${{ secrets.INT_REGULAR_USER_API_KEY }} adminUserApiKey: ${{ secrets.INT_ADMIN_USER_API_KEY }} cucumberPublishToken: ${{ secrets.IRS_CUCUMBER_PUBLISH_TOKEN }} jiraUser: ${{ secrets.jiraUser }} jiraPassword: ${{ secrets.jiraPassword }} with: - executionFilter: "!Ignore & !INACTIVE & INTEGRATION_TEST & INT" - # JIRA filter 10001: project = TRI AND type = Test AND "Test Type" = Cucumber TODO set correct filter description + executionFilter: "!Ignore& !INACTIVE & IRS & INT & POLICY_STORE" + # JIRA filter 10001: project = CXTM AND labels = "INT" AND labels = "IRS" AND status = Ready AND testType = Cucumber exportFilter: 10001 From ad144ce57d128fcc94f98b1f6890a78a7c6b6a46 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Fri, 26 Jul 2024 09:21:35 +0200 Subject: [PATCH 3/5] chore(testdata):[#226] add inputs for executionFilter and exportFilter --- .../cucumber-integration-test-INT-association.yaml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cucumber-integration-test-INT-association.yaml b/.github/workflows/cucumber-integration-test-INT-association.yaml index 3a12d46397..c5f30fac27 100644 --- a/.github/workflows/cucumber-integration-test-INT-association.yaml +++ b/.github/workflows/cucumber-integration-test-INT-association.yaml @@ -2,6 +2,15 @@ name: IRS Association INT Cucumber Integration test execution on: workflow_dispatch: # Trigger manually + inputs: + executionFilter: + description: 'Execution filter' + required: false + default: '!Ignore & !INACTIVE & INTEGRATION_TEST & DEV' + exportFilter: + description: 'Jira export filter' + required: false + default: '10001' # Cancel previous Test executions if a new one is triggered. concurrency: @@ -55,7 +64,7 @@ jobs: jiraUser: ${{ secrets.jiraUser }} jiraPassword: ${{ secrets.jiraPassword }} with: - executionFilter: "!Ignore& !INACTIVE & IRS & INT & POLICY_STORE" + executionFilter: ${{ github.event.inputs.executionFilter || '!Ignore& !INACTIVE & IRS & INT & POLICY_STORE' }} # JIRA filter 10001: project = CXTM AND labels = "INT" AND labels = "IRS" AND status = Ready AND testType = Cucumber - exportFilter: 10001 + exportFilter: ${{ github.event.inputs.exportFilter || '10001' }} From d4503224e8dbf1bbc9735389fa2071a8237a857f Mon Sep 17 00:00:00 2001 From: jhartmann Date: Fri, 26 Jul 2024 11:03:09 +0200 Subject: [PATCH 4/5] chore(workflows):[#828] fix secret names --- .../cucumber-integration-test-INT-association.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cucumber-integration-test-INT-association.yaml b/.github/workflows/cucumber-integration-test-INT-association.yaml index c5f30fac27..b276e841c3 100644 --- a/.github/workflows/cucumber-integration-test-INT-association.yaml +++ b/.github/workflows/cucumber-integration-test-INT-association.yaml @@ -43,13 +43,13 @@ jobs: shell: bash - name: Check if is defined jiraUser is defined run: | - if [[ -z "${{ secrets.IRS_XRAY_JIRA_USER }}" ]]; then + if [[ -z "${{ secrets.ASSOCIATION_TX_JIRA_USERNAME }}" ]]; then echo "Error: Missing secret: Please configure IRS_XRAY_JIRA_USER." exit 1 fi - name: Check if is defined jiraUser is defined run: | - if [[ -z "${{ secrets.IRS_XRAY_JIRA_SECRET }}" ]]; then + if [[ -z "${{ secrets.ASSOCIATION_TX_JIRA_PASSWORD }}" ]]; then echo "Error: Missing secret: Please configure IRS_XRAY_JIRA_SECRET." exit 1 fi @@ -61,8 +61,8 @@ jobs: regularUserApiKey: ${{ secrets.INT_REGULAR_USER_API_KEY }} adminUserApiKey: ${{ secrets.INT_ADMIN_USER_API_KEY }} cucumberPublishToken: ${{ secrets.IRS_CUCUMBER_PUBLISH_TOKEN }} - jiraUser: ${{ secrets.jiraUser }} - jiraPassword: ${{ secrets.jiraPassword }} + jiraUser: ${{ secrets.ASSOCIATION_TX_JIRA_USERNAME }} + jiraPassword: ${{ secrets.ASSOCIATION_TX_JIRA_PASSWORD }} with: executionFilter: ${{ github.event.inputs.executionFilter || '!Ignore& !INACTIVE & IRS & INT & POLICY_STORE' }} # JIRA filter 10001: project = CXTM AND labels = "INT" AND labels = "IRS" AND status = Ready AND testType = Cucumber From a11787212e5d5f4cbe1842e407a41f9b0fb161e7 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Fri, 26 Jul 2024 11:13:50 +0200 Subject: [PATCH 5/5] chore(workflows):[#828] fix cucumber test execution order --- .../cucumber-integration-test-xray.yaml | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cucumber-integration-test-xray.yaml b/.github/workflows/cucumber-integration-test-xray.yaml index 38d6c39c02..1ffb08e1a3 100644 --- a/.github/workflows/cucumber-integration-test-xray.yaml +++ b/.github/workflows/cucumber-integration-test-xray.yaml @@ -48,7 +48,7 @@ jobs: JIRA_USERNAME: ${{ secrets.jiraUser }} JIRA_PASSWORD: ${{ secrets.jiraPassword }} EXPORT_FILTER: ${{ inputs.exportFilter }} - # Downloads all feature files of cucumber tests inside TRI project + # Downloads all IRS feature files of cucumber tests run: | token=$(curl -H "Content-Type: application/json" -X POST \ --data "{ \"client_id\": \"$JIRA_USERNAME\",\"client_secret\": \"$JIRA_PASSWORD\" }" \ @@ -60,16 +60,20 @@ jobs: [[ $HTTP_RESULT == 200 || $HTTP_RESULT == 400 ]] echo "::set-output name=http_response::$HTTP_RESULT" - - name: Build with Maven + - name: Run Tests with Maven if: ${{ steps.download.outputs.http_response == '200' }} env: - KEYCLOAK_HOST: ${{ secrets.keycloakTokenUrl }} - KEYCLOAK_CLIENT_ID: ${{ secrets.clientId }} - KEYCLOAK_CLIENT_SECRET: ${{ secrets.clientSecret }} + REGULAR_USER_API_KEY: ${{ secrets.regularUserApiKey }} + ADMIN_USER_API_KEY: ${{ secrets.adminUserApiKey }} ISSUE_FILTER: ${{ inputs.executionFilter }} + CUCUMBER_PUBLISH_TOKEN: ${{ secrets.cucumberPublishToken }} run: | unzip -o features.zip -d irs-cucumber-tests/src/test/resources/org/eclipse/tractusx/irs/cucumber/features - mvn --batch-mode clean install -pl irs-cucumber-tests,irs-models -D"cucumber.filter.tags"="$ISSUE_FILTER" + + # workaround replacement since injecting the token via environment variable does not work + sed -i "s/CUCUMBER_TOKEN_IRS_PLACEHOLDER/${CUCUMBER_PUBLISH_TOKEN}/g" irs-cucumber-tests/src/test/java/org/eclipse/tractusx/irs/cucumber/RunCucumberTest.java + + mvn clean verify -P cucumber -Dgroups="$ISSUE_FILTER" -pl irs-cucumber-tests -am --batch-mode 2> irs-cucumber-tests/report-banner.txt - name: Submit results to Xray if: ${{ always() && steps.download.outputs.http_response == '200' }} @@ -87,18 +91,6 @@ jobs: --data-binary '@irs-cucumber-tests/target/report.json' \ "https://xray.cloud.getxray.app/api/v2/import/execution/cucumber" - - name: Run Tests with Maven - env: - REGULAR_USER_API_KEY: ${{ secrets.regularUserApiKey }} - ADMIN_USER_API_KEY: ${{ secrets.adminUserApiKey }} - ISSUE_FILTER: ${{ inputs.executionFilter }} - CUCUMBER_PUBLISH_TOKEN: ${{ secrets.cucumberPublishToken }} - run: | - # workaround replacement since injecting the token via environment variable does not work - sed -i "s/CUCUMBER_TOKEN_IRS_PLACEHOLDER/${CUCUMBER_PUBLISH_TOKEN}/g" irs-cucumber-tests/src/test/java/org/eclipse/tractusx/irs/cucumber/RunCucumberTest.java - - mvn clean verify -P cucumber -Dgroups="$ISSUE_FILTER" -pl irs-cucumber-tests -am --batch-mode 2> irs-cucumber-tests/report-banner.txt - - name: Publish Cucumber Results uses: EnricoMi/publish-unit-test-result-action@v2.17.0 if: always()