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 Jan 27, 2022
1 parent f190870 commit 8587c6c
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 142 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ updates:
interval: daily

- package-ecosystem: gomod
directory: .mage
directory: .sage
schedule:
interval: daily
interval: weekly
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.vscode
.idea
.mage/tools
15 changes: 0 additions & 15 deletions .mage/go.mod

This file was deleted.

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

This file was deleted.

2 changes: 2 additions & 0 deletions .sage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tools/
bin/
13 changes: 13 additions & 0 deletions .sage/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module sage

go 1.17

require (
github.com/go-logr/logr v1.2.2
go.einride.tech/sage v0.53.0
)

require (
github.com/iancoleman/strcase v0.2.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
8 changes: 2 additions & 6 deletions .mage/go.sum → .sage/go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
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 h1:oGdAbhIUd6iKamKlDGVtU6XGdy5SgNuCWn7gCTgHDtU=
github.com/magefile/mage v1.12.1/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=
go.einride.tech/sage v0.53.0 h1:6cdx0zubvjvWGlKiw/Jv0Od/BGZv+twr7Rl3EZWrZBk=
go.einride.tech/sage v0.53.0/go.mod h1:6qSXPc1PUoJOCbavwiKy4kq5SqQ1invk5C7pBG9UP3o=
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=
Expand Down
93 changes: 93 additions & 0 deletions .sage/sagefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package main

import (
"context"
"fmt"
"os"
"regexp"
"strings"

"github.com/go-logr/logr"
"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, GolangciLint, GoReview, GoTest, FormatMarkdown, FormatYAML, ReadmeSnippet)
sg.SerialDeps(ctx, GoModTidy, GitVerifyNoDiff)
return nil
}

func FormatYAML(ctx context.Context) error {
logr.FromContextOrDiscard(ctx).Info("formatting YAML files...")
return sgyamlfmt.FormatYAML(ctx)
}

func GoModTidy(ctx context.Context) error {
logr.FromContextOrDiscard(ctx).Info("tidying Go module files...")
return sg.Command(ctx, "go", "mod", "tidy", "-v").Run()
}

func GoTest(ctx context.Context) error {
logr.FromContextOrDiscard(ctx).Info("running Go tests...")
return sggo.TestCommand(ctx).Run()
}

func GoReview(ctx context.Context) error {
logr.FromContextOrDiscard(ctx).Info("reviewing Go files...")
return sggoreview.Command(ctx, "-c", "1", "./...").Run()
}

func GolangciLint(ctx context.Context) error {
logr.FromContextOrDiscard(ctx).Info("linting Go files...")
return sggolangcilint.RunCommand(ctx).Run()
}

func FormatMarkdown(ctx context.Context) error {
logr.FromContextOrDiscard(ctx).Info("formatting Markdown files...")
return sgmarkdownfmt.Command(ctx, "-w", ".").Run()
}

func ConvcoCheck(ctx context.Context) error {
logr.FromContextOrDiscard(ctx).Info("checking git commits...")
return sgconvco.Command(ctx, "check", "origin/master..HEAD").Run()
}

func GitVerifyNoDiff(ctx context.Context) error {
logr.FromContextOrDiscard(ctx).Info("verifying that git has no diff...")
return sggit.VerifyNoDiff(ctx)
}

func ReadmeSnippet(ctx context.Context) error {
usage := sg.Output(sg.Command(ctx, "go", "run", "./examples/cmd/grpc-server", "-help"))
usage = strings.TrimSpace(usage)
usage = "<!-- BEGIN usage -->\n\n```\n" + usage
usage = usage + "\n```\n\n<!-- END usage -->"
readme, err := os.ReadFile("README.md")
if err != nil {
return err
}
usageRegexp, err := regexp.Compile(`(?ms)<!-- BEGIN usage -->.*<!-- END usage -->`)
if err != nil {
return err
}
if !usageRegexp.Match(readme) {
return fmt.Errorf("found no match for 'usage' snippet in README.md")
}
return os.WriteFile("README.md", usageRegexp.ReplaceAll(readme, []byte(usage)), 0o600)
}
63 changes: 30 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
# 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: clean-sage
clean-sage:
@git clean -fdx .sage/tools

.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-mod-tidy
go-mod-tidy: $(magefile)
@$(magefile) goModTidy
go-mod-tidy: $(sagefile)
@$(sagefile) GoModTidy

.PHONY: go-review
go-review: $(sagefile)
@$(sagefile) GoReview

.PHONY: go-test
go-test: $(magefile)
@$(magefile) goTest
go-test: $(sagefile)
@$(sagefile) GoTest

.PHONY: golangci-lint
golangci-lint: $(magefile)
@$(magefile) golangciLint

.PHONY: goreview
goreview: $(magefile)
@$(magefile) goreview
golangci-lint: $(sagefile)
@$(sagefile) GolangciLint

.PHONY: readme-snippet
readme-snippet: $(magefile)
@$(magefile) readmeSnippet
readme-snippet: $(sagefile)
@$(sagefile) ReadmeSnippet

0 comments on commit 8587c6c

Please sign in to comment.