Skip to content

Commit ec30b98

Browse files
committed
chore: address code review feedback for built-in metrics
2 parents 9035de1 + 40ec408 commit ec30b98

3,095 files changed

Lines changed: 169987 additions & 13358 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: java-development
3+
description: General guidance on Java development practices, building, testing, and style in the monorepo. Use this skill when working on Java code across the repository.
4+
---
5+
6+
# Java Development Guide
7+
8+
This skill provides general guidelines for Java development inside the monorepo. It covers building, formatting, testing, and style conventions to ensure consistency across modules.
9+
10+
## Workflow
11+
12+
### 1. Building the Project
13+
14+
The repository uses Maven as its primary build system.
15+
16+
* **Build All Modules**: To build all modules from the root of the repository, run:
17+
```bash
18+
mvn install -T 1C -P quick-build
19+
```
20+
> [!TIP]
21+
> Use `-T 1C` to build modules in parallel (one thread per CPU core) and `-P quick-build` to skip unnecessary plugins for faster builds.
22+
* **Build a Specific Module**: You can also run Maven commands within a specific module directory (e.g., `java-bigquery`) to build only that module.
23+
24+
### 2. Code Formatting
25+
26+
Code formatting is enforced using the `fmt-maven-plugin`.
27+
28+
* **Check Formatting**: To check for formatting issues without modifying files, run:
29+
```bash
30+
mvn fmt:check -T 1C
31+
```
32+
* **Apply Formatting**: To automatically format the code according to the project style, run:
33+
```bash
34+
mvn fmt:format -T 1C
35+
```
36+
> [!TIP]
37+
> To save time, run `mvn fmt:format` within the specific module directory you are working on, rather than at the root.
38+
> [!NOTE]
39+
> Always run `mvn fmt:format` before committing changes to avoid build failures due to formatting.
40+
41+
### 3. Testing Strategy
42+
43+
* **Unit Tests**: Traditional unit tests should be added for individual classes and methods. Run them using:
44+
```bash
45+
mvn test -T 1C
46+
```
47+
* **Integration Tests**: Many modules have integration tests that run against live services or emulators. These may require specific profiles or environment variables. Refer to the specific module's README for details.
48+
49+
### 4. Style Guide
50+
51+
Follow these general rules to maintain code quality and consistency:
52+
53+
1. **Minimize Visibility**: Default to the most restrictive access level possible. Avoid using `public` unless the class or method is intended to be part of the public API.
54+
2. Avoid Fully Qualified Names: Use imports to keep class names short and readable, rather than using fully qualified names in the code.
55+
3. **Avoid Obsolete APIs**: Do not call methods marked with `@ObsoleteApi` or `@Deprecated` unless there are no viable alternatives.
56+
4. **Clean Diffs**: Avoid unnecessary formatting changes or whitespace modifications to keep diffs clean and easy to review.
57+
58+
### 5. Dependency Management
59+
60+
* **Version Bumps**: Try not to bump any external dependency versions unless there is a known security vulnerability (CVE) or a critical bug fix.
61+
* **New Dependencies**: Avoid introducing new external dependencies. If a new dependency is required, provide a strong justification in the pull request.
62+
* **Standard Library First**: Prefer to use features from the Java standard library, followed by existing dependencies in the project (preferably Google-managed dependencies).
63+
64+
### 6. Contribution Guidelines
65+
66+
* **Commit Messages**: Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification. Include the module as the scope (e.g., `feat(spanner): ...`, `fix(bigquery): ...`).
67+
* **Pull Requests**: All code changes must be submitted via a pull request and require review. Ensure you pull the latest changes from `main` and resolve any conflicts before submitting.

