Skip to content

Commit

Permalink
add magefile to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ecordell committed Feb 6, 2023
1 parent 71c2072 commit 98433af
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 72 deletions.
60 changes: 39 additions & 21 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on: # yamllint disable-line rule:truthy
pull_request:
branches:
- "*"
env:
GO_VERSION: "~1.19"
jobs:
paths-filter:
runs-on: "ubuntu-latest"
Expand Down Expand Up @@ -35,9 +37,9 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-go@v3"
- uses: "authzed/actions/setup-go@main"
with:
go-version: "~1.19"
go-version: "${{ env.GO_VERSION }}"
- uses: "authzed/actions/go-build@main"

image-build:
Expand All @@ -48,45 +50,61 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-go@v3"
- uses: "authzed/actions/setup-go@main"
with:
go-version: "~1.19"
go-version: "${{ env.GO_VERSION }}"
- uses: "authzed/actions/docker-build@main"
with:
push: false
tags: "authzed/spicedb-operator:ci"
buildx: false
qemu: false

test:
unit:
needs: "paths-filter"
if: |
needs.paths-filter.outputs.codechange == 'true'
name: "Test"
name: "Unit Tests"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
with:
submodules: true
- uses: "actions/setup-go@v2"
- uses: "authzed/actions/setup-go@main"
with:
go-version: "^1.19"
go-version: "${{ env.GO_VERSION }}"
- uses: "docker/setup-qemu-action@v2"
- uses: "docker/setup-buildx-action@v2"
- name: "Run Unit Tests"
uses: "magefile/mage-action@v2"
with:
version: "latest"
args: "test:unit"

e2e:
needs: "paths-filter"
if: |
needs.paths-filter.outputs.codechange == 'true'
name: "E2E Tests"
runs-on: "ubuntu-latest-8-cores"
steps:
- uses: "actions/checkout@v3"
with:
repository: "authzed/spicedb"
path: "spicedb"
submodules: true
- uses: "authzed/actions/setup-go@main"
with:
go-version: "${{ env.GO_VERSION }}"
- uses: "docker/setup-qemu-action@v2"
- uses: "docker/setup-buildx-action@v2"
- name: "Tag Test SpiceDB Image"
uses: "docker/build-push-action@v3"
- name: "Run E2E Tests"
uses: "magefile/mage-action@v2"
with:
version: "latest"
args: "test:e2e"
- uses: "actions/upload-artifact@v2"
if: "always()"
# this upload step is really flaky, don't fail the job if it fails
continue-on-error: true
with:
context: "spicedb"
file: "spicedb/Dockerfile"
tags: "spicedb:dev,spicedb:updated"
outputs: "type=docker,dest=/tmp/image.tar"
- name: "Run Ginkgo Tests"
run: "go run github.com/onsi/ginkgo/v2/ginkgo --skip-package ./spicedb --tags=e2e -r --procs=2 -v --randomize-all --randomize-suites --fail-on-pending --fail-fast --no-color --race --trace --json-report=report.json -- -v=4"
env:
PROVISION: "true"
ARCHIVES: "/tmp/image.tar"
name: "cluster-state"
path: "e2e/cluster-state"
16 changes: 13 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@ on: # yamllint disable-line rule:truthy
- "main"
pull_request:
branches: ["*"]
env:
GO_VERSION: "~1.19"
jobs:
go-lint:
name: "Lint Go"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-go@v3"
- uses: "authzed/actions/setup-go@main"
with:
go-version: "~1.19"
go-version: "${{ env.GO_VERSION }}"
- name: "Go Format"
# using this instead of the authzed/actions version because `.`
# properly ignores counterfeiter codegen
run: "go run mvdan.cc/gofumpt -w ."
- name: "Codegen"
uses: "magefile/mage-action@v2"
with:
version: "latest"
args: "generate"
- name: "Verify Gofumpt"
uses: "chainguard-dev/actions/nodiff@main"
with:
fixup-command: "gofumpt"
- uses: "authzed/actions/go-mod-tidy@main"
- uses: "authzed/actions/go-mod-tidy@main"
with:
working_directory: "./tools"
- uses: "authzed/actions/go-generate@main"
- uses: "authzed/actions/golangci-lint@main"

Expand All @@ -47,7 +57,7 @@ jobs:

codeql:
name: "Analyze with CodeQL"
runs-on: "ubuntu-latest"
runs-on: "ubuntu-latest-8-cores"
permissions:
actions: "read"
contents: "read"
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on: # yamllint disable-line rule:truthy
permissions:
contents: "write"
packages: "write"
env:
GO_VERSION: "~1.19"
jobs:
goreleaser:
runs-on: "ubuntu-latest"
Expand All @@ -16,9 +18,9 @@ jobs:
- uses: "actions/checkout@v3"
with:
fetch-depth: 0
- uses: "actions/setup-go@v3"
- uses: "authzed/actions/setup-go@main"
with:
go-version: "~1.19"
go-version: "${{ env.GO_VERSION }}"
- uses: "authzed/actions/docker-login@main"
with:
quayio_token: "${{ secrets.QUAYIO_PASSWORD }}"
Expand Down
19 changes: 7 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,23 @@ In order to build and test the project, the [latest stable version of Go] and kn
[latest stable version of Go]: https://golang.org/dl
[working Go environment]: https://golang.org/doc/code.html

