Skip to content

Commit dba264e

Browse files
authored
Merge branch 'main' into main
2 parents de8e6b2 + d1585fc commit dba264e

2,554 files changed

Lines changed: 200509 additions & 14158 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/release-note-generation/split_release_note.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def detect_modules(root_directory: Path):
6969
tree = ET.parse(module_pom_xml)
7070
root = tree.getroot()
7171
version = root.find('mvn:version', POM_NAMESPACES).text
72+
api_name = None
7273
if owlbot_yaml_path.exists():
7374
# If OwlBot configuration file exists (most cases), it's the better
7475
# source to get the OwlBot-generated pull request title prefix than
@@ -78,21 +79,21 @@ def detect_modules(root_directory: Path):
7879
match = re.search(r'api-name: (.+)', owlbot_yaml_content)
7980
if match:
8081
api_name = match.group(1)
81-
modules.append(LibraryModule(module_path, api_name,
82-
version,
83-
changelog))
82+
83+
if not api_name:
84+
# Fallback to repo-metadata.json (e.g. for vertexai or Spanner transitional state)
85+
if repo_metadata_path.exists():
86+
with open(repo_metadata_path, 'r') as file:
87+
repo_metadata = json.load(file)
88+
api_name = repo_metadata.get('api_shortname')
89+
90+
if api_name:
91+
modules.append(LibraryModule(module_path, api_name,
92+
version,
93+
changelog))
8494
else:
85-
# vertexai (handwritten) does not have OwlBot yaml file
86-
with open(repo_metadata_path, 'r') as file:
87-
repo_metadata = json.load(file)
88-
api_name = repo_metadata['api_shortname']
89-
if api_name:
90-
modules.append(LibraryModule(repo_metadata_path.parent, api_name,
91-
version,
92-
changelog))
93-
else:
94-
raise Exception(f'repo_metadata_path {repo_metadata_path} does'
95-
f' not have api_shortname field')
95+
raise Exception(f'Could not determine api-name for {repo_metadata_path}')
96+
9697

9798
return modules
9899

@@ -133,7 +134,7 @@ def group_changes_by_api(main_changes: [str]):
133134
elif section == BUG_FIXES_SECTION:
134135
api_to_changelog[api_name].bug_fixes.append(note)
135136
elif section == DEPENDENCIES_SECTION:
136-
api_to_changelog[api_name].dependencies.append(note)
137+
api_to_changelog[api_name].dependency_upgrades.append(note)
137138
return api_to_changelog
138139

139140

.github/release-note-generation/unit_test.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import unittest
2+
import tempfile
3+
import json
4+
from pathlib import Path
25

36
# Unit tests for split_release_note.py
47

5-
from split_release_note import LibraryModule, create_changelog_entry, group_changes_by_api, ChangesOnApi
6-
from pathlib import Path
8+
from split_release_note import LibraryModule, create_changelog_entry, group_changes_by_api, ChangesOnApi, detect_modules
79

810
dummy_module = LibraryModule(
911
Path('release-note-generation/test/java-analyics-admin'),
@@ -81,6 +83,31 @@ def test_group_changes_by_api(self):
8183
['No change']),
8284
['No change'])
8385

86+
def test_detect_modules_fallback(self):
87+
with tempfile.TemporaryDirectory() as tmpdirname:
88+
tmp_path = Path(tmpdirname)
89+
module_path = tmp_path / "java-spanner"
90+
module_path.mkdir()
91+
92+
# Create minimal pom.xml
93+
pom_path = module_path / "pom.xml"
94+
with open(pom_path, "w") as f:
95+
f.write('<project xmlns:mvn="http://maven.apache.org/POM/4.0.0"><mvn:version>1.0.0</mvn:version></project>')
96+
97+
# Create .repo-metadata.json with api_shortname
98+
metadata_path = module_path / ".repo-metadata.json"
99+
with open(metadata_path, "w") as f:
100+
json.dump({"api_shortname": "spanner"}, f)
101+
102+
# Create CHANGELOG.md
103+
changelog_path = module_path / "CHANGELOG.md"
104+
changelog_path.touch()
105+
106+
modules = detect_modules(tmp_path)
107+
self.assertEqual(len(modules), 1)
108+
self.assertEqual(modules[0].api_name, "spanner")
109+
self.assertEqual(modules[0].version, "1.0.0")
110+
84111

85112
if __name__ == "__main__":
86113
unittest.main()

