Skip to content
Closed
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .github/workflows/java-bigquerystorage-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- uses: actions/setup-java@v2
with:
distribution: temurin
Expand All @@ -122,3 +124,5 @@ jobs:
- run: .kokoro/build.sh
env:
JOB_TYPE: lint
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
4 changes: 4 additions & 0 deletions .github/workflows/java-datastore-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: temurin
Expand All @@ -145,3 +147,5 @@ jobs:
- run: .kokoro/build.sh
env:
JOB_TYPE: lint
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
4 changes: 4 additions & 0 deletions .github/workflows/java-logging-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: temurin
Expand All @@ -137,3 +139,5 @@ jobs:
- run: .kokoro/build.sh
env:
JOB_TYPE: lint
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
4 changes: 4 additions & 0 deletions .github/workflows/java-logging-logback-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: temurin
Expand All @@ -137,3 +139,5 @@ jobs:
- run: .kokoro/build.sh
env:
JOB_TYPE: lint
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
64 changes: 56 additions & 8 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,19 @@ case ${JOB_TYPE} in
echo "Running in subdir: ${BUILD_SUBDIR}"
pushd "${BUILD_SUBDIR}"
fi

MODULE_FILTER=""

if [ -n "${BASE_SHA}" ] && [ -n "${HEAD_SHA}" ]; then
changed_file_list=$(git diff --name-only "${BASE_SHA}" "${HEAD_SHA}")
# Optimize the build by identifying ONLY the Maven modules that contain changed Java source files.
# Format those specific modules instead of the entire codebase, reducing format check time.
# The --relative flag is when building in the submodule as only files modified in the module
# should be accounted for.
changed_file_list=$(git diff --name-only "${BASE_SHA}" "${HEAD_SHA}" --relative)
echo "${changed_file_list}"

has_code_change="false"

while IFS= read -r changed_file; do
# Checks if the line is not empty AND if it matches a .java file
if [ -n "${changed_file}" ] && [[ "${changed_file}" == *.java ]]; then
Expand All @@ -208,19 +215,60 @@ case ${JOB_TYPE} in
break
fi
done <<< "${changed_file_list}"

if [ "${has_code_change}" == "false" ]; then
echo "No java modules affected. Skipping linter check."
exit 0
fi

# Compute list of changed Maven modules from changed Java files.
# We walk each changed .java file up to its nearest pom.xml to find the correct module.
# e.g., if "java-asset/google-cloud-asset/src/main/java/Foo.java" is changed,
# it traverses upward until finding "java-asset/google-cloud-asset/pom.xml" and adds that module.
changed_modules=()
while IFS= read -r changed_file; do
if [ -n "${changed_file}" ] && [[ "${changed_file}" == *.java ]]; then
dir=$(dirname "${changed_file}")
while [ "${dir}" != "." ] && [ ! -f "${dir}/pom.xml" ]; do
dir=$(dirname "${dir}")
done
if [ -f "${dir}/pom.xml" ] && [ "${dir}" != "." ]; then
# Filter out directories not participating in the default formatting reactor:
# - samples are handwritten by developers
# - proto-*/grpc-* are generated code and should use the compiler format
# - *-bom/parents are POM-only and contain no Java source
if [[ "${dir}" != *"samples"* ]] && \
[[ "$(basename "${dir}")" != "proto-google-"* ]] && \
[[ "$(basename "${dir}")" != "grpc-google-"* ]] && \
[[ "$(basename "${dir}")" != *"-bom" ]] && \
[[ "$(basename "${dir}")" != "google-cloud-pom-parent" ]] && \
[[ "$(basename "${dir}")" != "google-cloud-jar-parent" ]]; then

changed_modules+=("${dir}")
fi
fi
fi
done <<< "${changed_file_list}"

echo "Changed Modules: ${changed_modules[*]}"

