Skip to content

Commit 3611c33

Browse files
committed
ci: Add Java 8 API compatibility check
1 parent 65f7853 commit 3611c33

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import org.gradle.api.Project
2+
import org.gradle.api.JavaVersion
3+
import org.gradle.api.plugins.JavaPluginExtension
4+
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferPlugin
5+
6+
initscript {
7+
repositories {
8+
gradlePluginPortal()
9+
mavenCentral()
10+
}
11+
dependencies {
12+
classpath("ru.vyarus:gradle-animalsniffer-plugin:2.0.1")
13+
}
14+
}
15+
16+
val excludedPathPrefixes =
17+
setOf(
18+
":sentry-samples",
19+
":sentry-system-test-support",
20+
":sentry-test-support",
21+
)
22+
23+
fun Project.isJava8SdkModule(): Boolean {
24+
val java = extensions.findByType(JavaPluginExtension::class.java) ?: return false
25+
return plugins.hasPlugin("java-library") &&
26+
java.targetCompatibility == JavaVersion.VERSION_1_8 &&
27+
excludedPathPrefixes.none { path == it || path.startsWith("$it:") }
28+
}
29+
30+
allprojects {
31+
if (rootProject.name != "sentry-root") return@allprojects
32+
33+
afterEvaluate {
34+
if (!isJava8SdkModule()) return@afterEvaluate
35+
36+
if (!plugins.hasPlugin("ru.vyarus.animalsniffer")) {
37+
apply<AnimalSnifferPlugin>()
38+
}
39+
40+
configurations.named("signature").configure {
41+
dependencies.clear()
42+
}
43+
dependencies.add("signature", "org.codehaus.mojo.signature:java18:1.0@signature")
44+
}
45+
}
46+
47+
rootProject {
48+
tasks.register("java8ApiCompatibility") {
49+
group = "verification"
50+
description = "Checks Java 8 SDK modules against the Java 8 runtime API signature."
51+
}
52+
}
53+
54+
gradle.projectsEvaluated {
55+
val java8SdkModules = rootProject.allprojects.filter { it.isJava8SdkModule() }
56+
rootProject.tasks.named("java8ApiCompatibility").configure {
57+
dependsOn(java8SdkModules.map { it.tasks.named("animalsnifferMain") })
58+
doFirst {
59+
logger.lifecycle(
60+
"Checking Java 8 API compatibility for: ${java8SdkModules.joinToString { it.path }}"
61+
)
62+
}
63+
}
64+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: 'Java 8 API Compatibility'
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
java-8-api-compatibility:
15+
name: Java 8 API Compatibility
16+
runs-on: ubuntu-latest
17+
18+
env:
19+
GRADLE_ENCRYPTION_KEY: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
20+
21+
steps:
22+
- name: Checkout Repo
23+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
24+
with:
25+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
26+
submodules: 'recursive'
27+
28+
- name: Setup Java Version
29+
uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5
30+
with:
31+
distribution: 'temurin'
32+
java-version: '17'
33+
34+
- name: Cache buildSrc
35+
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
36+
with:
37+
path: buildSrc/build
38+
key: build-logic-${{ hashFiles('buildSrc/src/**', 'buildSrc/build.gradle.kts','buildSrc/settings.gradle.kts') }}
39+
40+
- name: Setup Gradle
41+
uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # v6.2.0
42+
with:
43+
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
44+
45+
- name: Check Java 8 API compatibility
46+
run: |
47+
./gradlew java8ApiCompatibility \
48+
--init-script .github/gradle/java8-api-compatibility.init.gradle.kts \
49+
--no-configuration-cache \
50+
-Dorg.gradle.configureondemand=false

0 commit comments

Comments
 (0)