From 9e1189c4998eda4d6b4bed445eb1776a28039572 Mon Sep 17 00:00:00 2001 From: Oleksii PELYKH Date: Thu, 20 Jun 2024 18:33:32 +0200 Subject: [PATCH] (chore) test coverage --- .github/workflows/{push.yaml => ci.yaml} | 58 ++++++++++++++++-------- .github/workflows/pull-request.yaml | 57 ----------------------- README.md | 8 ++-- api/build.gradle.kts | 13 +++++- build.gradle.kts | 24 ++++++++++ ffm/build.gradle.kts | 11 +++++ jna/build.gradle.kts | 11 +++++ lib/build.gradle.kts | 13 +++++- regex/build.gradle.kts | 13 +++++- test/build.gradle.kts | 11 +++++ 10 files changed, 138 insertions(+), 81 deletions(-) rename .github/workflows/{push.yaml => ci.yaml} (53%) delete mode 100644 .github/workflows/pull-request.yaml create mode 100644 build.gradle.kts diff --git a/.github/workflows/push.yaml b/.github/workflows/ci.yaml similarity index 53% rename from .github/workflows/push.yaml rename to .github/workflows/ci.yaml index c2524ab..2c7f31d 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/ci.yaml @@ -1,12 +1,16 @@ -name: Push +name: CI on: push: branches: - main + pull_request: + branches: + - main jobs: - build: + + compatibility: strategy: matrix: os: [ ubuntu-latest ] @@ -21,19 +25,19 @@ jobs: - semeru - oracle - dragonwell - fail-fast: false + java-version: [ 21 ] runs-on: ${{ matrix.os }} steps: - - name: Checkout code + - name: Checkout uses: actions/checkout@v4 - - name: Set up "${{ matrix.java-distribution }}" JDK 21 + - name: Set up ${{ matrix.java-distribution }}-jdk-${{ matrix.java-version }} uses: actions/setup-java@v4 with: distribution: ${{ matrix.java-distribution }} - java-version: 21 + java-version: ${{ matrix.java-version }} - name: Cache Gradle packages uses: actions/cache@v4 @@ -44,19 +48,15 @@ jobs: key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: gradle-${{ runner.os }} - - name: Install PCRE (Ubuntu) + - name: Install PCRE if: ${{ matrix.os == 'ubuntu-latest' }} run: sudo apt-get install -y libpcre2-8-0 - - name: Build with Gradle (Ubuntu) - if: ${{ matrix.os == 'ubuntu-latest' }} - run: ./gradlew build -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu - - - name: Run tests (Ubuntu) + - name: Test if: ${{ matrix.os == 'ubuntu-latest' }} - run: ./gradlew test -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu + run: ./gradlew ffm:test jna:test -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu - publish: + package: runs-on: ubuntu-latest permissions: @@ -64,21 +64,43 @@ jobs: packages: write needs: - - build + - compatibility steps: - - name: Checkout code + - name: Checkout uses: actions/checkout@v4 - - name: Set up JDK 21 + - name: Set up temurin-jdk-21 uses: actions/setup-java@v4 with: distribution: temurin java-version: 21 + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: gradle-${{ runner.os }} + + - name: Install PCRE + run: sudo apt-get install -y libpcre2-8-0 + + - name: Build + run: ./gradlew build jacocoAggregatedTestReport -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu + + - name: Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: build/reports/jacoco/jacocoAggregatedTestReport/jacoco.xml + - name: Publish + if: ${{ github.event_name == 'push' && github.ref_name == 'main' }} env: GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew publishAllPublicationsToGitHubPackagesRepository -Ppcre4j.version=main-SNAPSHOT + run: ./gradlew publishAllPublicationsToGitHubPackagesRepository -Ppcre4j.version=${{ github.ref_name }}-SNAPSHOT diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml deleted file mode 100644 index e7bb485..0000000 --- a/.github/workflows/pull-request.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: Pull Request - -on: - pull_request: - branches: - - main - -jobs: - build: - strategy: - matrix: - os: [ ubuntu-latest ] - java-distribution: - - temurin - - zulu - - adopt-hotspot - - adopt-openj9 - - liberica - - microsoft - - corretto - - semeru - - oracle - - dragonwell - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up "${{ matrix.java-distribution }}" JDK 21 - uses: actions/setup-java@v4 - with: - distribution: ${{ matrix.java-distribution }} - java-version: 21 - - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: gradle-${{ runner.os }} - - - name: Install PCRE (Ubuntu) - if: ${{ matrix.os == 'ubuntu-latest' }} - run: sudo apt-get install -y libpcre2-8-0 - - - name: Build with Gradle (Ubuntu) - if: ${{ matrix.os == 'ubuntu-latest' }} - run: ./gradlew build -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu - - - name: Run tests (Ubuntu) - if: ${{ matrix.os == 'ubuntu-latest' }} - run: ./gradlew test -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu diff --git a/README.md b/README.md index 1c88744..d44fbd1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ ![GitHub License](https://img.shields.io/github/license/alexey-pelykh/pcre4j) ![GitHub branch check runs](https://img.shields.io/github/check-runs/alexey-pelykh/pcre4j/main) +[![codecov](https://codecov.io/gh/alexey-pelykh/pcre4j/graph/badge.svg?token=7UJZ501GWT)](https://codecov.io/gh/alexey-pelykh/pcre4j) ![Maven Central Version](https://img.shields.io/maven-central/v/org.pcre4j/lib) The PCRE4J project's goal is to bring the power of the [PCRE](https://www.pcre.org) library to Java. @@ -12,9 +13,10 @@ library author [Philip Hazel](https://github.com/PhilipHazel) and its contributo ## Usage The PCRE4J library provides several APIs to interact with the PCRE library: - - `java.util.regex`-alike API via `org.pcre4j.regex.Pattern` and `org.pcre4j.regex.Matcher` - - The PCRE4J API via `org.pcre4j.Pcre2Code` and related classes - - The `libpcre2` direct API via backends that implement `org.pcre4j.api.IPcre2` + +- `java.util.regex`-alike API via `org.pcre4j.regex.Pattern` and `org.pcre4j.regex.Matcher` +- The PCRE4J API via `org.pcre4j.Pcre2Code` and related classes +- The `libpcre2` direct API via backends that implement `org.pcre4j.api.IPcre2` ### Quick Start with `java.util.regex`-alike API diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 4fa649a..3de42b3 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -16,6 +16,7 @@ plugins { `java-library` `maven-publish` signing + jacoco } repositories { @@ -51,8 +52,18 @@ java { withJavadocJar() } -tasks.withType { +tasks.test { useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + + reports { + xml.required = true + html.required = true + } } tasks.named("sourcesJar") { diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..9698ce1 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,24 @@ +plugins { + `jacoco-report-aggregation` +} + +repositories { + mavenCentral() +} + +dependencies { + jacocoAggregation(project(":api")) + jacocoAggregation(project(":lib")) + jacocoAggregation(project(":test")) + jacocoAggregation(project(":jna")) + jacocoAggregation(project(":ffm")) + jacocoAggregation(project(":regex")) +} + +reporting { + reports { + register("jacocoAggregatedTestReport") { + testType = TestSuiteType.UNIT_TEST + } + } +} diff --git a/ffm/build.gradle.kts b/ffm/build.gradle.kts index dbc7a9b..88c8722 100644 --- a/ffm/build.gradle.kts +++ b/ffm/build.gradle.kts @@ -16,6 +16,7 @@ plugins { `java-library` `maven-publish` signing + jacoco } repositories { @@ -67,6 +68,16 @@ tasks.withType { System.getProperty("java.library.path") ).joinToString(":") ) + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + + reports { + xml.required = true + html.required = true + } } tasks.named("sourcesJar") { diff --git a/jna/build.gradle.kts b/jna/build.gradle.kts index ea42b21..363ed53 100644 --- a/jna/build.gradle.kts +++ b/jna/build.gradle.kts @@ -16,6 +16,7 @@ plugins { `java-library` `maven-publish` signing + jacoco } repositories { @@ -57,6 +58,16 @@ java { tasks.withType { useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + + reports { + xml.required = true + html.required = true + } } tasks.named("sourcesJar") { diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 85dd46d..be7b326 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -16,6 +16,7 @@ plugins { `java-library` `maven-publish` signing + jacoco } repositories { @@ -52,8 +53,18 @@ java { withJavadocJar() } -tasks.withType { +tasks.test { useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + + reports { + xml.required = true + html.required = true + } } tasks.named("sourcesJar") { diff --git a/regex/build.gradle.kts b/regex/build.gradle.kts index 667278e..4313668 100644 --- a/regex/build.gradle.kts +++ b/regex/build.gradle.kts @@ -16,6 +16,7 @@ plugins { `java-library` `maven-publish` signing + jacoco } repositories { @@ -54,8 +55,18 @@ java { withJavadocJar() } -tasks.withType { +tasks.test { useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + + reports { + xml.required = true + html.required = true + } } tasks.named("sourcesJar") { diff --git a/test/build.gradle.kts b/test/build.gradle.kts index 020cba6..0de0155 100644 --- a/test/build.gradle.kts +++ b/test/build.gradle.kts @@ -14,6 +14,7 @@ */ plugins { `java-library` + jacoco } repositories { @@ -50,4 +51,14 @@ java { tasks.withType { useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + + reports { + xml.required = true + html.required = true + } }