From 43d356f55ad265db6df54d1f4f24754b07f38cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20S=C3=B6derlund?= Date: Sun, 3 Apr 2022 17:57:43 +0200 Subject: [PATCH] ci: migrate to Sage --- .github/dependabot.yml | 8 ++-- .github/workflows/ci.yml | 12 ++---- .github/workflows/release.yml | 10 +---- .mage/go.mod | 15 ------- .mage/go.sum | 15 ------- .mage/magefile.go | 57 -------------------------- .sage/go.mod | 5 +++ .sage/go.sum | 2 + .sage/sagefile.go | 76 +++++++++++++++++++++++++++++++++++ Makefile | 72 +++++++++++++++++++-------------- go.mod | 25 +++++++++++- go.sum | 3 +- 12 files changed, 158 insertions(+), 142 deletions(-) delete mode 100644 .mage/go.mod delete mode 100644 .mage/go.sum delete mode 100644 .mage/magefile.go create mode 100644 .sage/go.mod create mode 100644 .sage/go.sum create mode 100644 .sage/sagefile.go diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 26bd213..8a8bb11 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,14 +4,14 @@ updates: - package-ecosystem: github-actions directory: / schedule: - interval: daily + interval: weekly - package-ecosystem: gomod directory: / schedule: - interval: daily + interval: weekly - package-ecosystem: gomod - directory: .mage + directory: .sage schedule: - interval: daily + interval: weekly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9fc24c..d60c8ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,14 +8,8 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: ^1.17 + - name: Setup Sage + uses: einride/sage/actions/setup@master - name: Make run: make @@ -23,5 +17,5 @@ jobs: - name: Report Code Coverage uses: codecov/codecov-action@v2.1.0 with: - file: .mage/tools/go/coverage/go-test.txt + file: .sage/build/go/coverage/go-test.txt fail_ci_if_error: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 519ec6b..f554507 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,14 +10,8 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: ^1.17 + - name: Setup Sage + uses: einride/sage/actions/setup@master - name: Make run: make diff --git a/.mage/go.mod b/.mage/go.mod deleted file mode 100644 index 4c339f5..0000000 --- a/.mage/go.mod +++ /dev/null @@ -1,15 +0,0 @@ -module mage-tools - -go 1.17 - -require ( - github.com/magefile/mage v1.13.0 - go.einride.tech/mage-tools v0.28.0 -) - -require ( - github.com/go-logr/logr v1.2.2 // indirect - github.com/google/uuid v1.3.0 // indirect - github.com/iancoleman/strcase v0.2.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect -) diff --git a/.mage/go.sum b/.mage/go.sum deleted file mode 100644 index 7cc7e99..0000000 --- a/.mage/go.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= -github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= -github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= -github.com/magefile/mage v1.12.1/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= -github.com/magefile/mage v1.13.0 h1:XtLJl8bcCM7EFoO8FyH8XK3t7G5hQAeK+i4tq+veT9M= -github.com/magefile/mage v1.13.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= -go.einride.tech/mage-tools v0.28.0 h1:RSCd3tN6WrtSuudwmqiAzjCKfuTpLtE7bLKqTyuMOMU= -go.einride.tech/mage-tools v0.28.0/go.mod h1:pFpCBZ0U7a6862mks4y6v5xBkT4IhdrcJdEeTEjweMI= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/.mage/magefile.go b/.mage/magefile.go deleted file mode 100644 index 07a7fcb..0000000 --- a/.mage/magefile.go +++ /dev/null @@ -1,57 +0,0 @@ -//go:build mage -// +build mage - -package main - -import ( - "github.com/magefile/mage/mg" - "github.com/magefile/mage/sh" - "go.einride.tech/mage-tools/mgmake" - "go.einride.tech/mage-tools/mgpath" - - // mage:import - "go.einride.tech/mage-tools/targets/mgyamlfmt" - - // mage:import - "go.einride.tech/mage-tools/targets/mgconvco" - - // mage:import - "go.einride.tech/mage-tools/targets/mggo" - - // mage:import - "go.einride.tech/mage-tools/targets/mggolangcilint" - - // mage:import - "go.einride.tech/mage-tools/targets/mgmarkdownfmt" - - // mage:import - "go.einride.tech/mage-tools/targets/mggitverifynodiff" -) - -func init() { - mgmake.GenerateMakefiles( - mgmake.Makefile{ - Path: mgpath.FromGitRoot("Makefile"), - DefaultTarget: All, - }, - ) -} - -func All() { - mg.Deps( - mg.F(mgconvco.ConvcoCheck, "origin/master..HEAD"), - mggolangcilint.GolangciLint, - mgmarkdownfmt.FormatMarkdown, - mgyamlfmt.FormatYaml, - SpannerGenerate, - ) - mg.SerialDeps( - mggo.GoTest, - mggo.GoModTidy, - mggitverifynodiff.GitVerifyNoDiff, - ) -} - -func SpannerGenerate() error { - return sh.RunV("go", "run", ".", "generate") -} diff --git a/.sage/go.mod b/.sage/go.mod new file mode 100644 index 0000000..1c6d8c0 --- /dev/null +++ b/.sage/go.mod @@ -0,0 +1,5 @@ +module sage + +go 1.17 + +require go.einride.tech/sage v0.106.0 diff --git a/.sage/go.sum b/.sage/go.sum new file mode 100644 index 0000000..6a1bb91 --- /dev/null +++ b/.sage/go.sum @@ -0,0 +1,2 @@ +go.einride.tech/sage v0.106.0 h1:HtfQDCPZTfNA3QLdB7lDqA8vPsgMmn6ERR4Y+qqJFcU= +go.einride.tech/sage v0.106.0/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ= diff --git a/.sage/sagefile.go b/.sage/sagefile.go new file mode 100644 index 0000000..9f34806 --- /dev/null +++ b/.sage/sagefile.go @@ -0,0 +1,76 @@ +package main + +import ( + "context" + + "go.einride.tech/sage/sg" + "go.einride.tech/sage/tools/sgconvco" + "go.einride.tech/sage/tools/sggit" + "go.einride.tech/sage/tools/sggo" + "go.einride.tech/sage/tools/sggolangcilint" + "go.einride.tech/sage/tools/sggoreview" + "go.einride.tech/sage/tools/sgmarkdownfmt" + "go.einride.tech/sage/tools/sgyamlfmt" +) + +func main() { + sg.GenerateMakefiles( + sg.Makefile{ + Path: sg.FromGitRoot("Makefile"), + DefaultTarget: All, + }, + ) +} + +func All(ctx context.Context) error { + sg.Deps(ctx, ConvcoCheck, FormatMarkdown, FormatYAML) + sg.Deps(ctx, GoLint, GoReview) + sg.Deps(ctx, SpannerGenerate) + sg.SerialDeps(ctx, GoTest, GoModTidy, GitVerifyNoDiff) + return nil +} + +func FormatYAML(ctx context.Context) error { + sg.Logger(ctx).Println("formatting YAML files...") + return sgyamlfmt.Command(ctx, "-d", sg.FromGitRoot(), "-r").Run() +} + +func GoModTidy(ctx context.Context) error { + sg.Logger(ctx).Println("tidying Go module files...") + return sg.Command(ctx, "go", "mod", "tidy", "-v").Run() +} + +func GoTest(ctx context.Context) error { + sg.Logger(ctx).Println("running Go tests...") + return sggo.TestCommand(ctx).Run() +} + +func GoReview(ctx context.Context) error { + sg.Logger(ctx).Println("reviewing Go files...") + return sggoreview.Command(ctx, "-c", "1", "./...").Run() +} + +func GoLint(ctx context.Context) error { + sg.Logger(ctx).Println("linting Go files...") + return sggolangcilint.Run(ctx) +} + +func FormatMarkdown(ctx context.Context) error { + sg.Logger(ctx).Println("formatting Markdown files...") + return sgmarkdownfmt.Command(ctx, "-w", ".").Run() +} + +func ConvcoCheck(ctx context.Context) error { + sg.Logger(ctx).Println("checking git commits...") + return sgconvco.Command(ctx, "check", "origin/master..HEAD").Run() +} + +func GitVerifyNoDiff(ctx context.Context) error { + sg.Logger(ctx).Println("verifying that git has no diff...") + return sggit.VerifyNoDiff(ctx) +} + +func SpannerGenerate(ctx context.Context) error { + sg.Logger(ctx).Println("generating Spanner code...") + return sg.Command(ctx, "go", "run", ".", "generate").Run() +} diff --git a/Makefile b/Makefile index 4924b3e..0764633 100644 --- a/Makefile +++ b/Makefile @@ -1,52 +1,62 @@ -# Code generated by go.einride.tech/mage-tools. DO NOT EDIT. -# To learn more, see .mage/magefile.go and https://github.com/einride/mage-tools. +# Code generated by go.einride.tech/sage. DO NOT EDIT. +# To learn more, see .sage/sagefile.go and https://github.com/einride/sage. .DEFAULT_GOAL := all -magefile := .mage/tools/bin/magefile +sagefile := .sage/bin/sagefile -$(magefile): .mage/go.mod .mage/*.go - @cd .mage && go run go.einride.tech/mage-tools/cmd/build +$(sagefile): .sage/go.mod .sage/*.go + @cd .sage && go mod tidy && go run . -.PHONY: clean-mage-tools -clean-mage-tools: - @git clean -fdx .mage/tools +.PHONY: sage +sage: + @git clean -fxq $(sagefile) + @$(MAKE) $(sagefile) + +.PHONY: update-sage +update-sage: + @cd .sage && go get -d go.einride.tech/sage@latest && go mod tidy && go run . + +.PHONY: clean-sage +clean-sage: + @git clean -fdx .sage/tools .sage/bin .sage/build .PHONY: all -all: $(magefile) - @$(magefile) all +all: $(sagefile) + @$(sagefile) All .PHONY: convco-check -convco-check: $(magefile) -ifndef rev - $(error missing argument rev="...") -endif - @$(magefile) convcoCheck $(rev) +convco-check: $(sagefile) + @$(sagefile) ConvcoCheck .PHONY: format-markdown -format-markdown: $(magefile) - @$(magefile) formatMarkdown +format-markdown: $(sagefile) + @$(sagefile) FormatMarkdown .PHONY: format-yaml -format-yaml: $(magefile) - @$(magefile) formatYaml +format-yaml: $(sagefile) + @$(sagefile) FormatYAML .PHONY: git-verify-no-diff -git-verify-no-diff: $(magefile) - @$(magefile) gitVerifyNoDiff +git-verify-no-diff: $(sagefile) + @$(sagefile) GitVerifyNoDiff + +.PHONY: go-lint +go-lint: $(sagefile) + @$(sagefile) GoLint .PHONY: go-mod-tidy -go-mod-tidy: $(magefile) - @$(magefile) goModTidy +go-mod-tidy: $(sagefile) + @$(sagefile) GoModTidy -.PHONY: go-test -go-test: $(magefile) - @$(magefile) goTest +.PHONY: go-review +go-review: $(sagefile) + @$(sagefile) GoReview -.PHONY: golangci-lint -golangci-lint: $(magefile) - @$(magefile) golangciLint +.PHONY: go-test +go-test: $(sagefile) + @$(sagefile) GoTest .PHONY: spanner-generate -spanner-generate: $(magefile) - @$(magefile) spannerGenerate +spanner-generate: $(sagefile) + @$(sagefile) SpannerGenerate diff --git a/go.mod b/go.mod index 229b434..ed21995 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module go.einride.tech/spanner-aip -go 1.15 +go 1.17 require ( cloud.google.com/go v0.100.2 @@ -9,9 +9,30 @@ require ( github.com/stoewer/go-strcase v1.2.0 go.einride.tech/aip v0.54.1 google.golang.org/api v0.74.0 - google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb + google.golang.org/genproto v0.0.0-20220401170504-314d38edb7de google.golang.org/grpc v1.45.0 google.golang.org/protobuf v1.28.0 gopkg.in/yaml.v2 v2.4.0 gotest.tools/v3 v3.1.0 ) + +require ( + cloud.google.com/go/compute v1.5.0 // indirect + github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect + github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect + github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1 // indirect + github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021 // indirect + github.com/envoyproxy/protoc-gen-validate v0.1.0 // indirect + github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/googleapis/gax-go/v2 v2.2.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + go.opencensus.io v0.23.0 // indirect + golang.org/x/net v0.0.0-20220325170049-de3da57026de // indirect + golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect + golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886 // indirect + golang.org/x/text v0.3.7 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + google.golang.org/appengine v1.6.7 // indirect +) diff --git a/go.sum b/go.sum index d268ecc..6726079 100644 --- a/go.sum +++ b/go.sum @@ -564,8 +564,9 @@ google.golang.org/genproto v0.0.0-20220222213610-43724f9ea8cf/go.mod h1:kGP+zUP2 google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= google.golang.org/genproto v0.0.0-20220310185008-1973136f34c6/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= google.golang.org/genproto v0.0.0-20220323144105-ec3c684e5b14/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= -google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb h1:0m9wktIpOxGw+SSKmydXWB3Z3GTfcPP6+q75HCQa6HI= google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= +google.golang.org/genproto v0.0.0-20220401170504-314d38edb7de h1:9Ti5SG2U4cAcluryUo/sFay3TQKoxiFMfaT0pbizU7k= +google.golang.org/genproto v0.0.0-20220401170504-314d38edb7de/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=