.github/workflows/ci.yaml

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
ci: ${{ steps.filter.outputs.ci }}
3232
steps:
3333
- uses: actions/checkout@v4
34-
- uses: dorny/paths-filter@v3
34+
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
3535
id: filter
3636
with:
3737
# we want to run tests if source code is changed or the scripts
@@ -40,6 +40,14 @@ jobs:
4040
src:
4141
- '**/*.java'
4242
- '**/pom.xml'
43+
- '!java-bigquery/**'
44+
- '!java-bigquerystorage/**'
45+
- '!java-datastore/**'
46+
- '!java-logging-logback/**'
47+
- '!java-logging/**'
48+
- '!java-spanner/**'
49+
- '!java-storage/**'
50+
- '!google-auth-library-java/**'
4351
ci:
4452
- '.github/workflows/ci.yaml'
4553
- '.kokoro/**'
@@ -113,18 +121,58 @@ jobs:
113121
outputs:
114122
packages: ${{ steps.filter.outputs.changes }}
115123
steps:
116-
- uses: dorny/paths-filter@v4
124+
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
117125
id: filter
118126
with:
127+
# For each library, run CI in split repos where there are changes in:
128+
# 1. Changes inside the split repo's module
129+
# 2. Java code changes in upstream modules: Auth Library and Sdk-Platform-Java
130+
# 3. Upstream dependency version changes: Shared-Deps and Gapic-Generator-Pom-Parent
119131
filters: |
120-
java-bigquery: java-bigquery/**
121-
java-bigquerystorage: java-bigquerystorage/**
122-
java-datastore: java-datastore/**
123-
java-logging-logback: java-logging-logback/**
124-
java-logging: java-logging/**
125-
java-spanner: java-spanner/**
126-
java-storage: java-storage/**
127-
sdk-platform-java: sdk-platform-java/**
132+
google-auth-library-java:
133+
- 'google-auth-library-java/**'
134+
java-bigquery:
135+
- 'java-bigquery/**'
136+
- 'google-auth-library-java/**/*.java'
137+
- 'sdk-platform-java/**/*.java'
138+
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
139+
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
140+
java-bigquerystorage:
141+
- 'java-bigquerystorage/**'
142+
- 'google-auth-library-java/**/*.java'
143+
- 'sdk-platform-java/**/*.java'
144+
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
145+
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
146+
java-datastore:
147+
- 'java-datastore/**'
148+
- 'google-auth-library-java/**/*.java'
149+
- 'sdk-platform-java/**/*.java'
150+
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
151+
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
152+
java-logging-logback:
153+
- 'java-logging-logback/**'
154+
- 'google-auth-library-java/**/*.java'
155+
- 'sdk-platform-java/**/*.java'
156+
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
157+
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
158+
java-logging:
159+
- 'java-logging/**'
160+
- 'google-auth-library-java/**/*.java'
161+
- 'sdk-platform-java/**/*.java'
162+
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
163+
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
164+
java-spanner:
165+
- 'java-spanner/**'
166+
- 'google-auth-library-java/**/*.java'
167+
- 'sdk-platform-java/**/*.java'
168+
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
169+
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
170+
java-storage:
171+
- 'java-storage/**'
172+
- 'google-auth-library-java/**/*.java'
173+
- 'sdk-platform-java/**/*.java'
174+
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
175+
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
128176
split-units:
129177
runs-on: ubuntu-latest
130178
needs: changes
@@ -198,6 +246,17 @@ jobs:
198246
JOB_TYPE: test
199247
JOB_NAME: units-8-runtime-${{matrix.java}}
200248
working-directory: ${{matrix.package}}
249+
required:
250+
needs: [ changes, split-units ]
251+
name: conditional-required-check
252+
if: ${{ always() }} # Always run even if any "needs" jobs fail
253+
runs-on: ubuntu-22.04
254+
steps:
255+
- name: Fail if any previous failure
256+
if: ${{ needs.changes.outputs.packages != '[]' && contains(needs.*.result, 'failure') }}
257+
run: exit 1
258+
- name: Success otherwise
259+
run: echo "Success!"
201260
windows:
202261
runs-on: windows-latest
203262
steps:
@@ -273,41 +332,14 @@ jobs:
273332
- name: validate generation configuration
274333
shell: bash
275334
run: |
276-
docker run \
277-
--rm \
335+
bash generation/run_generator_docker.sh "${library_generation_image_tag}" "${{ github.base_ref || 'main' }}" \
336+
-e GENERATOR_VERSION="${library_generation_image_tag}" \
278337
--quiet \
279338
-u "$(id -u):$(id -g)" \
280339
-v "$(pwd):${workspace_name}" \
281340
--entrypoint python \
282-
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
341+
-- \
283342
/src/library_generation/cli/entry_point.py validate-generation-config
284343
env:
285344
library_generation_image_tag: 2.68.0
286345
workspace_name: /workspace
287-
288-
# TODO: Uncomment the needed Github Actions
289-
# dependencies:
290-
# runs-on: ubuntu-latest
291-
# strategy:
292-
# matrix:
293-
# java: [8, 11, 17]
294-
# steps:
295-
# - uses: actions/checkout@v3
296-
# - uses: actions/setup-java@v3
297-
# with:
298-
# distribution: zulu
299-
# java-version: ${{matrix.java}}
300-
# - run: java -version
301-
# - run: .kokoro/dependencies.sh
302-
# clirr:
303-
# runs-on: ubuntu-latest
304-
# steps:
305-
# - uses: actions/checkout@v3
306-
# - uses: actions/setup-java@v3
307-
# with:
308-
# distribution: zulu
309-
# java-version: 8
310-
# - run: java -version
311-
# - run: .kokoro/build.sh
312-
# env:
313-
# JOB_TYPE: clirr

