diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bc2ec6d6..52ef7a72 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,17 +17,22 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: Cache Go Modules + uses: actions/cache@v4 with: - fetch-depth: 1 + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-gomod-ci-${{ hashFiles('gradle.properties', 'gradle/libs.versions.toml') }} + restore-keys: + ${{ runner.os }}-gomod-ci- - uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '17' + java-version: '21' cache: 'gradle' - - uses: actions/checkout@v4 - - uses: bufbuild/buf-setup-action@v1 - with: - github_token: ${{ github.token }} + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v2 - name: Lint run: make lint - name: Generate diff --git a/.github/workflows/conformance.yaml b/.github/workflows/conformance.yaml index 94fbb32e..c0d3519d 100644 --- a/.github/workflows/conformance.yaml +++ b/.github/workflows/conformance.yaml @@ -17,12 +17,21 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: Cache Go Modules + uses: actions/cache@v4 with: - fetch-depth: 1 + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-gomod-conformance-${{ hashFiles('gradle.properties', 'gradle/libs.versions.toml') }} + restore-keys: + ${{ runner.os }}-gomod-conformance- - uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '17' + java-version: '21' cache: 'gradle' + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v2 - name: Test conformance run: make conformance diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 93e58e0b..b82e0816 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,11 +15,21 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Cache Go Modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-gomod-ci-${{ hashFiles('gradle.properties', 'gradle/libs.versions.toml') }} + restore-keys: + ${{ runner.os }}-gomod-ci- + - name: Set up JDK uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '17' + java-version: '21' - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v2 diff --git a/build.gradle.kts b/build.gradle.kts index 55b0c67d..9949e294 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,6 +10,7 @@ plugins { alias(libs.plugins.errorprone) alias(libs.plugins.git) alias(libs.plugins.maven) + alias(libs.plugins.osdetector) } java { @@ -31,23 +32,20 @@ if (matchResult != null) { } val releaseVersion = project.findProperty("releaseVersion") as String? ?: snapshotVersion -val bufCLIFile = project.layout.buildDirectory.file("gobin/buf").get().asFile -val bufCLIPath: String = bufCLIFile.absolutePath +val buf: Configuration by configurations.creating val bufLicenseHeaderCLIFile = project.layout.buildDirectory.file("gobin/license-header").get().asFile val bufLicenseHeaderCLIPath: String = bufLicenseHeaderCLIFile.absolutePath -tasks.register("installBuf") { +tasks.register("configureBuf") { description = "Installs the Buf CLI." - environment("GOBIN", bufCLIFile.parentFile.absolutePath) - outputs.file(bufCLIFile) - commandLine("go", "install", "github.com/bufbuild/buf/cmd/buf@latest") + File(buf.asPath).setExecutable(true) } tasks.register("installLicenseHeader") { description = "Installs the Buf license-header CLI." environment("GOBIN", bufLicenseHeaderCLIFile.parentFile.absolutePath) outputs.file(bufLicenseHeaderCLIFile) - commandLine("go", "install", "github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@latest") + commandLine("go", "install", "github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v${libs.versions.buf.get()}") } tasks.register("licenseHeader") { @@ -69,10 +67,10 @@ tasks.register("licenseHeader") { } tasks.register("generateTestSourcesImports") { - dependsOn("installBuf") + dependsOn("configureBuf") description = "Generates code with buf generate --include-imports for unit tests." commandLine( - bufCLIPath, + buf.asPath, "generate", "--template", "src/test/resources/proto/buf.gen.imports.yaml", @@ -82,9 +80,9 @@ tasks.register("generateTestSourcesImports") { } tasks.register("generateTestSourcesNoImports") { - dependsOn("installBuf") + dependsOn("configureBuf") description = "Generates code with buf generate --include-imports for unit tests." - commandLine(bufCLIPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml", "src/test/resources/proto") + commandLine(buf.asPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml", "src/test/resources/proto") } tasks.register("generateTestSources") { @@ -93,10 +91,10 @@ tasks.register("generateTestSources") { } tasks.register("exportProtovalidateModule") { - dependsOn("installBuf") + dependsOn("configureBuf") description = "Exports the bufbuild/protovalidate module sources to src/main/resources." commandLine( - bufCLIPath, + buf.asPath, "export", "buf.build/bufbuild/protovalidate:${project.findProperty("protovalidate.version")}", "--output", @@ -105,16 +103,16 @@ tasks.register("exportProtovalidateModule") { } tasks.register("generateSources") { - dependsOn("installBuf") + dependsOn("configureBuf") description = "Generates sources for the bufbuild/protovalidate module sources to src/main/java." - commandLine(bufCLIPath, "generate", "--template", "buf.gen.yaml", "src/main/resources") + commandLine(buf.asPath, "generate", "--template", "buf.gen.yaml", "src/main/resources") } tasks.register("generateConformance") { - dependsOn("installBuf") + dependsOn("configureBuf") description = "Generates sources for the bufbuild/protovalidate-testing module to conformance/src/main/java." commandLine( - bufCLIPath, + buf.asPath, "generate", "--template", "conformance/buf.gen.yaml", @@ -193,14 +191,10 @@ allprojects { version = releaseVersion repositories { mavenCentral() - maven { - name = "buf" - url = uri("https://buf.build/gen/maven") - } } apply(plugin = "com.diffplug.spotless") configure { - setEnforceCheck(false) // Disables lint on gradle builds. + isEnforceCheck = false // Disables lint on gradle builds. java { importOrder() removeUnusedImports() @@ -276,9 +270,12 @@ dependencies { implementation(libs.ipaddress) implementation(libs.jakarta.mail.api) + buf("build.buf:buf:${libs.versions.buf.get()}:${osdetector.classifier}@exe") + testImplementation(libs.assertj) testImplementation(platform(libs.junit.bom)) testImplementation("org.junit.jupiter:junit-jupiter") + testRuntimeOnly("org.junit.platform:junit-platform-launcher") errorprone(libs.errorprone) } diff --git a/conformance/build.gradle.kts b/conformance/build.gradle.kts index 121e15c0..e9c93213 100644 --- a/conformance/build.gradle.kts +++ b/conformance/build.gradle.kts @@ -84,6 +84,7 @@ dependencies { implementation(libs.assertj) implementation(platform(libs.junit.bom)) testImplementation("org.junit.jupiter:junit-jupiter") + testRuntimeOnly("org.junit.platform:junit-platform-launcher") errorprone(libs.errorprone) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2951722f..d3f16249 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,6 @@ [versions] assertj = "3.25.3" +buf = "1.29.0" cel = "0.4.4" ipaddress = "5.5.0" junit = "5.10.2" @@ -10,6 +11,7 @@ protobuf = "3.25.3" [libraries] assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } +buf = { module = "buf.build:buf", version.ref = "buf" } cel = { module = "org.projectnessie.cel:cel-bom", version.ref = "cel" } cel-core = { module = "org.projectnessie.cel:cel-core" } 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 = errorprone = { id = "net.ltgt.errorprone", version = "3.1.0" } git = { id = "com.palantir.git-version", version = "3.0.0" } maven = { id = "com.vanniktech.maven.publish.base", version.ref = "maven-publish" } +osdetector = { id = "com.google.osdetector", version = "1.7.3" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 033e24c4..7f93135c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f862..a80b22ce 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index fcb6fca1..1aa94a42 100755 --- a/gradlew +++ b/gradlew @@ -83,7 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -201,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \