Skip to content

Commit 6419fb6

Browse files
Add proto generation automation script and workflow integration
Co-authored-by: brendandburns <[email protected]>
1 parent b956cfd commit 6419fb6

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

.github/workflows/generate.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,22 @@ jobs:
7373
7474
USE_SINGLE_PARAMETER=true bash java.sh ../../kubernetes/ settings
7575
popd
76-
rm -rf gen
7776
git config user.email "[email protected]"
7877
git config user.name "Kubernetes Publisher"
7978
git checkout -b "$BRANCH"
8079
git add .
8180
git commit -s -m 'Automated openapi generation from ${{ github.event.inputs.kubernetesBranch }}'
81+
- name: Generate Proto
82+
run: |
83+
pushd gen/proto
84+
# Download proto dependencies for the specified Kubernetes branch
85+
bash dependencies.sh "${{ github.event.inputs.kubernetesBranch }}"
86+
# Generate Java proto classes
87+
bash generate.sh java ../../proto/src/main/java/
88+
popd
89+
rm -rf gen
90+
git add proto/
91+
git commit -s -m 'Automated proto generation from ${{ github.event.inputs.kubernetesBranch }}'
8292
- name: Apply Manual Diffs
8393
if: ${{ github.event.inputs.skip_patches != 'true' }}
8494
run: |

proto/README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
# Generating proto files
22

3+
## Automated Generation
4+
5+
Protocol buffer files are automatically generated as part of the regular code generation workflow when a new Kubernetes release is published. This happens through the GitHub Actions workflow defined in `.github/workflows/generate.yml`.
6+
7+
To trigger proto generation manually along with OpenAPI generation:
8+
9+
1. Go to the [Generate workflow](https://github.com/kubernetes-client/java/actions/workflows/generate.yml) in GitHub Actions
10+
2. Click "Run workflow"
11+
3. Specify the Kubernetes branch (e.g., "release-1.30" or "master")
12+
4. The workflow will automatically:
13+
- Generate OpenAPI client code
14+
- Generate protocol buffer classes
15+
- Apply any necessary patches
16+
- Generate fluent API
17+
- Create a pull request with all changes
18+
19+
## Manual Generation
20+
21+
For local development or testing, you can generate proto files manually using the provided script:
22+
23+
```sh
24+
cd /path/to/kubernetes-client-java
25+
KUBERNETES_BRANCH=master bash scripts/update-proto.sh
26+
```
27+
28+
You can specify a different Kubernetes branch/tag:
29+
30+
```sh
31+
KUBERNETES_BRANCH=release-1.30 bash scripts/update-proto.sh
32+
```
33+
34+
## Using the kubernetes-client/gen Repository Directly
35+
36+
Alternatively, you can use the kubernetes-client/gen repository directly:
37+
338
```sh
439
git clone https://github.com/kubernetes-client/gen
540
cd gen/proto
6-
./generate.sh java ${PATH_TO_JAVA_CLIENT_ROOT}/java/proto/src/main/java/
41+
bash dependencies.sh master # or specify a different branch
42+
bash generate.sh java ${PATH_TO_JAVA_CLIENT_ROOT}/proto/src/main/java/
743
`````````````````````````````````

scripts/update-proto.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Script to generate protocol buffer classes from upstream Kubernetes proto files.
18+
# Generates proto classes at proto/src/main/java/
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
25+
PROTO_ROOT="${SCRIPT_ROOT}/../proto"
26+
27+
pushd "${SCRIPT_ROOT}" > /dev/null
28+
SCRIPT_ROOT=$(pwd)
29+
popd > /dev/null
30+
31+
pushd "${PROTO_ROOT}" > /dev/null
32+
PROTO_ROOT=$(pwd)
33+
popd > /dev/null
34+
35+
TEMP_FOLDER=$(mktemp -d)
36+
trap "rm -rf ${TEMP_FOLDER}" EXIT SIGINT
37+
38+
if [[ -z ${GEN_ROOT:-} ]]; then
39+
GEN_ROOT="${TEMP_FOLDER}/gen"
40+
echo ">>> Cloning gen repo"
41+
git clone --recursive https://github.com/kubernetes-client/gen.git "${GEN_ROOT}"
42+
else
43+
echo ">>> Reusing gen repo at ${GEN_ROOT}"
44+
fi
45+
46+
# Allow specifying Kubernetes branch/tag, default to master
47+
KUBERNETES_BRANCH="${KUBERNETES_BRANCH:-master}"
48+
49+
echo ">>> Generating proto files from Kubernetes ${KUBERNETES_BRANCH}"
50+
pushd "${GEN_ROOT}/proto" > /dev/null
51+
# Download proto dependencies for the specified Kubernetes branch
52+
bash dependencies.sh "${KUBERNETES_BRANCH}"
53+
# Generate Java proto classes
54+
bash generate.sh java "${PROTO_ROOT}/src/main/java/"
55+
popd > /dev/null
56+
57+
echo ">>> Done."

0 commit comments

Comments
 (0)