-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate to sage and upgrade to go 1.19
- 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
1 parent
2de323b
commit b334d91
Showing
49 changed files
with
505 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
Oops, something went wrong.