Skip to content

Commit

Permalink
ci: migrate to Sage
Browse files Browse the repository at this point in the history
  • Loading branch information
odsod committed Apr 3, 2022
1 parent 072e044 commit 43d356f
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 142 deletions.
8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 3 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ 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

- name: Report Code Coverage
uses: codecov/[email protected]
with:
file: .mage/tools/go/coverage/go-test.txt
file: .sage/build/go/coverage/go-test.txt
fail_ci_if_error: true
10 changes: 2 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions .mage/go.mod

This file was deleted.

15 changes: 0 additions & 15 deletions .mage/go.sum

This file was deleted.

57 changes: 0 additions & 57 deletions .mage/magefile.go

This file was deleted.

5 changes: 5 additions & 0 deletions .sage/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module sage

go 1.17

require go.einride.tech/sage v0.106.0
2 changes: 2 additions & 0 deletions .sage/go.sum
Original file line number Diff line number Diff line change
@@ -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=
76 changes: 76 additions & 0 deletions .sage/sagefile.go
Original file line number Diff line number Diff line change
@@ -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()
}
72 changes: 41 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
25 changes: 23 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.einride.tech/spanner-aip

go 1.15
go 1.17

require (
cloud.google.com/go v0.100.2
Expand All @@ -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
)
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 43d356f

Please sign in to comment.