Skip to content

Commit

Permalink
added back grpc codegen and created a workflow for ensuring autogener…
Browse files Browse the repository at this point in the history
…ated code is as expected
  • Loading branch information
MadsRC committed May 15, 2024
1 parent a481321 commit 7427129
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 63 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/codegen_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
# Trigger analysis when pushing in master or pull requests, and when creating
# a pull request.
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

# Declare default permissions as read only.
permissions: read-all

name: Code Generation Check
jobs:
check-codegen:
strategy:
matrix:
target: [ mocks, protobuf ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- uses: jdx/mise-action@0c39a522dfbced3ed83924152c45804a71ce216f # v2.0.4
with:
experimental: true
- run: mise run clean
- run: mise run generate:${{ matrix.target }} --check
2 changes: 1 addition & 1 deletion .mise/tasks/build/dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
# mise outputs=["dist/sophrosyne", "dist/sophrosyne_linux_amd64", "dist/sophrosyne_linux_arm64]
# mise outputs=["dist/sophrosyne", "dist/sophrosyne_linux_amd64", "dist/sophrosyne_linux_arm64"]

goos=""
goarch=""
Expand Down
2 changes: 2 additions & 0 deletions .mise/tasks/clean
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

rm -rf build
rm -rf dist
rm -rf internal/mocks
find . -name '*.pb.go' -delete
2 changes: 0 additions & 2 deletions .mise/tasks/dev/format
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/sh
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
# mise outputs=["build/report.xml"]

check=1

Expand Down
36 changes: 36 additions & 0 deletions .mise/tasks/generate/mocks
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
# mise sources=[".mockery.yaml", "go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
# mise outputs=["build/.mocksentinel"]

set -e

mkdir -p build

check=1

handle_argument() {
echo "Argument '$1' not supported" >&2; exit 1
}

while test "$#" -gt 0; do
case "$1" in
--check) check=0; shift 1;;

-*) echo "unknown option: $1" >&2; exit 1;;
*) handle_argument "$1"; shift 1;;
esac
done

mockery
touch build/.mocksentinel

if test "$check" = 0; then
echo "\nChecking mocks..."
changes=$(git status --porcelain internal/mocks)
if test -n "$changes"; then
echo "Mocks changed:"
git --no-pager diff internal/mocks
exit 1
fi
echo "Mocks have no changes according to git!"
fi
45 changes: 45 additions & 0 deletions .mise/tasks/generate/protobuf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
# mise sources=["proto/**/*.proto"]
# mise outputs=["build/.protobufsentinel"]

set -e

mkdir -p build

check=1

handle_argument() {
echo "Argument '$1' not supported" >&2; exit 1
}

while test "$#" -gt 0; do
case "$1" in
--check) check=0; shift 1;;

-*) echo "unknown option: $1" >&2; exit 1;;
*) handle_argument "$1"; shift 1;;
esac
done

mkdir -p internal/grpc/checks

protoc \
--proto_path=proto \
--go_out=internal/grpc \
--go_opt=paths=source_relative \
--go-grpc_out=internal/grpc \
--go-grpc_opt=paths=source_relative \
proto/checks/checks.proto

touch build/.protobufsentinel

if test "$check" = 0; then
echo "\nChecking GRPC files..."
changes=$(git status --porcelain internal/grpc)
if test -n "$changes"; then
echo "GRPC files changed:"
git --no-pager diff internal/grpc
exit 1
fi
echo "GRPC files have no changes according to git!"
fi
111 changes: 55 additions & 56 deletions internal/grpc/checks/checks.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions internal/grpc/checks/checks_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/checks/checks.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package checks.v1;

option go_package = "github.com/madsrc/sophrosyne/grpc/checks";
option go_package = "github.com/madsrc/sophrosyne/internal/grpc/checks";

message CheckRequest {
oneof check {
Expand Down

0 comments on commit 7427129

Please sign in to comment.