Skip to content

Commit c502a66

Browse files
committed
ci: automate protobuf source generation for Renovate updates
Group protobuf-java and protoc into a single Renovate PR and add a workflow that regenerates protobuf sources when both deps are updated. Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 35735f9 commit c502a66

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

.github/renovate.json5

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
description: "Ignore internal project modules",
3333
matchPackageNames: ["/^io\\.prometheus:(examples|example-.+|integration-tests|it-.+)$/"],
3434
},
35+
{
36+
description: "Group protobuf-java and protoc together so generated code can be updated in one PR",
37+
matchDepNames: ["com.google.protobuf:protobuf-java", "protoc"],
38+
groupName: "protobuf",
39+
separateMajorMinor: false,
40+
},
3541
],
3642
customManagers: [],
3743
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
name: Generate Protobuf
3+
4+
on:
5+
push:
6+
branches:
7+
- "renovate/protobuf"
8+
9+
permissions: {}
10+
11+
jobs:
12+
generate:
13+
runs-on: ubuntu-24.04
14+
permissions:
15+
contents: write
16+
steps:
17+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
18+
with:
19+
ref: ${{ github.ref }}
20+
- uses: jdx/mise-action@6d1e696aa24c1aa1bcc1adea0212707c71ab78a8 # v3.6.1
21+
with:
22+
version: v2026.2.11
23+
sha256: 3e1baedb9284124b770d2d561a04a98c343d05967c83deb8b35c7c941f8d9c9a
24+
- name: Cache local Maven repository
25+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
26+
with:
27+
path: ~/.m2/repository
28+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
29+
restore-keys: |
30+
${{ runner.os }}-maven-
31+
- name: Verify both protobuf deps are updated
32+
run: |
33+
git fetch origin main
34+
git diff origin/main -- pom.xml | grep -q 'protobuf-java.version' || { echo "::error::protobuf-java not updated in pom.xml — waiting for Renovate"; exit 1; }
35+
git diff origin/main -- mise.toml | grep -q 'protoc' || { echo "::error::protoc not updated in mise.toml — waiting for Renovate"; exit 1; }
36+
- name: Generate protobuf sources
37+
run: mise run generate
38+
- name: Commit and push generated sources
39+
run: |
40+
git diff --quiet && exit 0
41+
UNEXPECTED=$(git diff --name-only | grep -v '\.java$' | grep -v '^mise\.toml$' || true)
42+
if [[ -n "$UNEXPECTED" ]]; then
43+
echo "::error::Unexpected files changed:"
44+
echo "$UNEXPECTED"
45+
exit 1
46+
fi
47+
# TODO: verify whether GITHUB_TOKEN can push to Renovate branches,
48+
# or if we need a PAT / GitHub App token (ask Martin)
49+
git config user.name "github-actions[bot]"
50+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
51+
git add '*.java' mise.toml
52+
git commit -m "chore: regenerate protobuf sources"
53+
git push

mise.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ description = "bare compile, ignoring formatting and linters"
3131
run = "./mvnw install -DskipTests -Dspotless.check.skip=true -Dcoverage.skip=true -Dcheckstyle.skip=true -Dwarnings=-nowarn"
3232

3333
[tasks.generate]
34-
description = "bare compile, ignoring formatting and linters"
35-
run = [
36-
"mise use --pin protoc@latest",
37-
"./mvnw clean install -DskipTests -Dspotless.check.skip=true -Dcoverage.skip=true -Dcheckstyle.skip=true -Dwarnings=-nowarn"
38-
]
34+
description = "regenerate protobuf sources"
35+
run = "./mvnw clean install -DskipTests -Dspotless.check.skip=true -Dcoverage.skip=true -Dcheckstyle.skip=true -Dwarnings=-nowarn"
3936
env.PROTO_GENERATION = "true"
4037

4138
[tasks.test]

0 commit comments

Comments
 (0)