From fe73383ab106b75060994ec847419e89b2702727 Mon Sep 17 00:00:00 2001 From: Ewan Cahen Date: Mon, 14 Aug 2023 11:20:23 +0200 Subject: [PATCH] build: improve SonarCloud actions --- .github/workflows/authentication_tests.yml | 49 +++++++++++++++++ .github/workflows/database_scan.yml | 39 ++++++++++++++ .github/workflows/frontend_tests.yml | 16 ++++++ .github/workflows/scrapers_tests.yml | 35 ++++++++++-- .github/workflows/sonarcloud.yml | 63 ---------------------- authentication/pom.xml | 26 +++++++++ frontend/package.json | 1 + frontend/package.json.license | 3 +- frontend/sonar-project.properties | 3 ++ scrapers/pom.xml | 26 +++++++++ 10 files changed, 192 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/authentication_tests.yml create mode 100644 .github/workflows/database_scan.yml delete mode 100644 .github/workflows/sonarcloud.yml diff --git a/.github/workflows/authentication_tests.yml b/.github/workflows/authentication_tests.yml new file mode 100644 index 000000000..5b22fb8c7 --- /dev/null +++ b/.github/workflows/authentication_tests.yml @@ -0,0 +1,49 @@ +# SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center) +# SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center +# SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) +# SPDX-FileCopyrightText: 2022 dv4all +# +# SPDX-License-Identifier: Apache-2.0 + +name: authentication tests + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "authentication/**" + pull_request: + paths: + - "authentication/**" + +jobs: + authentication-tests: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: "Maven JUnit tests and JaCoCo test report" + working-directory: authentication + run: | + JAVA_HOME=$JAVA_HOME_17_X64 mvn verify + - name: SonarCloud Scan authentication + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + working-directory: authentication + run: JAVA_HOME=$JAVA_HOME_17_X64 mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=nl.research-software:authentication -Pcoverage diff --git a/.github/workflows/database_scan.yml b/.github/workflows/database_scan.yml new file mode 100644 index 000000000..a81945294 --- /dev/null +++ b/.github/workflows/database_scan.yml @@ -0,0 +1,39 @@ +# SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) +# SPDX-FileCopyrightText: 2023 Netherlands eScience Center +# +# SPDX-License-Identifier: Apache-2.0 + +name: database scan + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "database/**" + pull_request: + paths: + - "database/**" + +jobs: + build: + name: Build and analyse with SonarCloud + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: SonarCloud Scan database + uses: sonarsource/sonarcloud-github-action@master + with: + projectBaseDir: database + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/frontend_tests.yml b/.github/workflows/frontend_tests.yml index e142993be..323a74a04 100644 --- a/.github/workflows/frontend_tests.yml +++ b/.github/workflows/frontend_tests.yml @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) # SPDX-FileCopyrightText: 2022 - 2023 dv4all # SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +# SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) # SPDX-FileCopyrightText: 2023 Netherlands eScience Center # # SPDX-License-Identifier: Apache-2.0 @@ -23,6 +24,8 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: "install node v18.5 and cash yarn" uses: actions/setup-node@v3 with: @@ -38,6 +41,19 @@ jobs: - name: "run unit test" working-directory: frontend run: yarn test:coverage + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: SonarCloud Scan frontend + uses: sonarsource/sonarcloud-github-action@master + with: + projectBaseDir: frontend + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - name: "run build test" working-directory: frontend run: yarn build diff --git a/.github/workflows/scrapers_tests.yml b/.github/workflows/scrapers_tests.yml index 0b689b9ba..a1092ce05 100644 --- a/.github/workflows/scrapers_tests.yml +++ b/.github/workflows/scrapers_tests.yml @@ -1,6 +1,6 @@ +# SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center) +# SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center # SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) -# SPDX-FileCopyrightText: 2022 Ewan Cahen (Netherlands eScience Center) -# SPDX-FileCopyrightText: 2022 Netherlands eScience Center # SPDX-FileCopyrightText: 2022 dv4all # # SPDX-License-Identifier: Apache-2.0 @@ -8,6 +8,12 @@ name: scrapers tests on: + workflow_dispatch: + push: + branches: + - main + paths: + - "scrapers/**" pull_request: paths: - "scrapers/**" @@ -17,8 +23,27 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - - name: "Maven JUnit tests" + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: "Maven JUnit tests and JaCoCo test report" working-directory: scrapers run: | - JAVA_HOME=$JAVA_HOME_17_X64 mvn test - + JAVA_HOME=$JAVA_HOME_17_X64 mvn verify + - name: SonarCloud Scan scrapers + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + working-directory: scrapers + run: JAVA_HOME=$JAVA_HOME_17_X64 mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=nl.research-software:scrapers -Pcoverage diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml deleted file mode 100644 index 99f93b1c4..000000000 --- a/.github/workflows/sonarcloud.yml +++ /dev/null @@ -1,63 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) -# SPDX-FileCopyrightText: 2023 Netherlands eScience Center -# -# SPDX-License-Identifier: Apache-2.0 - -name: SonarCloud -on: - push: - branches: - - main - pull_request: - types: [opened, synchronize, reopened] -jobs: - build: - name: Build and analyse with SonarCloud - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'zulu' # Alternative distribution options are available. - - name: Cache SonarCloud packages - uses: actions/cache@v3 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache Maven packages - uses: actions/cache@v3 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - name: Build and analyse authentication module - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - working-directory: authentication - run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=nl.research-software:authentication - - name: Build and analyse scrapers module - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - working-directory: scrapers - run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=nl.research-software:scrapers - - name: Analyse frontend module - uses: sonarsource/sonarcloud-github-action@master - with: - projectBaseDir: frontend - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - name: Analyse database module - uses: sonarsource/sonarcloud-github-action@master - with: - projectBaseDir: database - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/authentication/pom.xml b/authentication/pom.xml index e2362f450..7844981c2 100644 --- a/authentication/pom.xml +++ b/authentication/pom.xml @@ -63,6 +63,32 @@ SPDX-License-Identifier: Apache-2.0 maven-surefire-plugin 3.0.0-M6 + + + + org.jacoco + jacoco-maven-plugin + 0.8.10 + + + prepare-agent + + prepare-agent + + + + report + + report + + + + XML + + + + + diff --git a/frontend/package.json b/frontend/package.json index 2fc75c9fb..3f33a47cc 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,6 +12,7 @@ "test": "jest", "test:watch": "jest --watch --detectOpenHandles", "test:coverage": "jest --coverage", + "test:coveragememlimit": "jest --coverage --workerIdleMemoryLimit=0.1 --maxWorkers=2", "test:memory": "node --expose-gc ./node_modules/.bin/jest --logHeapUsage", "test:inspect": "node --inspect-brk --expose-gc ./node_modules/.bin/jest --logHeapUsage", "test:memlimit": "jest --workerIdleMemoryLimit=0.1 --maxWorkers=2" diff --git a/frontend/package.json.license b/frontend/package.json.license index 0f5d53bf2..a589aca7b 100644 --- a/frontend/package.json.license +++ b/frontend/package.json.license @@ -1,8 +1,9 @@ SPDX-FileCopyrightText: 2021 - 2023 Dusan Mijatovic (dv4all) SPDX-FileCopyrightText: 2021 - 2023 dv4all +SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center SPDX-FileCopyrightText: 2022 Jesús García Gonzalez (Netherlands eScience Center) -SPDX-FileCopyrightText: 2022 Netherlands eScience Center SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all) +SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) SPDX-License-Identifier: Apache-2.0 SPDX-License-Identifier: CC-BY-4.0 diff --git a/frontend/sonar-project.properties b/frontend/sonar-project.properties index a64dbd386..ebd1d64ea 100644 --- a/frontend/sonar-project.properties +++ b/frontend/sonar-project.properties @@ -16,3 +16,6 @@ sonar.organization=research-software-directory # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8 + +# Test coverage report, see https://docs.sonarcloud.io/enriching/test-coverage/javascript-typescript-test-coverage/ +sonar.javascript.lcov.reportPaths=./coverage/lcov.info diff --git a/scrapers/pom.xml b/scrapers/pom.xml index 449212398..24019fcff 100644 --- a/scrapers/pom.xml +++ b/scrapers/pom.xml @@ -63,6 +63,32 @@ SPDX-License-Identifier: Apache-2.0 maven-surefire-plugin 3.0.0-M6 + + + + org.jacoco + jacoco-maven-plugin + 0.8.10 + + + prepare-agent + + prepare-agent + + + + report + + report + + + + XML + + + + +