Skip to content

Commit 97cd5ce

Browse files
committed
CI improvements
Update gradle to the latest version, build in CI with the latest LTS Java version, and remove unused Maven repository for generated SDKs (code generation has moved to happen in this project directly). Update to use buf maven artifact instead of an expensive (uncached) build each CI run.
1 parent 1445f7d commit 97cd5ce

File tree

9 files changed

+66
-40
lines changed

9 files changed

+66
-40
lines changed

.github/workflows/ci.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ jobs:
1717
steps:
1818
- name: Checkout code
1919
uses: actions/checkout@v4
20+
- name: Cache Go Modules
21+
uses: actions/cache@v4
2022
with:
21-
fetch-depth: 1
23+
path: |
24+
~/.cache/go-build
25+
~/go/pkg/mod
26+
key: ${{ runner.os }}-gomod-ci-${{ hashFiles('gradle.properties', 'gradle/libs.versions.toml') }}
27+
restore-keys:
28+
${{ runner.os }}-gomod-ci-
2229
- uses: actions/setup-java@v4
2330
with:
2431
distribution: 'temurin'
25-
java-version: '17'
32+
java-version: '21'
2633
cache: 'gradle'
27-
- uses: actions/checkout@v4
28-
- uses: bufbuild/buf-setup-action@v1
29-
with:
30-
github_token: ${{ github.token }}
34+
- name: Validate Gradle Wrapper
35+
uses: gradle/wrapper-validation-action@v2
3136
- name: Lint
3237
run: make lint
3338
- name: Generate

.github/workflows/conformance.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ jobs:
1717
steps:
1818
- name: Checkout code
1919
uses: actions/checkout@v4
20+
- name: Cache Go Modules
21+
uses: actions/cache@v4
2022
with:
21-
fetch-depth: 1
23+
path: |
24+
~/.cache/go-build
25+
~/go/pkg/mod
26+
key: ${{ runner.os }}-gomod-conformance-${{ hashFiles('gradle.properties', 'gradle/libs.versions.toml') }}
27+
restore-keys:
28+
${{ runner.os }}-gomod-conformance-
2229
- uses: actions/setup-java@v4
2330
with:
2431
distribution: 'temurin'
25-
java-version: '17'
32+
java-version: '21'
2633
cache: 'gradle'
34+
- name: Validate Gradle Wrapper
35+
uses: gradle/wrapper-validation-action@v2
2736
- name: Test conformance
2837
run: make conformance

.github/workflows/release.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v4
1717

18+
- name: Cache Go Modules
19+
uses: actions/cache@v4
20+
with:
21+
path: |
22+
~/.cache/go-build
23+
~/go/pkg/mod
24+
key: ${{ runner.os }}-gomod-ci-${{ hashFiles('gradle.properties', 'gradle/libs.versions.toml') }}
25+
restore-keys:
26+
${{ runner.os }}-gomod-ci-
27+
1828
- name: Set up JDK
1929
uses: actions/setup-java@v4
2030
with:
2131
distribution: 'temurin'
22-
java-version: '17'
32+
java-version: '21'
2333

2434
- name: Validate Gradle Wrapper
2535
uses: gradle/wrapper-validation-action@v2

build.gradle.kts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
alias(libs.plugins.errorprone)
1111
alias(libs.plugins.git)
1212
alias(libs.plugins.maven)
13+
alias(libs.plugins.osdetector)
1314
}
1415

