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 30, 2022
1 parent b54b969 commit 004e8af
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 116 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
- name: Make
run: make

- name: Fetch tags
run: git fetch --force --tags

- name: Release
uses: go-semantic-release/[email protected]
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
.idea
.mage/tools
.generated-go-semantic-release-changelog.md
.semrel
15 changes: 0 additions & 15 deletions .mage/go.mod

This file was deleted.

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

This file was deleted.

55 changes: 0 additions & 55 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.65.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.65.0 h1:tan4TFJ8RdtdGrKGyxv9P8dG1JXZQIwXLA+a1Jce4aQ=
go.einride.tech/sage v0.65.0/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ=
69 changes: 69 additions & 0 deletions .sage/sagefile.go
Original file line number Diff line number Diff line change
@@ -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)
}
59 changes: 28 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 004e8af

Please sign in to comment.