Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate to just #185

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
branches:
- main
- 'v*'
- "v*"
jobs:
test:
name: Test
Expand All @@ -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: |
Expand All @@ -30,7 +33,7 @@ jobs:
generate-${{ runner.os }}-go-

- name: Test
run: make test
run: just test

golangci:
name: Lint
Expand All @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
---
run:
timeout: 300s
skip-dirs:
- "^genpb/"
- "^hack/"
- "^protos/"
- "^tools/"
build-tags:
- tests

Expand Down Expand Up @@ -41,7 +36,6 @@ linters-settings:

nolintlint:
allow-unused: false
allow-leading-space: false
require-specific: true

tagliatelle:
Expand Down Expand Up @@ -103,6 +97,12 @@ linters:
issues:
max-same-issues: 30

exclude-dirs:
- "^genpb/"
- "^hack/"
- "^protos/"
- "^tools/"

exclude-rules:
- path: _test\.go
linters:
Expand Down
90 changes: 90 additions & 0 deletions .justfile
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

18 changes: 15 additions & 3 deletions .mockery.yaml
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:
55 changes: 0 additions & 55 deletions Makefile

This file was deleted.

30 changes: 30 additions & 0 deletions tools/buf.gen.yaml
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
Loading
Loading