NOISSUE - Add group API tests (#243) #1
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
# Copyright (c) Abstract Machines | |
# SPDX-License-Identifier: Apache-2.0 | |
name: Check the consistency of generated files | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
check-generated-files: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.21.x | |
cache-dependency-path: "go.sum" | |
- name: Check for changes in specific paths | |
uses: dorny/paths-filter@v2 | |
id: changes | |
with: | |
base: main | |
filters: | | |
proto: | |
- ".github/workflows/check-generated-files.yml" | |
- "auth.proto" | |
- "auth/*.pb.go" | |
- "pkg/messaging/message.proto" | |
- "pkg/messaging/*.pb.go" | |
mocks: | |
- ".github/workflows/check-generated-files.yml" | |
- "pkg/sdk/go/sdk.go" | |
- "users/postgres/clients.go" | |
- "users/clients.go" | |
- "pkg/clients/clients.go" | |
- "pkg/messaging/pubsub.go" | |
- "things/postgres/clients.go" | |
- "things/things.go" | |
- "auth/domains.go" | |
- "auth/keys.go" | |
- "auth/policies.go" | |
- "pkg/events/events.go" | |
- "provision/service.go" | |
- "pkg/groups/groups.go" | |
- name: Set up protoc | |
if: steps.changes.outputs.proto == 'true' | |
run: | | |
PROTOC_VERSION=25.1 | |
PROTOC_GEN_VERSION=v1.31.0 | |
PROTOC_GRPC_VERSION=v1.3.0 | |
# Download and install protoc | |
PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip | |
curl -0L -o $PROTOC_ZIP https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP | |
unzip -o $PROTOC_ZIP -d protoc3 | |
sudo mv protoc3/bin/* /usr/local/bin/ | |
sudo mv protoc3/include/* /usr/local/include/ | |
rm -rf $PROTOC_ZIP protoc3 | |
# Install protoc-gen-go and protoc-gen-go-grpc | |
go install google.golang.org/protobuf/cmd/protoc-gen-go@$PROTOC_GEN_VERSION | |
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$PROTOC_GRPC_VERSION | |
# Add protoc to the PATH | |
export PATH=$PATH:/usr/local/bin/protoc | |
- name: Check Protobuf is up to Date | |
if: steps.changes.outputs.proto == 'true' | |
run: | | |
for p in $(find . -name "*.pb.go"); do | |
mv $p $p.tmp | |
done | |
make proto | |
for p in $(find . -name "*.pb.go"); do | |
if ! cmp -s $p $p.tmp; then | |
echo "Error: Proto file and generated Go file $p are out of sync!" | |
echo "Please run 'make proto' with protoc version $PROTOC_VERSION, protoc-gen-go version $PROTOC_GEN_VERSION and protoc-gen-go-grpc version $PROTOC_GRPC_VERSION and commit the changes." | |
exit 1 | |
fi | |
done | |
- name: Check Mocks are up to Date | |
if: steps.changes.outputs.mocks == 'true' | |
run: | | |
MOCKERY_VERSION=v2.38.0 | |
go install github.com/vektra/mockery/v2@$MOCKERY_VERSION | |
mv ./pkg/sdk/mocks/sdk.go ./pkg/sdk/mocks/sdk.go.tmp | |
mv ./users/mocks/repository.go ./users/mocks/repository.go.tmp | |
mv ./users/mocks/service.go ./users/mocks/service.go.tmp | |
mv ./pkg/messaging/mocks/pubsub.go ./pkg/messaging/mocks/pubsub.go.tmp | |
mv ./things/mocks/repository.go ./things/mocks/repository.go.tmp | |
mv ./things/mocks/service.go ./things/mocks/service.go.tmp | |
mv ./things/mocks/cache.go ./things/mocks/cache.go.tmp | |
mv ./auth/mocks/agent.go ./auth/mocks/agent.go.tmp | |
mv ./auth/mocks/authz.go ./auth/mocks/authz.go.tmp | |
mv ./auth/mocks/domains.go ./auth/mocks/domains.go.tmp | |
mv ./auth/mocks/keys.go ./auth/mocks/keys.go.tmp | |
mv ./pkg/events/mocks/publisher.go ./pkg/events/mocks/publisher.go.tmp | |
mv ./pkg/events/mocks/subscriber.go ./pkg/events/mocks/subscriber.go.tmp | |
mv ./provision/mocks/service.go ./provision/mocks/service.go.tmp | |
mv ./pkg/groups/mocks/repository.go ./pkg/groups/mocks/repository.go.tmp | |
mv ./pkg/groups/mocks/service.go ./pkg/groups/mocks/service.go.tmp | |
make mocks | |
check_mock_changes() { | |
local file_path=$1 | |
local tmp_file_path=$1.tmp | |
local entity_name=$2 | |
if ! cmp -s "$file_path" "$tmp_file_path"; then | |
echo "Error: Generated mocks for $entity_name are out of sync!" | |
echo "Please run 'make mocks' with mockery version $MOCKERY_VERSION and commit the changes." | |
exit 1 | |
fi | |
} | |
check_mock_changes ./pkg/sdk/mocks/sdk.go "SDK ./pkg/sdk/mocks/sdk.go" | |
check_mock_changes ./users/mocks/repository.go "Users Repository ./users/mocks/repository.go" | |
check_mock_changes ./users/mocks/service.go "Users Service ./users/mocks/service.go" | |
check_mock_changes ./pkg/messaging/mocks/pubsub.go "PubSub ./pkg/messaging/mocks/pubsub.go" | |
check_mock_changes ./things/mocks/repository.go "Things Repository ./things/mocks/repository.go" | |
check_mock_changes ./things/mocks/service.go "Things Service ./things/mocks/service.go" | |
check_mock_changes ./things/mocks/cache.go "Things Cache ./things/mocks/cache.go" | |
check_mock_changes ./auth/mocks/agent.go "Auth Agent ./auth/mocks/agent.go" | |
check_mock_changes ./auth/mocks/authz.go "Auth Authz ./auth/mocks/authz.go" | |
check_mock_changes ./auth/mocks/domains.go "Auth Domains ./auth/mocks/domains.go" | |
check_mock_changes ./auth/mocks/keys.go "Auth Keys ./auth/mocks/keys.go" | |
check_mock_changes ./pkg/events/mocks/publisher.go "ES Publisher ./pkg/events/mocks/publisher.go" | |
check_mock_changes ./pkg/events/mocks/subscriber.go "EE Subscriber ./pkg/events/mocks/subscriber.go" | |
check_mock_changes ./provision/mocks/service.go "Provision Service ./provision/mocks/service.go" | |
check_mock_changes ./pkg/groups/mocks/repository.go "Groups Repository ./pkg/groups/mocks/repository.go" | |
check_mock_changes ./pkg/groups/mocks/service.go "Groups Service ./pkg/groups/mocks/service.go" |