.github/workflows/ci.yaml

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ 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:
37-
# we want to run tests if source code is changed or the scripts
38-
# used to run the unit tests
3937
filters: |
4038
src:
41-
- '**/*.java'
42-
- '**/pom.xml'
39+
- '!(java-bigquery|java-bigquerystorage|java-datastore|java-logging-logback|java-logging|java-spanner|java-storage|google-auth-library-java)/**/*.java'
40+
- '!(java-bigquery|java-bigquerystorage|java-datastore|java-logging-logback|java-logging|java-spanner|java-storage|google-auth-library-java)/**/pom.xml'
41+
- 'pom.xml'
4342
ci:
4443
- '.github/workflows/ci.yaml'
4544
- '.kokoro/**'
@@ -113,53 +112,62 @@ jobs:
113112
outputs:
114113
packages: ${{ steps.filter.outputs.changes }}
115114
steps:
116-
- uses: dorny/paths-filter@v4
115+
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
117116
id: filter
118117
with:
119118
# For each library, run CI in split repos where there are changes in:
120119
# 1. Changes inside the split repo's module
121120
# 2. Java code changes in upstream modules: Auth Library and Sdk-Platform-Java
122121
# 3. Upstream dependency version changes: Shared-Deps and Gapic-Generator-Pom-Parent
123122
filters: |
123+
google-auth-library-java:
124+
- 'google-auth-library-java/**'
124125
java-bigquery:
125126
- 'java-bigquery/**'
126127
- 'google-auth-library-java/**/*.java'
128+
- 'google-auth-library-java/**/pom.xml'
127129
- 'sdk-platform-java/**/*.java'
128130
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
129131
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
130132
java-bigquerystorage:
131133
- 'java-bigquerystorage/**'
132134
- 'google-auth-library-java/**/*.java'
135+
- 'google-auth-library-java/**/pom.xml'
133136
- 'sdk-platform-java/**/*.java'
134137
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
135138
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
136139
java-datastore:
137140
- 'java-datastore/**'
138141
- 'google-auth-library-java/**/*.java'
142+
- 'google-auth-library-java/**/pom.xml'
139143
- 'sdk-platform-java/**/*.java'
140144
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
141145
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
142146
java-logging-logback:
143147
- 'java-logging-logback/**'
144148
- 'google-auth-library-java/**/*.java'
149+
- 'google-auth-library-java/**/pom.xml'
145150
- 'sdk-platform-java/**/*.java'
146151
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
147152
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
148153
java-logging:
149154
- 'java-logging/**'
150155
- 'google-auth-library-java/**/*.java'
156+
- 'google-auth-library-java/**/pom.xml'
151157
- 'sdk-platform-java/**/*.java'
152158
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
153159
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
154160
java-spanner:
155161
- 'java-spanner/**'
156162
- 'google-auth-library-java/**/*.java'
163+
- 'google-auth-library-java/**/pom.xml'
157164
- 'sdk-platform-java/**/*.java'
158165
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
159166
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
160167
java-storage:
161168
- 'java-storage/**'
162169
- 'google-auth-library-java/**/*.java'
170+
- 'google-auth-library-java/**/pom.xml'
163171
- 'sdk-platform-java/**/*.java'
164172
- 'sdk-platform-java/java-shared-dependencies/**/pom.xml'
165173
- 'sdk-platform-java/gapic-generator-java-pom-parent/pom.xml'
@@ -236,6 +244,49 @@ jobs:
236244
JOB_TYPE: test
237245
JOB_NAME: units-8-runtime-${{matrix.java}}
238246
working-directory: ${{matrix.package}}
247+
split-clirr:
248+
runs-on: ubuntu-latest
249+
needs: changes
250+
strategy:
251+
matrix:
252+
package: ${{ fromJSON(needs.changes.outputs.packages) }}
253+
steps:
254+
- uses: actions/checkout@v4
255+
- uses: actions/setup-java@v4
256+
with:
257+
distribution: temurin
258+
java-version: 11
259+
- run: .kokoro/build.sh
260+
env:
261+
BUILD_SUBDIR: ${{matrix.package}}
262+
JOB_TYPE: clirr
263+
JOB_NAME: clirr-${{matrix.package}}
264+
split-dependencies:
265+
runs-on: ubuntu-latest
266+
needs: changes
267+
strategy:
268+
matrix:
269+
package: ${{ fromJSON(needs.changes.outputs.packages) }}
270+
steps:
271+
- uses: actions/checkout@v4
272+
- uses: actions/setup-java@v4
273+
with:
274+
distribution: temurin
275+
java-version: 17
276+
- run: .kokoro/dependencies.sh
277+
env:
278+
BUILD_SUBDIR: ${{matrix.package}}
279+
required:
280+
needs: [ changes, split-units, split-clirr, split-dependencies ]
281+
name: conditional-required-check
282+
if: ${{ always() }} # Always run even if any "needs" jobs fail
283+
runs-on: ubuntu-22.04
284+
steps:
285+
- name: Fail if any previous failure
286+
if: ${{ needs.changes.outputs.packages != '[]' && contains(needs.*.result, 'failure') }}
287+
run: exit 1
288+
- name: Success otherwise
289+
run: echo "Success!"
239290
windows:
240291
runs-on: windows-latest
241292
steps:
@@ -311,41 +362,14 @@ jobs:
311362
- name: validate generation configuration
312363
shell: bash
313364
run: |
314-
docker run \
315-
--rm \
365+
bash generation/run_generator_docker.sh "${library_generation_image_tag}" "${{ github.base_ref || 'main' }}" \
366+
-e GENERATOR_VERSION="${library_generation_image_tag}" \
316367
--quiet \
317368
-u "$(id -u):$(id -g)" \
318369
-v "$(pwd):${workspace_name}" \
319370
--entrypoint python \
320-
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
371+
-- \
321372
/src/library_generation/cli/entry_point.py validate-generation-config
322373
env:
323374
library_generation_image_tag: 2.68.0
324375
workspace_name: /workspace
325-
326-
# TODO: Uncomment the needed Github Actions
327-
# dependencies:
328-
# runs-on: ubuntu-latest
329-
# strategy:
330-
# matrix:
331-
# java: [8, 11, 17]
332-
# steps:
333-
# - uses: actions/checkout@v3
334-
# - uses: actions/setup-java@v3
335-
# with:
336-
# distribution: zulu
337-
# java-version: ${{matrix.java}}
338-
# - run: java -version
339-
# - run: .kokoro/dependencies.sh
340-
# clirr:
341-
# runs-on: ubuntu-latest
342-
# steps:
343-
# - uses: actions/checkout@v3
344-
# - uses: actions/setup-java@v3
345-
# with:
346-
# distribution: zulu
347-
# java-version: 8
348-
# - run: java -version
349-
# - run: .kokoro/build.sh
350-
# env:
351-
# 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"

0 commit comments

Comments
 (0)