From 4bc72fe3d87ba94aa2e8dc5bae8094866aeb0ef6 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Sun, 12 Jan 2025 10:46:31 +0200 Subject: [PATCH 1/6] Added code coverage --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++++++++++------ pom.xml | 19 +++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9acde765..9efa9352 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: AST Java Wrapper CI -on: [ pull_request ] +on: [pull_request] jobs: integration-tests: @@ -21,7 +21,6 @@ jobs: - name: Checkout LFS objects run: git lfs checkout - - name: Cache local Maven repository uses: actions/cache@v4 with: @@ -39,13 +38,15 @@ jobs: - name: Check existence of cx-linux binary run: | if [ ! -f "src/main/resources/cx-linux" ]; then - echo "cx-linux binary does not exist"; exit 1; + echo "cx-linux binary does not exist"; exit 1; fi + - name: Check existence of cx.exe binary run: | if [ ! -f "src/main/resources/cx.exe" ]; then echo "cx.exe binary does not exist"; exit 1; fi + - name: Check existence of cx-mac binary run: | if [ ! -f "src/main/resources/cx-mac" ]; then @@ -55,13 +56,12 @@ jobs: - name: Run tests with Maven run: mvn -B test --file pom.xml env: - CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID}} - CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET}} + CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID }} + CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET }} CX_BASE_URI: ${{ secrets.CX_BASE_URI }} CX_TENANT: ${{ secrets.CX_TENANT }} CX_APIKEY: ${{ secrets.CX_APIKEY }} - - name: Build with Maven run: mvn -B verify -DskipTests -Dgpg.skip --file pom.xml @@ -70,3 +70,36 @@ jobs: uses: jwgmeligmeyling/spotbugs-github-action@b8e2c3523acb34c87f14e18cbcd2d87db8c8584e #v1.2 with: path: '**/spotbugsXml.xml' + + code-coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Cache local Maven repository + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Set up JDK 11 + uses: actions/setup-java@v4.3.0 + with: + distribution: 'temurin' + java-version: '11' + + - name: Generate and Display Code Coverage Report + run: | + mvn clean verify + mvn jacoco:report + echo "Code Coverage Summary:" + grep -A 10 "Total" target/site/jacoco/jacoco.csv || echo "Coverage report not found." + + - name: Upload JaCoCo Coverage Report + uses: actions/upload-artifact@v4 + with: + name: jacoco-report + path: target/site/jacoco/* diff --git a/pom.xml b/pom.xml index 58aaaa05..c165e2f3 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,25 @@ + + org.jacoco + jacoco-maven-plugin + 0.8.8 + + + + prepare-agent + + + + report + verify + + report + + + + com.github.spotbugs spotbugs-maven-plugin From db68e745b171eef96b4976ea9aa51a1971aec848 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Sun, 12 Jan 2025 10:55:37 +0200 Subject: [PATCH 2/6] try fix jacoco --- .github/workflows/ci.yml | 54 +++++++++++++++------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9efa9352..60d4a98c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,12 @@ jobs: distribution: 'temurin' java-version: '11' + - name: Set Executable Permissions for Binary Files + run: | + chmod +x src/main/resources/cx-linux + chmod +x src/main/resources/cx.exe + chmod +x src/main/resources/cx-mac + - name: Check existence of cx-linux binary run: | if [ ! -f "src/main/resources/cx-linux" ]; then @@ -53,8 +59,10 @@ jobs: echo "cx-mac binary does not exist"; exit 1; fi - - name: Run tests with Maven - run: mvn -B test --file pom.xml + - name: Run tests with Maven and Generate Coverage Report + run: | + mvn clean verify + mvn jacoco:report env: CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID }} CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET }} @@ -62,39 +70,8 @@ jobs: CX_TENANT: ${{ secrets.CX_TENANT }} CX_APIKEY: ${{ secrets.CX_APIKEY }} - - name: Build with Maven - run: mvn -B verify -DskipTests -Dgpg.skip --file pom.xml - - - name: Run SpotBugs Analysis - if: ${{ github.actor != 'dependabot[bot]' }} - uses: jwgmeligmeyling/spotbugs-github-action@b8e2c3523acb34c87f14e18cbcd2d87db8c8584e #v1.2 - with: - path: '**/spotbugsXml.xml' - - code-coverage: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Cache local Maven repository - uses: actions/cache@v4 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: Set up JDK 11 - uses: actions/setup-java@v4.3.0 - with: - distribution: 'temurin' - java-version: '11' - - - name: Generate and Display Code Coverage Report + - name: Display Coverage Summary run: | - mvn clean verify - mvn jacoco:report echo "Code Coverage Summary:" grep -A 10 "Total" target/site/jacoco/jacoco.csv || echo "Coverage report not found." @@ -103,3 +80,12 @@ jobs: with: name: jacoco-report path: target/site/jacoco/* + + - name: Build with Maven + run: mvn -B verify -DskipTests -Dgpg.skip --file pom.xml + + - name: Run SpotBugs Analysis + if: ${{ github.actor != 'dependabot[bot]' }} + uses: jwgmeligmeyling/spotbugs-github-action@b8e2c3523acb34c87f14e18cbcd2d87db8c8584e #v1.2 + with: + path: '**/spotbugsXml.xml' From a7ef3efc26010081581ac27b34966187d5a8c11e Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Sun, 12 Jan 2025 11:12:06 +0200 Subject: [PATCH 3/6] fix yml file --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60d4a98c..643b5222 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,8 +61,8 @@ jobs: - name: Run tests with Maven and Generate Coverage Report run: | - mvn clean verify - mvn jacoco:report + mvn clean verify -Dgpg.skip + mvn jacoco:report -Dgpg.skip env: CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID }} CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET }} From ec1a14df7ce198abf13ce7b6456f87a2ff83b708 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Sun, 12 Jan 2025 11:29:26 +0200 Subject: [PATCH 4/6] fix jacoco --- .github/workflows/ci.yml | 42 ++++++++++++++++++---------------------- pom.xml | 8 +++++++- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 643b5222..a4ccba7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: AST Java Wrapper CI -on: [pull_request] +on: [ pull_request ] jobs: integration-tests: @@ -35,51 +35,47 @@ jobs: distribution: 'temurin' java-version: '11' - - name: Set Executable Permissions for Binary Files - run: | - chmod +x src/main/resources/cx-linux - chmod +x src/main/resources/cx.exe - chmod +x src/main/resources/cx-mac - - name: Check existence of cx-linux binary run: | if [ ! -f "src/main/resources/cx-linux" ]; then - echo "cx-linux binary does not exist"; exit 1; + echo "cx-linux binary does not exist"; exit 1; fi - - name: Check existence of cx.exe binary run: | if [ ! -f "src/main/resources/cx.exe" ]; then echo "cx.exe binary does not exist"; exit 1; fi - - name: Check existence of cx-mac binary run: | if [ ! -f "src/main/resources/cx-mac" ]; then echo "cx-mac binary does not exist"; exit 1; fi - - name: Run tests with Maven and Generate Coverage Report - run: | - mvn clean verify -Dgpg.skip - mvn jacoco:report -Dgpg.skip + - name: Install xmllint + run: sudo apt-get install -y libxml2-utils + + - name: Run tests with JaCoCo + run: mvn test jacoco:report env: - CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID }} - CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET }} + CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID}} + CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET}} CX_BASE_URI: ${{ secrets.CX_BASE_URI }} CX_TENANT: ${{ secrets.CX_TENANT }} CX_APIKEY: ${{ secrets.CX_APIKEY }} - - name: Display Coverage Summary + - name: Print total coverage percentage run: | - echo "Code Coverage Summary:" - grep -A 10 "Total" target/site/jacoco/jacoco.csv || echo "Coverage report not found." + COVERED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) + MISSED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) + TOTAL_LINES=$((COVERED_LINES + MISSED_LINES)) + COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc) + echo "Total coverage percentage: $COVERAGE_PERCENTAGE%" - - name: Upload JaCoCo Coverage Report - uses: actions/upload-artifact@v4 + - name: Upload JaCoCo coverage report + uses: actions/upload-artifact@v3 with: - name: jacoco-report - path: target/site/jacoco/* + name: jacoco-coverage-report + path: target/site/jacoco - name: Build with Maven run: mvn -B verify -DskipTests -Dgpg.skip --file pom.xml diff --git a/pom.xml b/pom.xml index c165e2f3..dafdd068 100644 --- a/pom.xml +++ b/pom.xml @@ -73,10 +73,16 @@ report - verify + test report + + + **/src/main/java/** + + + From 3c600226aae2db8cd5efcf80f9657a79d5a88f32 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Sun, 12 Jan 2025 14:14:40 +0200 Subject: [PATCH 5/6] change artifact upload to v4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4ccba7f..a31f7a69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: echo "Total coverage percentage: $COVERAGE_PERCENTAGE%" - name: Upload JaCoCo coverage report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: jacoco-coverage-report path: target/site/jacoco From 718ace3eaea912321bc53789375157e913ce138b Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Sun, 12 Jan 2025 14:29:30 +0200 Subject: [PATCH 6/6] add sha for v4 artifact upload --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a31f7a69..b6116fdc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: echo "Total coverage percentage: $COVERAGE_PERCENTAGE%" - name: Upload JaCoCo coverage report - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4 with: name: jacoco-coverage-report path: target/site/jacoco