Skip to content

Commit ca172bc

Browse files
authored
feat: add automated proto generation workflow (#4931)
#4233 This PR Adds a GitHub Action to automatically regenerate Python and Go code when proto files are updated. - The workflow runs on merges to master affecting `gcp/api/v1/osv_service_v1.proto`, `osv/importfinding.proto`, or `vulnerability.proto` in osv-schema submodule. - The workflow also sets up the environments needed for proto generation including Python (Poetrty) and Go, protoc and necessary plugins. - As an outcome, the workflow makes a pull request with the regenerated code for review.
1 parent d8ab8f8 commit ca172bc

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Generate Protos
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
paths:
7+
- 'gcp/api/v1/osv_service_v1.proto'
8+
- 'osv/importfinding.proto'
9+
- 'osv/osv-schema/proto/vulnerability.proto'
10+
workflow_dispatch:
11+
12+
concurrency:
13+
# Pushing new changes to a branch will cancel any in-progress CI runs
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
# Restrict jobs in this workflow to have no permissions by default; permissions
18+
# should be granted per job as needed using a dedicated `permissions` block
19+
permissions: {}
20+
21+
jobs:
22+
generate:
23+
permissions:
24+
contents: write # to fetch and commit code
25+
actions: write # to manually dispatch checks on the pull request
26+
pull-requests: write # Create pull requests
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Check out code
30+
uses: actions/checkout@v4
31+
with:
32+
submodules: recursive
33+
persist-credentials: false
34+
35+
- name: Set up Python
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: '3.13'
39+
40+
- name: Install poetry
41+
run: pip install poetry==2.2.1
42+
43+
- name: Set up poetry
44+
run: |
45+
poetry install
46+
cd gcp/api && poetry install
47+
48+
- name: Set up Go
49+
uses: actions/setup-go@v5
50+
with:
51+
go-version: '1.26.0'
52+
53+
- name: Install protoc
54+
run: |
55+
sudo apt-get update
56+
sudo apt-get install -y protobuf-compiler
57+
58+
- name: Install Go proto plugins
59+
run: |
60+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.11
61+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.6.1
62+
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
63+
64+
- name: Generate protos
65+
run: make build-protos
66+
67+
- name: Create Pull Request
68+
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
69+
with:
70+
token: ${{ secrets.PR_TOKEN_BOT }}
71+
title: "chore: regenerate protos"
72+
body: >
73+
The proto files have been updated. This PR contains the regenerated code.
74+
75+
Please review and merge!
76+
branch: "bot/regenerate-protos"
77+
author: "osv-robot <osv-robot@google.com>"
78+
commit-message: "chore: regenerate protos"

0 commit comments

Comments
 (0)