-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charith Ellawala <[email protected]>
- Loading branch information
Showing
8 changed files
with
1,090 additions
and
22 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ on: | |
pull_request: | ||
branches: | ||
- main | ||
- 'v*' | ||
- "v*" | ||
jobs: | ||
test: | ||
name: Test | ||
|
@@ -19,6 +19,9 @@ jobs: | |
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install just | ||
uses: extractions/setup-just@v2 | ||
|
||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
|
@@ -30,7 +33,7 @@ jobs: | |
generate-${{ runner.os }}-go- | ||
- name: Test | ||
run: make test | ||
run: just test | ||
|
||
golangci: | ||
name: Lint | ||
|
@@ -48,11 +51,14 @@ jobs: | |
uses: golangci/[email protected] | ||
with: | ||
version: latest | ||
args: '--config=.golangci.yaml --fix' | ||
args: "--config=.golangci.yaml --fix" | ||
|
||
- name: Install just | ||
uses: extractions/setup-just@v2 | ||
|
||
- name: Check repo status | ||
run: |- | ||
make generate | ||
just generate | ||
REPO_STATUS="$(git status --porcelain)" | ||
if [[ ! -z $REPO_STATUS ]]; then | ||
echo "::error::Uncommitted changes detected" | ||
|
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,90 @@ | ||
set dotenv-load := true | ||
|
||
dev_dir := join(justfile_directory(), "hack", "dev") | ||
genmocks_dir := join(justfile_directory(), "test", "mocks") | ||
genpb_dir := join(justfile_directory(), "genpb") | ||
tools_mod_dir := join(justfile_directory(), "tools") | ||
|
||
export TOOLS_BIN_DIR := join(env_var_or_default("XDG_CACHE_HOME", join(env_var("HOME"), ".cache")), "cerbos-cloud-api/bin") | ||
|
||
default: | ||
@ just --list | ||
|
||
compile: | ||
@ go build ./... && go test -tags=tests,integration -run=ignore ./... > /dev/null | ||
|
||
cover PKG='./...' TEST='.*': _cover | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
COVERFILE="$(mktemp -t cloud-api-XXXXX)" | ||
trap 'rm -rf "$COVERFILE"' EXIT | ||
go test -tags=tests,integration -coverprofile="$COVERFILE" -count=1 -run='{{ TEST }}' '{{ PKG }}' | ||
"${TOOLS_BIN_DIR}/cover" -p "$COVERFILE" | ||
|
||
generate: generate-proto-code generate-mocks | ||
|
||
generate-mocks QUIET='--quiet': _mockery | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
cd {{ justfile_directory() }} | ||
rm -rf {{ genmocks_dir }} | ||
"${TOOLS_BIN_DIR}/mockery" {{ QUIET }} | ||
generate-proto-code: _buf | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
cd {{ justfile_directory() }} | ||
"${TOOLS_BIN_DIR}/buf" format -w | ||
rm -rf {{ genpb_dir }} | ||
( | ||
cd {{ tools_mod_dir }} | ||
"${TOOLS_BIN_DIR}/buf" generate --template=buf.gen.yaml --output=.. | ||
) | ||
lint: _golangcilint _buf | ||
@ "${TOOLS_BIN_DIR}/golangci-lint" run --config=.golangci.yaml --fix | ||
@ "${TOOLS_BIN_DIR}/buf" lint | ||
@ "${TOOLS_BIN_DIR}/buf" format --diff --exit-code | ||
|
||
pre-commit: generate lint tests | ||
|
||
test PKG='./...' TEST='.*': | ||
@ go test -v -tags=tests,integration -failfast -cover -count=1 -run='{{ TEST }}' '{{ PKG }}' | ||
|
||
tests PKG='./...' TEST='.*': _gotestsum | ||
@ "${TOOLS_BIN_DIR}/gotestsum" --format=dots-v2 --format-hide-empty-pkg -- -tags=tests,integration -failfast -count=1 -run='{{ TEST }}' '{{ PKG }}' | ||
|
||
# Executables | ||
|
||
_buf: (_install "buf" "github.com/bufbuild/buf" "cmd/buf") | ||
|
||
_cover: (_install "cover" "nikand.dev/go/cover@master" ) | ||
|
||
_golangcilint: (_install "golangci-lint" "github.com/golangci/golangci-lint" "cmd/golangci-lint") | ||
|
||
_gotestsum: (_install "gotestsum" "gotest.tools/gotestsum") | ||
|
||
_mockery: (_install "mockery" "github.com/vektra/mockery/v2") | ||
|
||
_install EXECUTABLE MODULE CMD_PKG="": | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
cd {{ tools_mod_dir }} | ||
TMP_VERSION=$(GOWORK=off go list -m -f "{{{{.Version}}" "{{ MODULE }}") | ||
VERSION="${TMP_VERSION#v}" | ||
BINARY="${TOOLS_BIN_DIR}/{{ EXECUTABLE }}" | ||
SYMLINK="${BINARY}-${VERSION}" | ||
if [[ ! -e "$SYMLINK" ]]; then | ||
echo "Installing $SYMLINK" 1>&2 | ||
mkdir -p "$TOOLS_BIN_DIR" | ||
find "${TOOLS_BIN_DIR}" -lname "$BINARY" -delete | ||
if [[ "{{ EXECUTABLE }}" == "golangci-lint" ]]; then | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$TOOLS_BIN_DIR" | ||
else | ||
export CGO_ENABLED={{ if EXECUTABLE =~ "(^sql|^tbls)" { "1" } else { "0" } }} | ||
GOWORK=off GOBIN="$TOOLS_BIN_DIR" go install {{ if CMD_PKG != "" { MODULE + "/" + CMD_PKG } else { MODULE } }} | ||
fi | ||
ln -s "$BINARY" "$SYMLINK" | ||
fi | ||
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,6 +1,18 @@ | ||
boilerplate-file: hack/copyright_header.txt | ||
keeptree: True | ||
output: test/mocks | ||
packageprefix: mock | ||
dir: test/mocks/{{trimPrefix .PackagePath "github.com/cerbos/cloud-api/"}} | ||
filename: "{{.InterfaceName}}.go" | ||
mockname: "{{.InterfaceName}}" | ||
outpkg: "mock{{.PackageName}}" | ||
with-expecter: True | ||
packages: | ||
github.com/cerbos/cloud-api/genpb/cerbos/cloud/apikey/v1/apikeyv1connect: | ||
interfaces: | ||
ApiKeyServiceHandler: | ||
|
||
github.com/cerbos/cloud-api/genpb/cerbos/cloud/bundle/v1/bundlev1connect: | ||
interfaces: | ||
CerbosBundleServiceHandler: | ||
|
||
github.com/cerbos/cloud-api/genpb/cerbos/cloud/logs/v1/logsv1connect: | ||
interfaces: | ||
CerbosLogsServiceHandler: |
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,30 @@ | ||
version: v2 | ||
inputs: | ||
- directory: ../protos | ||
plugins: | ||
- local: | ||
- go | ||
- run | ||
- google.golang.org/protobuf/cmd/protoc-gen-go | ||
out: genpb | ||
opt: paths=source_relative | ||
- local: | ||
- go | ||
- run | ||
- connectrpc.com/connect/cmd/protoc-gen-connect-go | ||
out: genpb | ||
opt: paths=source_relative | ||
- local: | ||
- go | ||
- run | ||
- github.com/cerbos/protoc-gen-go-hashpb | ||
out: genpb | ||
opt: paths=source_relative | ||
- local: | ||
- go | ||
- run | ||
- github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto | ||
out: genpb | ||
opt: | ||
- paths=source_relative | ||
- features=marshal+unmarshal+size |
Oops, something went wrong.