1516
java {
@@ -31,23 +32,20 @@ if (matchResult != null) {
3132
}
3233
val releaseVersion = project.findProperty("releaseVersion") as String? ?: snapshotVersion
3334

34-
val bufCLIFile = project.layout.buildDirectory.file("gobin/buf").get().asFile
35-
val bufCLIPath: String = bufCLIFile.absolutePath
35+
val buf: Configuration by configurations.creating
3636
val bufLicenseHeaderCLIFile = project.layout.buildDirectory.file("gobin/license-header").get().asFile
3737
val bufLicenseHeaderCLIPath: String = bufLicenseHeaderCLIFile.absolutePath
3838

39-
tasks.register<Exec>("installBuf") {
39+
tasks.register("configureBuf") {
4040
description = "Installs the Buf CLI."
41-
environment("GOBIN", bufCLIFile.parentFile.absolutePath)
42-
outputs.file(bufCLIFile)
43-
commandLine("go", "install", "github.com/bufbuild/buf/cmd/buf@latest")
41+
File(buf.asPath).setExecutable(true)
4442
}
4543

4644
tasks.register<Exec>("installLicenseHeader") {
4745
description = "Installs the Buf license-header CLI."
4846
environment("GOBIN", bufLicenseHeaderCLIFile.parentFile.absolutePath)
4947
outputs.file(bufLicenseHeaderCLIFile)
50-
commandLine("go", "install", "github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@latest")
48+
commandLine("go", "install", "github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v${libs.versions.buf.get()}")
5149
}
5250

5351
tasks.register<Exec>("licenseHeader") {
@@ -69,10 +67,10 @@ tasks.register<Exec>("licenseHeader") {
6967
}
7068

7169
tasks.register<Exec>("generateTestSourcesImports") {
72-
dependsOn("installBuf")
70+
dependsOn("configureBuf")
7371
description = "Generates code with buf generate --include-imports for unit tests."
7472
commandLine(
75-
bufCLIPath,
73+
buf.asPath,
7674
"generate",
7775
"--template",
7876
"src/test/resources/proto/buf.gen.imports.yaml",
@@ -82,9 +80,9 @@ tasks.register<Exec>("generateTestSourcesImports") {
8280
}
8381

8482
tasks.register<Exec>("generateTestSourcesNoImports") {
85-
dependsOn("installBuf")
83+
dependsOn("configureBuf")
8684
description = "Generates code with buf generate --include-imports for unit tests."
87-
commandLine(bufCLIPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml", "src/test/resources/proto")
85+
commandLine(buf.asPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml", "src/test/resources/proto")
8886
}
8987

9088
tasks.register("generateTestSources") {
@@ -93,10 +91,10 @@ tasks.register("generateTestSources") {
9391
}
9492

9593
tasks.register<Exec>("exportProtovalidateModule") {
96-
dependsOn("installBuf")
94+
dependsOn("configureBuf")
9795
description = "Exports the bufbuild/protovalidate module sources to src/main/resources."
9896
commandLine(
99-
bufCLIPath,
97+
buf.asPath,
10098
"export",
10199
"buf.build/bufbuild/protovalidate:${project.findProperty("protovalidate.version")}",
102100
"--output",
@@ -105,16 +103,16 @@ tasks.register<Exec>("exportProtovalidateModule") {
105103
}
106104

107105
tasks.register<Exec>("generateSources") {
108-
dependsOn("installBuf")
106+
dependsOn("configureBuf")
109107
description = "Generates sources for the bufbuild/protovalidate module sources to src/main/java."
110-
commandLine(bufCLIPath, "generate", "--template", "buf.gen.yaml", "src/main/resources")
108+
commandLine(buf.asPath, "generate", "--template", "buf.gen.yaml", "src/main/resources")
111109
}
112110

113111
tasks.register<Exec>("generateConformance") {
114-
dependsOn("installBuf")
112+
dependsOn("configureBuf")
115113
description = "Generates sources for the bufbuild/protovalidate-testing module to conformance/src/main/java."
116114
commandLine(
117-
bufCLIPath,
115+
buf.asPath,
118116
"generate",
119117
"--template",
120118
"conformance/buf.gen.yaml",
@@ -193,14 +191,10 @@ allprojects {
193191
version = releaseVersion
194192
repositories {
195193
mavenCentral()
196-
maven {
197-
name = "buf"
198-
url = uri("https://buf.build/gen/maven")
199-
}
200194
}
201195
apply(plugin = "com.diffplug.spotless")
202196
configure<SpotlessExtension> {
203-
setEnforceCheck(false) // Disables lint on gradle builds.
197+
isEnforceCheck = false // Disables lint on gradle builds.
204198
java {
205199
importOrder()
206200
removeUnusedImports()
@@ -276,9 +270,12 @@ dependencies {
276270
implementation(libs.ipaddress)
277271
implementation(libs.jakarta.mail.api)
278272

273+
buf("build.buf:buf:${libs.versions.buf.get()}:${osdetector.classifier}@exe")
274+
279275
testImplementation(libs.assertj)
280276
testImplementation(platform(libs.junit.bom))
281277
testImplementation("org.junit.jupiter:junit-jupiter")
278+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
282279

283280
errorprone(libs.errorprone)
284281
}

conformance/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ dependencies {
8484
implementation(libs.assertj)
8585
implementation(platform(libs.junit.bom))
8686
testImplementation("org.junit.jupiter:junit-jupiter")
87+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
8788

8889
errorprone(libs.errorprone)
8990
}

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[versions]
22
assertj = "3.25.3"
3+
buf = "1.29.0"
34
cel = "0.4.4"
45
ipaddress = "5.5.0"
56
junit = "5.10.2"
@@ -10,6 +11,7 @@ protobuf = "3.25.3"
1011

1112
[libraries]
1213
assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" }
14+
buf = { module = "buf.build:buf", version.ref = "buf" }
1315
cel = { module = "org.projectnessie.cel:cel-bom", version.ref = "cel" }
1416
cel-core = { module = "org.projectnessie.cel:cel-core" }
1517
errorprone = { module = "com.google.errorprone:error_prone_core", version = "2.25.0" }
@@ -26,3 +28,4 @@ spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version =
2628
errorprone = { id = "net.ltgt.errorprone", version = "3.1.0" }
2729
git = { id = "com.palantir.git-version", version = "3.0.0" }
2830
maven = { id = "com.vanniktech.maven.publish.base", version.ref = "maven-publish" }
31+
osdetector = { id = "com.google.osdetector", version = "1.7.3" }

gradle/wrapper/gradle-wrapper.jar

346 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ done
8383
# This is normally unused
8484
# shellcheck disable=SC2034
8585
APP_BASE_NAME=${0##*/}
86-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
86+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87+
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
8788

8889
# Use the maximum available, or set MAX_FD != -1 to use that value.
8990
MAX_FD=maximum
@@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144145
case $MAX_FD in #(
145146
max*)
146147
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147-
# shellcheck disable=SC3045
148+
# shellcheck disable=SC2039,SC3045
148149
MAX_FD=$( ulimit -H -n ) ||
149150
warn "Could not query maximum file descriptor limit"
150151
esac
151152
case $MAX_FD in #(
152153
'' | soft) :;; #(
153154
*)
154155
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155-
# shellcheck disable=SC3045
156+
# shellcheck disable=SC2039,SC3045
156157
ulimit -n "$MAX_FD" ||
157158
warn "Could not set maximum file descriptor limit to $MAX_FD"
158159
esac
@@ -201,11 +202,11 @@ fi
201202
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
202203
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
203204

204-
# Collect all arguments for the java command;
205-
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
206-
# shell script including quotes and variable substitutions, so put them in
207-
# double quotes to make sure that they get re-expanded; and
208-
# * put everything else in single quotes, so that it's not re-expanded.
205+
# Collect all arguments for the java command:
206+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207+
# and any embedded shellness will be escaped.
208+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209+
# treated as '${Hostname}' itself on the command line.
209210

210211
set -- \
211212
"-Dorg.gradle.appname=$APP_BASE_NAME" \

0 commit comments

Comments
 (0)