Skip to content

Commit e7049ed

Browse files
authored
test: Add testing for Java source files (#2)
1 parent 4eef8b6 commit e7049ed

File tree

9 files changed

+849
-263
lines changed

9 files changed

+849
-263
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: PR Release & Snapshot Publish
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- synchronize
9+
- opened
10+
- reopened
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
pull-requests: write
16+
17+
concurrency:
18+
group: pr-release-${{ github.event.pull_request.number }}
19+
cancel-in-progress: false
20+
21+
jobs:
22+
verify:
23+
name: Verify
24+
uses: ./.github/workflows/verify-version.yml
25+
secrets: inherit
26+
27+
build-test-publish:
28+
name: Build, Test & Publish Snapshot
29+
runs-on: ubuntu-latest
30+
needs: verify
31+
env:
32+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
33+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
34+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
35+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
36+
37+
steps:
38+
- name: Checkout PR Branch
39+
uses: actions/checkout@v5
40+
with:
41+
fetch-depth: 0
42+
43+
- name: Setup JDK 24 for Kotlin 2.2.0
44+
uses: actions/setup-java@v5
45+
with:
46+
distribution: 'temurin'
47+
java-version: '24'
48+
cache: 'gradle'
49+
50+
- name: Grant Execute Permission for Gradlew
51+
run: chmod +x gradlew
52+
53+
- name: Build
54+
run: ./gradlew clean copyJar --no-daemon --stacktrace
55+
56+
- name: Test with Kotest
57+
run: ./gradlew kotest --stacktrace
58+
59+
- name: Check if publish paths changed in latest commit
60+
id: changes
61+
run: |
62+
if git diff --quiet ${{ github.event.before }} ${{ github.event.after }} -- \
63+
'modules/**/src/main/**' \
64+
'modules/**/build.gradle' \
65+
'build.gradle' \
66+
'gradle.properties'; then
67+
echo "changed=false" >> $GITHUB_OUTPUT
68+
else
69+
echo "changed=true" >> $GITHUB_OUTPUT
70+
fi
71+
72+
73+
- name: Determine PR Snapshot Version
74+
if: steps.changes.outputs.changed == 'true'
75+
id: versioning
76+
run: |
77+
BASE_VERSION=$(grep '^baseVersion=' gradle.properties | cut -d'=' -f2)
78+
PR_NUMBER=${{ github.event.pull_request.number }}
79+
INCREMENT=$(date +%s)
80+
SNAPSHOT_VERSION="${BASE_VERSION}-PR${PR_NUMBER}-${INCREMENT}-SNAPSHOT"
81+
82+
echo "snapshot_version=$SNAPSHOT_VERSION" >> $GITHUB_OUTPUT
83+
echo "Using snapshot version: $SNAPSHOT_VERSION"
84+
85+
- name: Publish PR Snapshot to Maven Central Snapshot Repo
86+
if: steps.changes.outputs.changed == 'true'
87+
run: ./gradlew publishToMavenCentral -Pversion=${{ steps.versioning.outputs.snapshot_version }} --stacktrace --info
88+
89+
- name: Find Comment
90+
uses: peter-evans/find-comment@v3
91+
if: steps.changes.outputs.changed == 'true'
92+
id: find-comment
93+
with:
94+
issue-number: ${{ github.event.pull_request.number }}
95+
comment-author: 'github-actions[bot]'
96+
body-includes: '<!-- PR Snapshot Coordinates -->'
97+
- name: Comment Snapshot Coordinates on PR
98+
if: steps.changes.outputs.changed == 'true'
99+
uses: peter-evans/create-or-update-comment@v4
100+
with:
101+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
102+
issue-number: ${{ github.event.pull_request.number }}
103+
body: |
104+
<!-- PR Snapshot Coordinates -->
105+
🆕 **PR Snapshot Published to Maven Central Snapshot Repository**
106+
107+
You can test this PR build by adding the following dependencies:
108+
109+
Version: `${{ steps.versioning.outputs.snapshot_version }}`
110+
111+
```gradle
112+
implementation "io.github.eventhorizonlab:spi-tooling-annotations:${{ steps.versioning.outputs.snapshot_version }}"
113+
kapt "io.github.eventhorizonlab:spi-tooling-processor:${{ steps.versioning.outputs.snapshot_version }}"
114+
```
115+
116+
_This comment will be updated automatically if a new snapshot is published for this PR_
117+
edit-mode: replace
118+
reactions: rocket
119+
reactions-edit-mode: replace

.github/workflows/pr-snapshot-publish.yml

Lines changed: 0 additions & 68 deletions
This file was deleted.

.github/workflows/release-and-publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- name: Build Artifacts
4040
run: ./gradlew clean copyJar --no-daemon --stacktrace
4141

42+
- name: Test with Kotest
43+
run: ./gradlew kotest --stacktrace
44+
4245
- name: Publish to Maven Central and GitHub Packages
4346
run: ./gradlew publishToMavenCentral publishAllPublicationsToGitHubPackagesRepository --stacktrace
4447

.github/workflows/verify-version.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Verify SemVer Version
22
on:
3-
pull_request:
4-
branches:
5-
- main
3+
workflow_call:
64

75
jobs:
86
check-version:
@@ -19,7 +17,7 @@ jobs:
1917
echo "PR_VERSION=$PR_VERSION" >> $GITHUB_OUTPUT
2018
- name: Verify in SemVer format
2119
run: |
22-
if ! [[ "${{ steps.pr_version.outputs.PR_VERSION }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
20+
if ! [[ "${{ steps.pr_version.outputs.PR_VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
2321
echo "Error: Version '${{ steps.pr_version.outputs.PR_VERSION }}' is not in valid SemVer format."
2422
exit 1
2523
fi

build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ subprojects {
2121

2222
// Configure Vanniktech plugin
2323
mavenPublishing {
24-
// Central Portal publishing
2524
publishToMavenCentral(true)
26-
27-
// Sign all publications with in‑memory keys
2825
signAllPublications()
2926

30-
// Optional: override artifactId per module
3127
coordinates(
3228
rootProject.group as String,
3329
"${rootProject.name}-${project.name}",

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
group=io.github.eventhorizonlab
3-
baseVersion=0.1.17
3+
baseVersion=0.1.18
44
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8

modules/annotations/src/main/kotlin/com/github/eventhorizonlab/spi/ServiceScheme.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import kotlin.reflect.KClass
55
/**
66
* Marks a class as a ServiceLoader provider for the given contract.
77
*/
8+
@Repeatable
9+
@MustBeDocumented
810
@Target(AnnotationTarget.CLASS)
911
@Retention(AnnotationRetention.RUNTIME)
10-
annotation class ServiceProvider(val value: KClass<*>)
12+
annotation class ServiceProvider(vararg val value: KClass<*>)
1113

1214
/**
1315
* Marks an interface as a ServiceLoader contract.
1416
*/
17+
@MustBeDocumented
1518
@Target(AnnotationTarget.CLASS)
1619
@Retention(AnnotationRetention.RUNTIME)
1720
annotation class ServiceContract

0 commit comments

Comments
 (0)