-
Notifications
You must be signed in to change notification settings - Fork 832
ci: automate protobuf source generation for Renovate updates #1920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zeitlinger
wants to merge
4
commits into
main
Choose a base branch
from
automate-protobuf-generation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c502a66
ci: automate protobuf source generation for Renovate updates
zeitlinger 68a0d20
ci: clarify GITHUB_TOKEN limitation and close/reopen workaround
zeitlinger 87f97d4
ci: fix lint issues in generate-protobuf workflow
zeitlinger b1b5559
ci: remove mise.toml from generate workflow commit scope
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| name: Generate Protobuf | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "renovate/protobuf" | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| generate: | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | ||
| with: | ||
| ref: ${{ github.ref }} | ||
| # zizmor: ignore[artipacked] -- needs credentials to push | ||
| persist-credentials: true | ||
| - uses: jdx/mise-action@6d1e696aa24c1aa1bcc1adea0212707c71ab78a8 # v3.6.1 | ||
| with: | ||
| version: v2026.2.11 | ||
| sha256: 3e1baedb9284124b770d2d561a04a98c343d05967c83deb8b35c7c941f8d9c9a | ||
| - name: Cache local Maven repository | ||
| uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 | ||
| with: | ||
| path: ~/.m2/repository | ||
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-maven- | ||
| - name: Verify both protobuf deps are updated | ||
| run: | | ||
| git fetch origin main | ||
| DIFF_POM=$(git diff origin/main -- pom.xml) | ||
| DIFF_MISE=$(git diff origin/main -- mise.toml) | ||
| if ! echo "$DIFF_POM" | grep -q 'protobuf-java.version'; then | ||
| echo "::error::protobuf-java not updated in pom.xml" | ||
| exit 1 | ||
| fi | ||
| if ! echo "$DIFF_MISE" | grep -q 'protoc'; then | ||
| echo "::error::protoc not updated in mise.toml" | ||
| exit 1 | ||
| fi | ||
| - name: Generate protobuf sources | ||
| run: mise run generate | ||
| - name: Commit and push generated sources | ||
| run: | | ||
| git diff --quiet && exit 0 | ||
| UNEXPECTED=$(git diff --name-only | grep -v '\.java$' || true) | ||
| if [[ -n "$UNEXPECTED" ]]; then | ||
| echo "::error::Unexpected files changed:" | ||
| echo "$UNEXPECTED" | ||
| exit 1 | ||
| fi | ||
| # Note: GITHUB_TOKEN pushes don't trigger CI re-runs. | ||
| # Close and reopen the PR to trigger CI after this commit. | ||
| # TODO: switch to PROMBOT_GITHUB_TOKEN once it's added to this repo. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git add '*.java' | ||
| git commit -m "chore: regenerate protobuf sources" | ||
| git push | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that a push for this from renovate could still theoretically contain untrusted code if the dependency being updated was compromised and a malicious version published.
If the update contained malicious code that tried to steal
GITHUB_TOKEN(or whatever secret is used), it would able to perform arbitrary write operations on the repository, or whatever permissions that token had.It's risky performing automated writes to the repository with elevated permissions in this context.
It's not something I've tried to do myself, but a safer approach could be to have this job only generate a Git patch for the changes as a build artifact, and then have another job/workflow take that artifact and apply it after applying some sanity checks (e.g. the diff only updates the expected files). Then any compromised code isn't able to actually execute with access to the secrets but the protobuf files can still be regenerated.