Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON provider tests in GH matrix #42

Merged
merged 19 commits into from
Aug 2, 2023
52 changes: 6 additions & 46 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,12 @@ on:
branches: [ master ]

jobs:
build-gradle:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Setup java
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.2.1

- name: Gradle build
run: ./gradlew build testClasses -x check

- name: Gradle check
run: ./gradlew check jacocoTestReport

- name: Generate coverage badge
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
generate-coverage-badge: true
generate-coverage-endpoint: true

- name: Upload build
uses: actions/upload-artifact@v3
with:
name: build-output
path: |
build/libs
build/reports
.github/badges/jacoco.svg

- name: Upload GH pages
uses: actions/upload-pages-artifact@v1
with:
path: './.github/badges'
tests:
uses: ./.github/workflows/tests.yml

sonar-cloud:
runs-on: ubuntu-latest
needs: build-gradle
needs: tests

steps:
- name: Git checkout
Expand All @@ -62,7 +21,8 @@ jobs:

- uses: actions/download-artifact@v3
with:
name: build-output
name: report-output
path: build/reports

- name: Setup java
uses: actions/setup-java@v3
Expand All @@ -84,7 +44,7 @@ jobs:
deploy-gh-pages:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs: build-gradle
needs: tests

permissions:
pages: write
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: deploy-sonatype
name: deploy-release

on:
workflow_dispatch:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: deploy
name: deploy-tag

on:
push:
Expand Down
123 changes: 123 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: tests

on:
workflow_call:

jobs:
generic-tests:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Setup java
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.2.1

- name: Run generic tests
run: ./gradlew check -x test --no-daemon

- name: Upload test execution data
uses: actions/upload-artifact@v3
with:
name: generic-tests-exec
path: build/jacoco

provider-list:
runs-on: ubuntu-latest
outputs:
test-classes: ${{ steps.test-classes.outputs.test-classes }}
steps:
- name: Git checkout
uses: actions/checkout@v3
- name: List provider test classes
id: test-classes
run: |
CLASSES=$(ls src/test/java/dev/harrel/jsonschema/providers/ | sed 's/\.java$//' | jq -R -s -c 'split("\n")[:-1]')
echo "test-classes=$CLASSES" >> "$GITHUB_OUTPUT"

provider-tests:
needs: provider-list
runs-on: ubuntu-latest

strategy:
matrix:
test-class: ${{ fromJSON(needs.provider-list.outputs.test-classes) }}

steps:
- uses: actions/checkout@v3
- name: Setup java
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.2.1

- name: Gradle provider tests
run: ./gradlew test --tests ${{ matrix.test-class }} --no-daemon

- name: Rename test execution data
run: mv build/jacoco/test.exec build/jacoco/${{ matrix.test-class }}.exec

- name: Upload test execution data
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.test-class }}-tests-exec
path: build/jacoco

report:
needs: [generic-tests, provider-tests]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup java
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.2.1

- name: Download test execution data
uses: actions/download-artifact@v3
with:
path: build/jacoco

- name: Get exec data up one level
run: find build/jacoco -path 'build/jacoco/*/*' -execdir mv -t ../ {} +

- name: Gradle jacoco report
run: ./gradlew jacocoTestReport --no-daemon

- name: Generate coverage badge
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
generate-coverage-badge: true
generate-coverage-endpoint: true

- name: Upload report
uses: actions/upload-artifact@v3
with:
name: report-output
path: build/reports

- name: Upload badge
uses: actions/upload-pages-artifact@v1
with:
path: './.github/badges'
2 changes: 2 additions & 0 deletions setup/reporting.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
jacocoTestReport {
executionData fileTree(project.rootDir.absolutePath).include("build/jacoco/*.exec")

reports.html.required = false
reports.csv.required = true
reports.xml.required = true
Expand Down
11 changes: 11 additions & 0 deletions setup/testing.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
tasks.register('genericTests', Test) {
description = 'Runs all tests that are not related to specific JSON providers (no specification tests)'
useJUnitPlatform()
group = 'verification'

filter {
excludeTestsMatching 'dev.harrel.jsonschema.providers.*'
}
}
tasks.check.dependsOn genericTests

ext.setupProviderTest = (String provider, String dependency) -> {
def taskName = "${provider}Test"
def configName = "${taskName}Implementation"
Expand Down