From 004e8af5330852f3976212ad2327c25324dc8bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20S=C3=B6derlund?= Date: Sun, 30 Jan 2022 08:07:13 +0100 Subject: [PATCH] ci: migrate to sage --- .github/workflows/release.yml | 3 ++ .gitignore | 3 +- .mage/go.mod | 15 -------- .mage/go.sum | 14 ------- .mage/magefile.go | 55 ---------------------------- .sage/go.mod | 5 +++ .sage/go.sum | 2 + .sage/sagefile.go | 69 +++++++++++++++++++++++++++++++++++ Makefile | 59 ++++++++++++++---------------- 9 files changed, 109 insertions(+), 116 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/workflows/release.yml b/.github/workflows/release.yml index cd20ddd..1abc1a1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,9 @@ jobs: - name: Make run: make + - name: Fetch tags + run: git fetch --force --tags + - name: Release uses: go-semantic-release/action@v1.15.0 with: diff --git a/.gitignore b/.gitignore index 87f951d..e233e44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode .idea -.mage/tools +.generated-go-semantic-release-changelog.md +.semrel diff --git a/.mage/go.mod b/.mage/go.mod deleted file mode 100644 index 87fbed8..0000000 --- a/.mage/go.mod +++ /dev/null @@ -1,15 +0,0 @@ -module mage-tools - -go 1.17 - -require ( - github.com/magefile/mage v1.12.1 - 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 d20aae9..0000000 --- a/.mage/go.sum +++ /dev/null @@ -1,14 +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 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= -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 4df94e0..0000000 --- a/.mage/magefile.go +++ /dev/null @@ -1,55 +0,0 @@ -//go:build mage -// +build mage - -package main - -import ( - "github.com/magefile/mage/mg" - "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/mggoreview" - - // 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, - mggoreview.Goreview, - mggo.GoTest, - mgmarkdownfmt.FormatMarkdown, - mgyamlfmt.FormatYaml, - ) - mg.SerialDeps( - mggo.GoModTidy, - mggitverifynodiff.GitVerifyNoDiff, - ) -} diff --git a/.sage/go.mod b/.sage/go.mod new file mode 100644 index 0000000..86bce7d --- /dev/null +++ b/.sage/go.mod @@ -0,0 +1,5 @@ +module sage + +go 1.17 + +require go.einride.tech/sage v0.65.0 diff --git a/.sage/go.sum b/.sage/go.sum new file mode 100644 index 0000000..cf99847 --- /dev/null +++ b/.sage/go.sum @@ -0,0 +1,2 @@ +go.einride.tech/sage v0.65.0 h1:tan4TFJ8RdtdGrKGyxv9P8dG1JXZQIwXLA+a1Jce4aQ= +go.einride.tech/sage v0.65.0/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ= diff --git a/.sage/sagefile.go b/.sage/sagefile.go new file mode 100644 index 0000000..d3a4332 --- /dev/null +++ b/.sage/sagefile.go @@ -0,0 +1,69 @@ +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, GolangciLint, GoReview, GoTest, FormatMarkdown, FormatYAML) + sg.SerialDeps(ctx, 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 GolangciLint(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) +} diff --git a/Makefile b/Makefile index 316faae..244bd33 100644 --- a/Makefile +++ b/Makefile @@ -1,52 +1,49 @@ -# 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 .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-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