diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 858131f..aaa3a0b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,6 +32,13 @@ jobs: distribution: 'zulu' java-version: '11' + - name: Project version + working-directory: code + run: | + VERSION=$( lein project-version ) + echo "::set-output name=version::$VERSION" + id: project_version + - name: Setup Sonar Scanner uses: warchant/setup-sonar-scanner@v3 with: @@ -45,36 +52,46 @@ jobs: run: sonar-scanner -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} + -Dsonar.projectVersion=${{ steps.project_version.outputs.version }} + -X - - name: Get list of tests - if: always() - id: tests - uses: Rishabh510/Path-lister-action@master - with: - path: "code/test-reports" - type: ".xml" - - - name: Fail on failed tests - if: always() + - name: debug run: | - sudo apt-get update - sudo apt-get install -y libxml2-utils - 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 + 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 +# 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 @@ -117,7 +134,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() diff --git a/code/project.clj b/code/project.clj index 2c67bf0..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 @@ -41,6 +42,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.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 77f32d2..93cc213 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 @@ -11,4 +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.testExecutionReportPaths=test-reports/sonar/testExecutions.xml diff --git a/code/src/sixsq/nuvla/server/error.clj b/code/src/sixsq/nuvla/server/error.clj new file mode 100644 index 0000000..b28600a --- /dev/null +++ b/code/src/sixsq/nuvla/server/error.clj @@ -0,0 +1,13 @@ +(ns sixsq.nuvla.server.error) + +(defn sum + [a b] + (+ a b)) + +(defn mult + [a b] + (* a b)) + +(defn sub + [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..2ac7483 --- /dev/null +++ b/code/test/sixsq/nuvla/server/error_test.clj @@ -0,0 +1,10 @@ +(ns sixsq.nuvla.server.error-test + (:require + [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))))