From b09403f117aa2b7445208e2699d6845f8a2d6fe4 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Tue, 15 Mar 2022 17:01:33 +0100 Subject: [PATCH 01/13] use test reports in sonar format --- .github/workflows/main.yml | 8 ++++++++ code/project.clj | 5 +++-- code/sonar-project.properties | 1 + code/src/sixsq/nuvla/server/error.clj | 9 +++++++++ code/test/sixsq/nuvla/server/error_test.clj | 7 +++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 code/src/sixsq/nuvla/server/error.clj create mode 100644 code/test/sixsq/nuvla/server/error_test.clj diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8f899b2..1ba6121 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,6 +46,14 @@ jobs: -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} + - name: debug + run: | + echo --------- + cat code/.scannerwork/report-task.txt || true + echo --------- + cat code/test-reports/sonar/testExecutions.xml || true + echo --------- + - name: Get list of tests if: always() id: tests diff --git a/code/project.clj b/code/project.clj index 2c67bf0..930c76e 100644 --- a/code/project.clj +++ b/code/project.clj @@ -41,6 +41,7 @@ :profiles {:test {:source-paths ["test"] :resource-paths ["test-resources"] - :plugins [[lein-test-report-junit-xml "0.2.0"]] - :test-report-junit-xml {:output-dir "test-reports"}} + :plugins [[org.clojars.konstan/lein-test-report-sonar "0.0.3"]] + :test-report-sonar {:output-dir "test-reports" + :emit-junit-xml true}} :dev {:dependencies [[clj-kondo "RELEASE"]]}}) diff --git a/code/sonar-project.properties b/code/sonar-project.properties index 77f32d2..a03c455 100644 --- a/code/sonar-project.properties +++ b/code/sonar-project.properties @@ -12,3 +12,4 @@ sonar.clojure.nvd.json-output-location=target/nvd/dependency-check-report.json sonar.clojure.cloverage.enabled=true sonar.clojure.cloverage.json-output-location=target/coverage/codecov.json +sonar.testExecutionReportPaths=test-reports/sonar/testExecutions.xml \ No newline at end of file diff --git a/code/src/sixsq/nuvla/server/error.clj b/code/src/sixsq/nuvla/server/error.clj new file mode 100644 index 0000000..1de551c --- /dev/null +++ b/code/src/sixsq/nuvla/server/error.clj @@ -0,0 +1,9 @@ +(ns sixsq.nuvla.server.error) + +(defn sum + [a b] + (+ a b)) + +(defn mult + [a b] + (* a b)) diff --git a/code/test/sixsq/nuvla/server/error_test.clj b/code/test/sixsq/nuvla/server/error_test.clj new file mode 100644 index 0000000..271234a --- /dev/null +++ b/code/test/sixsq/nuvla/server/error_test.clj @@ -0,0 +1,7 @@ +(ns sixsq.nuvla.server.error-test + (:require + [clojure.test :refer :all] + [sixsq.nuvla.server.error :as e])) + +(deftest test-sum + (is (= 2 (e/sum 1 1)))) From 28aee580de0343c33a58ccd9719e10b41fd4b516 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Tue, 15 Mar 2022 17:07:17 +0100 Subject: [PATCH 02/13] JUnit test report were moved under xml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ba6121..997412f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,7 +59,7 @@ jobs: id: tests uses: Rishabh510/Path-lister-action@master with: - path: "code/test-reports" + path: "code/test-reports/xml" type: ".xml" - name: Fail on failed tests @@ -124,7 +124,7 @@ jobs: uses: EnricoMi/publish-unit-test-result-action@v1 if: always() with: - files: code/test-reports/TEST-*.xml + files: code/test-reports/xml/TEST-*.xml job-notify: if: always() From 468e744714eca05ee1e685922ca11d30c1c47e1b Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Tue, 15 Mar 2022 17:27:55 +0100 Subject: [PATCH 03/13] attempt to fix libxml2-utils install issue --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 997412f..e78beb8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -65,7 +65,8 @@ jobs: - name: Fail on failed tests if: always() run: | - sudo apt-get install -y libxml2-utils + sudo apt-get update + sudo apt-get install -y libxml2-utils --fix-missing echo "Found ${{ steps.tests.outputs.path_count }} test report(s)" if [[ ${{ steps.tests.outputs.path_count }} < 1 ]]; then echo "ERROR: No unit test reports collected." From f6c00ef02d4620db445b4cce8f4cf31ea8a31604 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Tue, 15 Mar 2022 17:56:38 +0100 Subject: [PATCH 04/13] explicitly configure test inclusions --- code/sonar-project.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/sonar-project.properties b/code/sonar-project.properties index a03c455..dfa3709 100644 --- a/code/sonar-project.properties +++ b/code/sonar-project.properties @@ -2,7 +2,6 @@ sonar.organization=nuvla sonar.projectKey=nuvla-ring sonar.projectName=nuvla-ring sonar.sources=src,project.clj -sonar.tests=test sonar.clojure.eastwood.enabled=true sonar.clojure.kibit.enabled=true sonar.clojure.kondo.enabled=true @@ -12,4 +11,6 @@ sonar.clojure.nvd.json-output-location=target/nvd/dependency-check-report.json sonar.clojure.cloverage.enabled=true sonar.clojure.cloverage.json-output-location=target/coverage/codecov.json +sonar.tests=test +sonar.test.inclusions=**/*.clj,**/*.cljc sonar.testExecutionReportPaths=test-reports/sonar/testExecutions.xml \ No newline at end of file From 17e688513e253b98d8ee8f5381f4b67068864029 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Tue, 15 Mar 2022 17:58:01 +0100 Subject: [PATCH 05/13] fail a test --- code/test/sixsq/nuvla/server/error_test.clj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/test/sixsq/nuvla/server/error_test.clj b/code/test/sixsq/nuvla/server/error_test.clj index 271234a..2ac7483 100644 --- a/code/test/sixsq/nuvla/server/error_test.clj +++ b/code/test/sixsq/nuvla/server/error_test.clj @@ -3,5 +3,8 @@ [clojure.test :refer :all] [sixsq.nuvla.server.error :as e])) +(deftest test-sum-failure + (is (= 3 (e/sum 1 1)))) + (deftest test-sum (is (= 2 (e/sum 1 1)))) From 8aa56bd59a6a8b9bdbc8af4fa67f66f875ca544a Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Tue, 15 Mar 2022 18:04:38 +0100 Subject: [PATCH 06/13] run with debug --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e78beb8..8e3b657 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,6 +45,7 @@ jobs: run: sonar-scanner -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} + -X - name: debug run: | From 36f95921af827c71a5bb8b53194ee31fc7b54eea Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Wed, 16 Mar 2022 09:02:56 +0100 Subject: [PATCH 07/13] try quality gate on failed tests in SQ --- .github/workflows/main.yml | 58 +++++++++++++++++------------------ code/project.clj | 2 +- code/sonar-project.properties | 4 +-- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8e3b657..9a59615 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,35 +55,35 @@ jobs: cat code/test-reports/sonar/testExecutions.xml || true echo --------- - - name: Get list of tests - if: always() - id: tests - uses: Rishabh510/Path-lister-action@master - with: - path: "code/test-reports/xml" - type: ".xml" - - - name: Fail on failed tests - if: always() - run: | - sudo apt-get update - sudo apt-get install -y libxml2-utils --fix-missing - echo "Found ${{ steps.tests.outputs.path_count }} test report(s)" - if [[ ${{ steps.tests.outputs.path_count }} < 1 ]]; then - echo "ERROR: No unit test reports collected." - exit 1 - fi - for f in ${{ steps.tests.outputs.paths }}; do - echo "=== $f ===" - if [[ $(xmllint --xpath "string(//testsuite/@failures)" $f) > 1 ]]; then - echo TEST FAILED: $f - exit 1 - fi - if [[ $(xmllint --xpath "string(//testsuite/@errors)" $f) > 1 ]]; then - echo TEST ERRORED: $f - exit 1 - fi - done +# - name: Get list of tests +# if: always() +# id: tests +# uses: Rishabh510/Path-lister-action@master +# with: +# path: "code/test-reports/xml" +# type: ".xml" +# +# - name: Fail on failed tests +# if: always() +# run: | +# sudo apt-get update +# sudo apt-get install -y libxml2-utils --fix-missing +# echo "Found ${{ steps.tests.outputs.path_count }} test report(s)" +# if [[ ${{ steps.tests.outputs.path_count }} < 1 ]]; then +# echo "ERROR: No unit test reports collected." +# exit 1 +# fi +# for f in ${{ steps.tests.outputs.paths }}; do +# echo "=== $f ===" +# if [[ $(xmllint --xpath "string(//testsuite/@failures)" $f) > 1 ]]; then +# echo TEST FAILED: $f +# exit 1 +# fi +# if [[ $(xmllint --xpath "string(//testsuite/@errors)" $f) > 1 ]]; then +# echo TEST ERRORED: $f +# exit 1 +# fi +# done - name: SonarQube Quality Gate check uses: sonarsource/sonarqube-quality-gate-action@v1.0.0 diff --git a/code/project.clj b/code/project.clj index 930c76e..7dc772e 100644 --- a/code/project.clj +++ b/code/project.clj @@ -41,7 +41,7 @@ :profiles {:test {:source-paths ["test"] :resource-paths ["test-resources"] - :plugins [[org.clojars.konstan/lein-test-report-sonar "0.0.3"]] + :plugins [[org.clojars.konstan/lein-test-report-sonar "0.0.4"]] :test-report-sonar {:output-dir "test-reports" :emit-junit-xml true}} :dev {:dependencies [[clj-kondo "RELEASE"]]}}) diff --git a/code/sonar-project.properties b/code/sonar-project.properties index dfa3709..93cc213 100644 --- a/code/sonar-project.properties +++ b/code/sonar-project.properties @@ -10,7 +10,5 @@ sonar.clojure.nvd.enabled=true sonar.clojure.nvd.json-output-location=target/nvd/dependency-check-report.json sonar.clojure.cloverage.enabled=true sonar.clojure.cloverage.json-output-location=target/coverage/codecov.json - sonar.tests=test -sonar.test.inclusions=**/*.clj,**/*.cljc -sonar.testExecutionReportPaths=test-reports/sonar/testExecutions.xml \ No newline at end of file +sonar.testExecutionReportPaths=test-reports/sonar/testExecutions.xml From b239572bf44aaffc751fa7d1cd7af6fa37e5b358 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Wed, 16 Mar 2022 16:45:42 +0100 Subject: [PATCH 08/13] report project version to SQ --- .github/workflows/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9a59615..7b31156 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,6 +32,12 @@ jobs: distribution: 'zulu' java-version: '11' + - name: Project version + run: | + VERSION=$( mvn help:evaluate -Dexpression=project.version -q -DforceStdout ) + echo "::set-output name=version::$VERSION" + id: project_version + - name: Setup Sonar Scanner uses: warchant/setup-sonar-scanner@v3 with: @@ -45,6 +51,7 @@ jobs: run: sonar-scanner -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} + -Dsonar.projectVersion=${{ steps.project_version.version }} -X - name: debug From 239fc1bc0bce9fd9c4a68e65b5483717d5776b1b Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Wed, 16 Mar 2022 17:22:26 +0100 Subject: [PATCH 09/13] get var from outputs --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7b31156..024d466 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,6 +33,7 @@ jobs: java-version: '11' - name: Project version + working-directory: code run: | VERSION=$( mvn help:evaluate -Dexpression=project.version -q -DforceStdout ) echo "::set-output name=version::$VERSION" @@ -51,7 +52,7 @@ jobs: run: sonar-scanner -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} - -Dsonar.projectVersion=${{ steps.project_version.version }} + -Dsonar.projectVersion=${{ steps.project_version.outputs.version }} -X - name: debug From 1d66c6d47342d96bb0f75095702850f421cb9de4 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Wed, 16 Mar 2022 17:52:15 +0100 Subject: [PATCH 10/13] error in test --- code/test/sixsq/nuvla/server/error_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/test/sixsq/nuvla/server/error_test.clj b/code/test/sixsq/nuvla/server/error_test.clj index 2ac7483..b1d5104 100644 --- a/code/test/sixsq/nuvla/server/error_test.clj +++ b/code/test/sixsq/nuvla/server/error_test.clj @@ -4,7 +4,7 @@ [sixsq.nuvla.server.error :as e])) (deftest test-sum-failure - (is (= 3 (e/sum 1 1)))) + (is (= 4 (e/sum 1 1)))) (deftest test-sum (is (= 2 (e/sum 1 1)))) From f1608c5ced9d11b28b1bac81b3d4b3e1458a7911 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Wed, 16 Mar 2022 22:10:16 +0100 Subject: [PATCH 11/13] fail the test --- code/test/sixsq/nuvla/server/error_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/test/sixsq/nuvla/server/error_test.clj b/code/test/sixsq/nuvla/server/error_test.clj index b1d5104..2ac7483 100644 --- a/code/test/sixsq/nuvla/server/error_test.clj +++ b/code/test/sixsq/nuvla/server/error_test.clj @@ -4,7 +4,7 @@ [sixsq.nuvla.server.error :as e])) (deftest test-sum-failure - (is (= 4 (e/sum 1 1)))) + (is (= 3 (e/sum 1 1)))) (deftest test-sum (is (= 2 (e/sum 1 1)))) From 0de2f1b6a465298d603c608964e1b3b4eee2ef74 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Wed, 16 Mar 2022 22:32:30 +0100 Subject: [PATCH 12/13] new code --- code/src/sixsq/nuvla/server/error.clj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/src/sixsq/nuvla/server/error.clj b/code/src/sixsq/nuvla/server/error.clj index 1de551c..b28600a 100644 --- a/code/src/sixsq/nuvla/server/error.clj +++ b/code/src/sixsq/nuvla/server/error.clj @@ -7,3 +7,7 @@ (defn mult [a b] (* a b)) + +(defn sub + [a b] + (- a b)) From e5c7032ce8c3be489cb2c5673d38380feb0e4265 Mon Sep 17 00:00:00 2001 From: Konstantin Skaburskas Date: Fri, 18 Mar 2022 08:47:58 +0100 Subject: [PATCH 13/13] add lein project-version plugin to get the project version in CI --- .github/workflows/main.yml | 2 +- code/project.clj | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 024d466..aaa3a0b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Project version working-directory: code run: | - VERSION=$( mvn help:evaluate -Dexpression=project.version -q -DforceStdout ) + VERSION=$( lein project-version ) echo "::set-output name=version::$VERSION" id: project_version diff --git a/code/project.clj b/code/project.clj index 7dc772e..5306698 100644 --- a/code/project.clj +++ b/code/project.clj @@ -10,7 +10,8 @@ :url "http://www.apache.org/licenses/LICENSE-2.0.txt" :distribution :repo} - :plugins [[lein-parent "0.3.5"]] + :plugins [[lein-parent "0.3.5"] + [lein-project-version "0.1.0"]] :parent-project {:coords [sixsq.nuvla/parent ~parent-version] :inherit [:plugins