Skip to content

Commit f625b6d

Browse files
committed
feat(java): add github workflows and update bazel configuration to prepare for a java implementation
1 parent 267ead1 commit f625b6d

File tree

9 files changed

+698
-88
lines changed

9 files changed

+698
-88
lines changed

.github/workflows/java.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
name: Java checks
18+
19+
on:
20+
push:
21+
branches:
22+
- main
23+
paths:
24+
- "java/**"
25+
- "spec/**"
26+
- ".github/workflows/java.yml"
27+
pull_request:
28+
paths:
29+
- "java/**"
30+
- "spec/**"
31+
- ".github/workflows/java.yml"
32+
33+
jobs:
34+
tests:
35+
runs-on: ubuntu-latest
36+
strategy:
37+
matrix:
38+
java-version: ['17', '21', '23', '24']
39+
fail-fast: false
40+
41+
name: Java ${{ matrix.java-version }} Tests
42+
steps:
43+
- uses: actions/checkout@v4
44+
45+
- name: Set up JDK ${{ matrix.java-version }}
46+
uses: actions/setup-java@v4
47+
with:
48+
java-version: ${{ matrix.java-version }}
49+
distribution: 'temurin'
50+
51+
- name: Setup Bazel
52+
uses: bazelbuild/setup-bazelisk@v3
53+
54+
- name: Run Tests
55+
# Force Bazel to use the local JDK setup by actions/setup-java
56+
run: |
57+
bazel test \
58+
--java_runtime_version=local_jdk \
59+
--tool_java_runtime_version=local_jdk \
60+
--test_output=errors \
61+
//java/com/google/dotprompt:all \
62+
//java/com/google/dotprompt/smoke:SmokeTest

.github/workflows/publish_java.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
name: Publish Java Package
18+
#
19+
# Requirements for this workflow:
20+
#
21+
# 1. Secrets must be configured in the repository settings:
22+
# - OSSRH_USERNAME: The username for Sonatype OSSRH (Maven Central).
23+
# - OSSRH_TOKEN: The password or token for Sonatype OSSRH.
24+
# - MAVEN_GPG_PRIVATE_KEY: The ASCII-armored GPG private key for signing artifacts.
25+
# - MAVEN_GPG_PASSPHRASE: The passphrase for the GPG private key.
26+
#
27+
# 2. GPG Key Formatting:
28+
# - The private key should be exported using: `gpg --armor --export-secret-keys <ID>`
29+
# - Ensure the key has no empty lines or formatting issues when pasted into GitHub Secrets.
30+
#
31+
32+
on:
33+
release:
34+
types: [created]
35+
36+
jobs:
37+
publish-java:
38+
runs-on: ubuntu-latest
39+
permissions:
40+
contents: read
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Set up JDK 21
45+
uses: actions/setup-java@v4
46+
with:
47+
java-version: '21'
48+
distribution: 'temurin'
49+
50+
- name: Setup Bazel
51+
uses: bazelbuild/setup-bazelisk@v3
52+
53+
- name: Import GPG key
54+
id: import_gpg
55+
uses: crazy-max/ghaction-import-gpg@v6
56+
with:
57+
gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
58+
passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
59+
60+
- name: Publish to Maven Central
61+
env:
62+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
63+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
64+
run: |
65+
./scripts/publish-java.sh \
66+
"${{ steps.import_gpg.outputs.keyring }}" \
67+
"${{ secrets.MAVEN_GPG_PASSPHRASE }}" \
68+
"$MAVEN_USERNAME" \
69+
"$MAVEN_PASSWORD"

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ bazel_dep(name = "platforms", version = "1.0.0")
2828
include("//:go.MODULE.bazel")
2929
include("//:java.MODULE.bazel")
3030
include("//:rust.MODULE.bazel")
31+
include("//:kotlin.MODULE.bazel")
3132
include("//:ts.MODULE.bazel")

MODULE.bazel.lock

Lines changed: 203 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/contributing/coding_guidelines.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ You are an expert Python developer contributing to the Google Dotprompt project.
77
- **Language**: Python.
88
- **Environment Management**: Use `uv` for packaging and environment management.
99

10+
### Libraries
11+
- **JSON**: Use **Jackson** for JSON parsing and serialization. Avoid Gson.
12+
- **Testing**: Use **Google Truth** (`com.google.truth.Truth`) for assertions. Use JUnit 4/5 for test runners.
13+
- **Utilities**: Use **Guava** for immutable collections and common utilities.
14+
- **Dependency Injection**: Use **Dagger** for dependency injection.
15+
1016
## 2. Typing & Style
1117
- **Type Unions**: Use the pipe operator `|` (PEP 604) for union types (e.g., `int | str`) instead of `typing.Union`. Use `| None` for optional types.
1218
- **Generics**: Use standard collection generics (PEP 585) like `list`, `dict`, `tuple` (lowercase) for type hints instead of `typing.List`, `typing.Dict`.

java.MODULE.bazel

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,19 @@ java_toolchain = use_repo_rule("@rules_java//java:repositories.bzl", "java_toolc
2525

2626
java_toolchain(
2727
name = "jdk",
28-
version = "21",
28+
version = "17",
2929
)
3030

3131
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
32-
33-
# Overriding these versions to prevent duplicate version warnings.
34-
maven.artifact(
35-
name = "guava",
36-
artifact = "com.google.guava:guava:33.4.8-jre",
37-
group = "com.google.guava",
38-
version = "33.4.8-jre",
39-
)
40-
maven.artifact(
41-
name = "truth",
42-
artifact = "com.google.truth:truth:1.4.4",
43-
group = "com.google.truth",
44-
version = "1.4.4",
45-
)
4632
maven.install(
4733
artifacts = [
4834
"junit:junit:4.13.2",
4935
"com.google.truth.extensions:truth-proto-extension:1.4.4",
5036
"com.google.truth:truth:1.4.4",
5137
"com.github.jknack:handlebars:4.4.0",
52-
"com.google.guava:guava:33.4.8-jre",
38+
"com.google.guava:guava:33.5.0-jre",
39+
"com.fasterxml.jackson.core:jackson-databind:2.20.1",
40+
"com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.20.1",
5341
],
5442
lock_file = "//:maven_install.json",
5543
repositories = [

java.bazelrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ common:java21 --tool_java_language_version=21
88
common:java21 --java_runtime_version=remotejdk_21
99
common:java21 --tool_java_runtime_version=remotejdk_21
1010

11-
common --config=java21
11+
common:java24 --java_language_version=24
12+
common:java24 --tool_java_language_version=24
13+
common:java24 --java_runtime_version=remotejdk_24
14+
common:java24 --tool_java_runtime_version=remotejdk_24
15+
16+
common --config=java17
1217

1318
# =============================================================================
1419
# junit_test is incompatible with JDK 18+ -

kotlin.MODULE.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
"""Configuration for Bazel with Kotlin dependencies."""
18+
19+
bazel_dep(name = "rules_kotlin", version = "2.2.1")

0 commit comments

Comments
 (0)