Install ginkgo:
Install [mage](https://magefile.org/#installation):

```sh
go install github.com/onsi/ginkgo/v2/ginkgo@v2
# homebrew, see link for other options
brew install mage
```

Run against an existing cluster with images already loaded (current kubeconfig context)
Run e2e tests:

```sh
ginkgo --tags=e2e -r
mage test:e2e
```

Spin up a new `kind` cluster and run tests:
Run unit tests:

```sh
PROVISION=true IMAGES=spicedb:dev,spicedb:updated ginkgo --tags=e2e -r
```

Run with `go test` (ginkgo has better signal handling, prefer ginkgo to `go test`)

```sh
go test -tags=e2e ./...
mage test:unit
```

### Adding dependencies
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ We recommend one of the following:
Next, you'll install a [release](https://github.com/authzed/spicedb-operator/releases/) of the operator:

```console
kubectl apply --server-side -f https://github.com/authzed/spicedb-operator/releases/download/v1.1.0/bundle.yaml
kubectl apply --server-side -f https://github.com/authzed/spicedb-operator/releases/latest/download/bundle.yaml
```

Finally you can create your first cluster:
Expand Down
10 changes: 5 additions & 5 deletions default-operator-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -561,19 +561,19 @@ channels:
name: stable
nodes:
- id: v1.16.1
migration: add-caveats
migration: add_caveat
tag: v1.16.1
- id: v1.16.0
migration: add-caveats
migration: add_caveat
tag: v1.16.0
- id: v1.15.0
migration: add-caveats
migration: add_caveat
tag: v1.15.0
- id: v1.14.1
migration: add-caveats
migration: add_caveat
tag: v1.14.1
- id: v1.14.0
migration: add-caveats
migration: add_caveat
tag: v1.14.0
- id: v1.13.0
migration: add_ns_config_id
Expand Down
86 changes: 86 additions & 0 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//go:build mage
// +build mage

package main

import (
"fmt"
"os/exec"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
kind "sigs.k8s.io/kind/pkg/cluster"
"sigs.k8s.io/kind/pkg/cmd"
)

var Aliases = map[string]interface{}{
"test": Test.Unit,
"e2e": Test.E2e,
"generate": Gen.All,
}

type Test mg.Namespace

// Runs the unit tests
func (Test) Unit() error {
fmt.Println("running unit tests")
goCmd := "go"
if hasBinary("richgo") {
goCmd = "richgo"
}
return sh.RunV(goCmd, "test", "./...")
}

// Runs the end-to-end tests in a kind cluster
func (Test) E2e() error {
mg.Deps(checkDocker)
fmt.Println("running e2e tests")
return sh.RunWithV(map[string]string{
"PROVISION": "true",
}, "go", "run", "github.com/onsi/ginkgo/v2/ginkgo", "--tags=e2e", "-p", "-r", "-v", "--fail-fast", "--randomize-all", "--race", "e2e")
}

// Removes the kind cluster used for end-to-end tests
func (Test) Clean_e2e() error {
mg.Deps(checkDocker)
fmt.Println("removing kind cluster")
return kind.NewProvider(
kind.ProviderWithLogger(cmd.NewLogger()),
).Delete("spicedb-operator-e2e", "")
}

type Gen mg.Namespace

// Run all generators in parallel
func (g Gen) All() error {
mg.Deps(g.Api, g.Graph)
return nil
}

// Run kube api codegen
func (Gen) Api() error {
fmt.Println("generating apis")
return sh.RunV("go", "generate", "./...")
}

// Generate the update graph
func (Gen) Graph() error {
fmt.Println("generating update graph")
return sh.RunV("go", "generate", "./tools/generate-update-graph/main.go")
}

func checkDocker() error {
if !hasBinary("docker") {
return fmt.Errorf("docker must be installed to run e2e tests")
}
err := sh.Run("docker", "ps")
if err == nil || sh.ExitStatus(err) == 0 {
return nil
}
return err
}

func hasBinary(binaryName string) bool {
_, err := exec.LookPath(binaryName)
return err == nil
}
10 changes: 5 additions & 5 deletions tools/generate-update-graph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ func crdbChannel() updates.Channel {

func mysqlChannel() updates.Channel {
releases := []updates.State{
{ID: "v1.16.1", Tag: "v1.16.1", Migration: "add-caveats"},
{ID: "v1.16.0", Tag: "v1.16.0", Migration: "add-caveats"},
{ID: "v1.15.0", Tag: "v1.15.0", Migration: "add-caveats"},
{ID: "v1.14.1", Tag: "v1.14.1", Migration: "add-caveats"},
{ID: "v1.14.0", Tag: "v1.14.0", Migration: "add-caveats"},
{ID: "v1.16.1", Tag: "v1.16.1", Migration: "add_caveat"},
{ID: "v1.16.0", Tag: "v1.16.0", Migration: "add_caveat"},
{ID: "v1.15.0", Tag: "v1.15.0", Migration: "add_caveat"},
{ID: "v1.14.1", Tag: "v1.14.1", Migration: "add_caveat"},
{ID: "v1.14.0", Tag: "v1.14.0", Migration: "add_caveat"},
{ID: "v1.13.0", Tag: "v1.13.0", Migration: "add_ns_config_id"},
{ID: "v1.12.0", Tag: "v1.12.0", Migration: "add_ns_config_id"},
{ID: "v1.11.0", Tag: "v1.11.0", Migration: "add_ns_config_id"},
Expand Down
14 changes: 7 additions & 7 deletions tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/exp v0.0.0-20220823124025-807a23277127 // indirect
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.26.0 // indirect
k8s.io/apimachinery v0.26.0 // indirect
k8s.io/api v0.26.1 // indirect
k8s.io/apimachinery v0.26.1 // indirect
k8s.io/client-go v0.26.0 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
Expand Down
Loading

0 comments on commit 98433af

Please sign in to comment.