Skip to content

Instantly share code, notes, and snippets.

@nekomeowww
Last active August 15, 2025 09:18
Show Gist options
  • Save nekomeowww/a4a72922356232c908e9eb168c28d3ee to your computer and use it in GitHub Desktop.
Save nekomeowww/a4a72922356232c908e9eb168c28d3ee to your computer and use it in GitHub Desktop.
Example of distributing Protobuf files from centralized repository to sub packages like Golang, Python, Rust, Node.js while maintain their each languages / frameworks workflow and structure of projects. Each sub-repository can have their own publishing mechanism like go-releaser, or bumpp for Node.js.
name: Protobuf Codegen
concurrency: protobuf-gen
on:
workflow_dispatch:
jobs:
protobuf_gen_golang:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
path: clones/${org}/${protobuf-repo}-go
- name: Checkout
uses: actions/checkout@v5
with:
repository: ${org}/${protobuf-repo}
token: ${{ secrets.ACCESS_TOKEN }}
path: clones/${org}/${protobuf-repo}
- name: Get HEAD SHA of ${org}/${protobuf-repo}
id: details
run: |
cd clones/neveco/neve-protobuf
echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Setup buf
uses: bufbuild/[email protected]
- name: Buf build
run: |
cd clones/${org}/${protobuf-repo}
buf generate
- name: Copy build artifacts
run: |
cd clones/${org}
cp -R ${protobuf-repo}/gen/go/proto ${protobuf-repo}-go
ls -la ${protobuf-repo}-go
- name: Sync go.mod
run: |
cd clones/${org}/${protobuf-repo}-go
go mod tidy
- name: Sync repo
run: |
cd clones/${org}/${protobuf-repo}-go
ls -la
bash -c 'if [ $(git status --porcelain | wc -l) -eq 0 ]; then
echo "No worktree change, skipping..."
else
echo "Committing..."
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore(generated): protobuf sync (from ${{ steps.details.outputs.sha }})"
echo "Pushing..."
git push
fi'
name: Protobuf Dispatch Codegen
on:
push:
branches:
- main
workflow_dispatch:
jobs:
dispatch:
strategy:
matrix:
repos: ['${org}/${protobuf-repo}-go']
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Setup buf
uses: bufbuild/[email protected]
- name: Dispatch all Protobuf Codegen workflows
uses: benc-uk/workflow-dispatch@v1
with:
# Dispatch to matrix.repo contained protobuf-codegen.yaml workflow
workflow: protobuf-codegen.yaml
token: ${{ secrets.ACCESS_TOKEN }}
# Dispatch ${org}/${{ matrix.repos }},比如 example-org/example-protobuf-go
repo: neveco/${{ matrix.repos }}
# Git ref of dispatching event, default to main
ref: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment