forked from cylc/cylc-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
protobuf: automate derived file generation
* Use the bufbuild/buf tool to: * Lint the protobuf schema. * Check for breaking changes. * Configure the generation of derived Python files. * Adds a GitHub action which automates the checking and generation of derived files and commits the results back on pull request branches.
- Loading branch information
1 parent
c43bf80
commit 1e8b633
Showing
19 changed files
with
641 additions
and
128 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
exclude_paths: | ||
- 'etc/**' | ||
- 'tests/**' | ||
- 'cylc/flow/**_pb2.py' | ||
- 'cylc/flow/network/protobuf/**_pb2.py' |
This file contains 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 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 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,82 @@ | ||
name: protobuf | ||
|
||
on: | ||
pull_request: | ||
# NOTE: don't run this on "workflow_dispatch" or "schedule" as it will commit | ||
# directly to the branch | ||
|
||
jobs: | ||
protobuf: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
# we need all of the commits on the PR branch in order to be able to add new ones | ||
fetch-depth: 100 | ||
|
||
- name: Configure git | ||
uses: cylc/release-actions/configure-git@v1 | ||
|
||
- name: Install Protobuf | ||
uses: mamba-org/setup-micromamba@v1 | ||
with: | ||
environment-name: protobuf | ||
create-args: protobuf | ||
init-shell: bash | ||
|
||
- name: Install bufbuild/buf | ||
run: | | ||
# activate homebrew (NOTE: must use "shell: bash -el {0}" to use this) | ||
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" # activate homebrew | ||
# NOTE: bufbuild does exist on conda-forge but hasn't been updated for a while | ||
brew install bufbuild/buf/buf | ||
- name: Lint | ||
run: | | ||
# lint .proto files | ||
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" # activate homebrew | ||
cd cylc/flow/network/protobuf | ||
buf lint | ||
- name: Compatibility | ||
shell: bash -el {0} | ||
run: | | ||
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" # activate homebrew | ||
cd cylc/flow/network/protobuf | ||
# NOTE: "buf breaking" exits "100" for a missing file (i.e. new version not present on old branch) | ||
# --against 'https://github.com/cylc/cylc-flow.git#tag=${{ github.base_ref }},subdir=proto') \ | ||
buf breaking \ | ||
--against 'https://github.com/oliver-sanders/cylc-flow.git#tag=${{ github.base_ref }},subdir=cylc/flow/network/protobuf' \ | ||
|| ( \ | ||
ret=$?; \ | ||
if [[ $ret == 100 ]]; then exit 0; \ | ||
elif [[ $ret != 0 ]]; then echo '::error:: Breaking changes detected, create a new version of the protobuf schema if this is desired and increment the Cylc API number to match'; \ | ||
fi \ | ||
) | ||
- name: Build | ||
shell: bash -el {0} | ||
run: | | ||
# generate .py and .pyi files from the .proto files | ||
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" # activate homebrew | ||
micromamba activate protobuf | ||
cd cylc/flow/network/protobuf | ||
buf generate | ||
- name: Commit & Push | ||
run: | | ||
if [[ -z $(git diff --stat) ]]; then | ||
echo '::error:: No functional changes made to the protobuf schema' | ||
exit 0 | ||
else | ||
echo '::info:: pushing update commit' | ||
git add -u | ||
git commit -m 'protobuf: updating generated files' | ||
git remote add pr https://github.com/${{ github.event.pull_request.head.repo.owner.login }}/cylc-flow | ||
git push pr HEAD:${{ github.head_ref }} | ||
exit 0 | ||
fi |
This file was deleted.
Oops, something went wrong.
This file contains 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 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,10 @@ | ||
# file containing protobuf configuration | ||
|
||
version: v2 | ||
|
||
plugins: | ||
- protoc_builtin: python | ||
out: . | ||
|
||
- protoc_builtin: pyi | ||
out: . |
This file contains 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,11 @@ | ||
# file containing protobuf configuration | ||
|
||
version: v2 | ||
|
||
lint: | ||
use: | ||
- DEFAULT | ||
|
||
breaking: | ||
use: | ||
- FILE |
Oops, something went wrong.