.github/workflows/sdk-platform-java-create_additional_release_tag.yaml renamed to .github/workflows/create_additional_release_tag.yaml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
name: sdk-platform-java Create additional tags for each release
1+
name: Create additional tags for each release
22

33
on:
44
release:
55
types: [published]
66
workflow_dispatch:
7-
8-
env:
9-
BUILD_SUBDIR: sdk-platform-java
107
jobs:
11-
filter:
12-
runs-on: ubuntu-latest
13-
outputs:
14-
library: ${{ steps.filter.outputs.library }}
15-
steps:
16-
- uses: actions/checkout@v4
17-
- uses: dorny/paths-filter@v3
18-
id: filter
19-
with:
20-
filters: |
21-
library:
22-
- 'sdk-platform-java/**'
238
build:
24-
needs: filter
25-
if: ${{ needs.filter.outputs.library == 'true' }}
269
runs-on: ubuntu-latest
2710
permissions:
2811
# Permission to create tag
@@ -32,7 +15,7 @@ jobs:
3215
- name: Checkout code
3316
uses: actions/checkout@v4
3417
with:
35-
token: ${{ secrets.GITHUB_TOKEN }}
18+
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
3619
- name: Set up Git
3720
run: |
3821
git config --local user.email "action@github.com"

.github/workflows/generated_files_sync.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
pull_request:
1818
name: generation diff
1919
env:
20-
library_generation_image_tag: 2.70.0 # {x-version-update:gapic-generator-java:current}
20+
library_generation_image_tag: 2.71.0 # {x-version-update:gapic-generator-java:current}
2121
jobs:
2222
root-pom:
2323
# root pom.xml does not have diff from generated one
@@ -27,13 +27,12 @@ jobs:
2727
- name: Generate root pom.xml file
2828
shell: bash
2929
run: |
30-
docker run \
31-
--rm \
30+
bash generation/run_generator_docker.sh "${library_generation_image_tag}" "${{ github.base_ref }}" \
3231
--quiet \
3332
-u "$(id -u):$(id -g)" \
3433
-v "$(pwd):/workspace" \
3534
--entrypoint python \
36-
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
35+
-- \
3736
/src/library_generation/cli/generate_monorepo_root_pom.py \
3837
generate \
3938
--repository-path=/workspace
@@ -48,13 +47,12 @@ jobs:
4847
- name: Generate gapic-libraries-bom/pom.xml
4948
shell: bash
5049
run: |
51-
docker run \
52-
--rm \
50+
bash generation/run_generator_docker.sh "${library_generation_image_tag}" "${{ github.base_ref }}" \
5351
--quiet \
5452
-u "$(id -u):$(id -g)" \
5553
-v "$(pwd):/workspace" \
5654
--entrypoint python \
57-
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
55+
-- \
5856
/src/library_generation/cli/generate_monorepo_gapic_bom.py \
5957
generate \
6058
--repository-path=/workspace \

.github/workflows/google-auth-library-java-ci.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ jobs:
2828
library: ${{ steps.filter.outputs.library }}
2929
steps:
3030
- uses: actions/checkout@v4
31-
- uses: dorny/paths-filter@v3
31+
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
3232
id: filter
3333
with:
3434
filters: |
3535
library:
3636
- 'google-auth-library-java/**'
37+
- '.github/workflows/google-auth-library-java-ci.yaml'
3738
units-logging:
3839
needs: filter
3940
if: ${{ needs.filter.outputs.library == 'true' }}
@@ -54,3 +55,14 @@ jobs:
5455
BUILD_SUBDIR: google-auth-library-java
5556
JOB_TYPE: test
5657
SUREFIRE_JVM_OPT: "-P '!slf4j2x,slf4j2x-test'"
58+
required:
59+
needs: [ units-logging ]
60+
name: conditional-required-check
61+
if: ${{ always() }} # Always run even if any "needs" jobs fail
62+
runs-on: ubuntu-22.04
63+
steps:
64+
- name: Fail if any previous failure
65+
if: ${{ contains(needs.*.result, 'failure') }}
66+
run: exit 1
67+
- name: Success otherwise
68+
run: echo "Success!"

0 commit comments

Comments
 (0)