Skip to content

Commit

Permalink
CI improvements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pkwarren committed Mar 5, 2024
1 parent 1445f7d commit 97cd5ce
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 40 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 19 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
alias(libs.plugins.errorprone)
alias(libs.plugins.git)
alias(libs.plugins.maven)
alias(libs.plugins.osdetector)
}

java {
Expand All @@ -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<Exec>("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<Exec>("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<Exec>("licenseHeader") {
Expand All @@ -69,10 +67,10 @@ tasks.register<Exec>("licenseHeader") {
}

tasks.register<Exec>("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",
Expand All @@ -82,9 +80,9 @@ tasks.register<Exec>("generateTestSourcesImports") {
}

tasks.register<Exec>("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") {
Expand All @@ -93,10 +91,10 @@ tasks.register("generateTestSources") {
}

tasks.register<Exec>("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",
Expand All @@ -105,16 +103,16 @@ tasks.register<Exec>("exportProtovalidateModule") {
}

tasks.register<Exec>("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<Exec>("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",
Expand Down Expand Up @@ -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<SpotlessExtension> {
setEnforceCheck(false) // Disables lint on gradle builds.
isEnforceCheck = false // Disables lint on gradle builds.
java {
importOrder()
removeUnusedImports()
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions conformance/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" }
Expand All @@ -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" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -144,15 +145,15 @@ 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
case $MAX_FD in #(
'' | 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
Expand Down Expand Up @@ -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" \
Expand Down

0 comments on commit 97cd5ce

Please sign in to comment.