Skip to content

Commit

Permalink
feat: migrate to sage and upgrade to go 1.19
Browse files Browse the repository at this point in the history
- Remove tools dir
- Fix linting errors
- Use go:generate for code generation and move mocks
- Update workflows to use go-semantic-release
- Change dependabot update frequency from daily to weekly
  • Loading branch information
Hashem Hashem authored and hashemmm96 committed Nov 9, 2022
1 parent 2de323b commit b334d91
Show file tree
Hide file tree
Showing 49 changed files with 505 additions and 592 deletions.
9 changes: 7 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +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: .sage
schedule:
interval: weekly
39 changes: 12 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,16 @@ jobs:
make:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.16

- name: Setup Node
uses: actions/setup-node@v3
- name: Setup Sage
uses: einride/sage/actions/setup@master
with:
node-version: 16
go-version: 1.19

- name: Make
run: make

- name: Report Code Coverage
uses: codecov/codecov-action@v2.1.0
uses: codecov/codecov-action@v3.1.1
with:
file: ./build/coverage/go-test.txt
fail_ci_if_error: true
Expand All @@ -39,26 +31,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
- name: Setup Sage
uses: einride/sage/actions/setup@master
with:
go-version: ^1.16
go-version: 1.19

- name: Setup Node
uses: actions/setup-node@v3
- name: Create Release
uses: go-semantic-release/[email protected]
with:
node-version: 16

- name: Run semantic-release
run: make semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
allow-initial-development-versions: true

- name: Run goreleaser
uses: goreleaser/goreleaser-action@v2.9.1
uses: goreleaser/goreleaser-action@v3.2.0
with:
version: latest
args: release --rm-dist
Expand Down
29 changes: 0 additions & 29 deletions .golangci.yml

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 go.einride.tech/can/.sage

go 1.19

require go.einride.tech/sage v0.184.1
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.184.1 h1:ZQPFz+TMzHZ9n6OVMv3GQwj3qlE2H2lMfWVMER/MGi8=
go.einride.tech/sage v0.184.1/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ=
128 changes: 128 additions & 0 deletions .sage/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package main

import (
"context"
"fmt"
"os"
"path/filepath"

"go.einride.tech/sage/sg"
"go.einride.tech/sage/sgtool"
"go.einride.tech/sage/tools/sgconvco"
"go.einride.tech/sage/tools/sggit"
"go.einride.tech/sage/tools/sggolangcilint"
"go.einride.tech/sage/tools/sggolicenses"
"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: Default,
},
)
}

func Default(ctx context.Context) error {
sg.Deps(ctx, ConvcoCheck, FormatMarkdown, FormatYaml, GoGenerate, GenerateTestdata)
sg.Deps(ctx, GoLint, GoReview)
sg.Deps(ctx, GoTest)
sg.Deps(ctx, GoModTidy)
sg.Deps(ctx, GoLicenses, GitVerifyNoDiff)
return nil
}

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...")
coverageDir := sg.FromGitRoot("build", "coverage")
if err := os.MkdirAll(coverageDir, 0o775); err != nil {
return err
}
return sg.Command(
ctx,
"go",
"test",
"-short",
"-race",
fmt.Sprintf("-coverprofile=%s", filepath.Join(coverageDir, "go-test.txt")),
"-covermode=atomic",
"./...",
).Run()
}

func GoReview(ctx context.Context) error {
sg.Logger(ctx).Println("reviewing Go files...")
return sggoreview.Run(ctx)
}

func GoLint(ctx context.Context) error {
sg.Logger(ctx).Println("linting Go files...")
return sggolangcilint.Run(ctx)
}

func GoLicenses(ctx context.Context) error {
sg.Logger(ctx).Println("checking Go licenses...")
return sggolicenses.Check(ctx)
}

func FormatMarkdown(ctx context.Context) error {
sg.Logger(ctx).Println("formatting Markdown files...")
return sgmarkdownfmt.Command(ctx, "-w", ".").Run()
}

func FormatYaml(ctx context.Context) error {
sg.Logger(ctx).Println("formatting Yaml files...")
return sgyamlfmt.Run(ctx)
}

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 GoGenerate(ctx context.Context) error {
sg.Deps(ctx, Mockgen, Stringer)
sg.Logger(ctx).Println("generating Go code...")
return sg.Command(ctx, "go", "generate", "./...").Run()
}

func Mockgen(ctx context.Context) error {
sg.Logger(ctx).Println("installing mockgen...")
_, err := sgtool.GoInstallWithModfile(ctx, "github.com/golang/mock/mockgen", sg.FromGitRoot("go.mod"))
return err
}

func Stringer(ctx context.Context) error {
sg.Logger(ctx).Println("installing stringer...")
_, err := sgtool.GoInstallWithModfile(ctx, "golang.org/x/tools/cmd/stringer", sg.FromGitRoot("go.mod"))
return err
}

func GenerateTestdata(ctx context.Context) error {
sg.Logger(ctx).Println("generating testdata...")
// don't use "sg.FromGitRoot" in paths to avoid embedding user paths in generated files
cmd := sg.Command(
ctx,
"go",
"run",
"cmd/cantool/main.go",
"generate",
"testdata/dbc",
"testdata/gen/go",
)
cmd.Dir = sg.FromGitRoot()
return cmd.Run()
}
Loading

0 comments on commit b334d91

Please sign in to comment.