# Deduplicate the modules using sort -u to pass a concise list of unique modules
# via the Maven `-pl` argument.
if [ ${#changed_modules[@]} -gt 0 ]; then
unique_modules=$(printf '%s\n' "${changed_modules[@]}" | sort -u | paste -sd ',' -)
MODULE_FILTER="-pl ${unique_modules}"
echo "Formatting only changed modules: ${unique_modules}"
fi
else
echo "BASE_SHA or HEAD_SHA is empty. Skipping file difference check."
echo "BASE_SHA or HEAD_SHA is empty. Cannot continue linting."
exit 1
fi

mvn -B -ntp \
-T 1.5C \
-T 1C \
${MODULE_FILTER} \
com.spotify.fmt:fmt-maven-plugin:check
mvn -B -ntp checkstyle:check@checkstyle
mvn -B -ntp ${MODULE_FILTER} checkstyle:check@checkstyle

if [[ -n "${BUILD_SUBDIR}" ]]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1837,4 +1837,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ public interface DeleteAccessApprovalSettingsMessageOrBuilder
* @return The bytes for name.
*/
com.google.protobuf.ByteString getNameBytes();
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -2068,4 +2068,6 @@ public void testIamPermissionsExceptionTest() throws Exception {
// Expected exception.
}
}
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -4569,4 +4569,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,5 @@ private DeviceEncryptionStatus(int value) {
}

// @@protoc_insertion_point(enum_scope:google.identity.accesscontextmanager.type.DeviceEncryptionStatus)
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -858,4 +858,5 @@ public com.google.protobuf.Parser<GetAccessLevelRequest> getParserForType() {
getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -804,4 +804,5 @@ public void batchDeactivateCustomFieldsExceptionTest2() throws Exception {
// Expected exception.
}
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,6 @@ public MobileDeviceSubmodelName build() {
return new MobileDeviceSubmodelName(this);
}
}
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,5 @@ public void updateSettingsExceptionTest() throws Exception {
// Expected exception.
}
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -848,4 +848,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -2505,4 +2505,6 @@ public com.google.protobuf.Parser<Message> getParserForType() {
public com.google.cloud.advisorynotifications.v1.Message getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ public ServerServiceDefinition getServiceDefinition() {
public void reset() {
serviceImpl.reset();
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -998,4 +998,6 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -1018,4 +1018,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -1309,4 +1309,5 @@ public com.google.protobuf.Parser<AddContextArtifactsAndExecutionsRequest> getPa
getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -1320,4 +1320,5 @@ public com.google.protobuf.Parser<AddContextArtifactsAndExecutionsRequest> getPa
getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ public interface MetadataExchangeRequestOrBuilder
* @return The bytes for oauth2Token.
*/
com.google.protobuf.ByteString getOauth2TokenBytes();
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ public interface MetadataExchangeRequestOrBuilder
* @return The bytes for oauth2Token.
*/
com.google.protobuf.ByteString getOauth2TokenBytes();
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@ public interface MetadataExchangeRequestOrBuilder
* @return The bytes for oauth2Token.
*/
com.google.protobuf.ByteString getOauth2TokenBytes();
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ public ServerServiceDefinition getServiceDefinition() {
public void reset() {
serviceImpl.reset();
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,6 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ public interface BackupSourceOrBuilder
* @return The bytes for backupName.
*/
com.google.protobuf.ByteString getBackupNameBytes();
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ public interface BackupSourceOrBuilder
* @return The bytes for backupName.
*/
com.google.protobuf.ByteString getBackupNameBytes();
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ public interface BackupSourceOrBuilder
* @return The bytes for backupName.
*/
com.google.protobuf.ByteString getBackupNameBytes();
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -3438,4 +3438,6 @@ public void getReportingIdentitySettings(
Exception.class.getName())));
}
}
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -22393,4 +22393,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -7960,4 +7960,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,5 @@ public EventCreateRuleName build() {
return new EventCreateRuleName(this);
}
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,5 @@ public interface CustomDimensionOrBuilder
* @return The disallowAdsPersonalization.
*/
boolean getDisallowAdsPersonalization();
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -1269,4 +1269,5 @@ public void listReportTasksExceptionTest2() throws Exception {
// Expected exception.
}
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -2863,4 +2863,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -2244,4 +2244,6 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,5 @@ com.google.analytics.data.v1alpha.DimensionHeaderOrBuilder getDimensionHeadersOr
* <code>.google.analytics.data.v1alpha.ResponseMetaData metadata = 8;</code>
*/
com.google.analytics.data.v1alpha.ResponseMetaDataOrBuilder getMetadataOrBuilder();
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -938,4 +938,5 @@ public com.google.protobuf.Parser<CreateAudienceExportRequest> getParserForType(
public com.google.analytics.data.v1beta.CreateAudienceExportRequest getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ public ServerServiceDefinition getServiceDefinition() {
public void reset() {
serviceImpl.reset();
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -4317,4 +4317,5 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
}
return result;
}
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ public interface DestinationDatasetReferenceOrBuilder
* @return The bytes for projectId.
*/
com.google.protobuf.ByteString getProjectIdBytes();
// Simulated PR Change
// Simulated PR Change
}
Original file line number Diff line number Diff line change
Expand Up @@ -1549,4 +1549,6 @@ public void deleteApiConfigExceptionTest2() throws Exception {
} catch (ExecutionException e) {
}
}
// Simulated PR Change
// Simulated PR Change
}
Loading
Loading