Skip to content

Commit

Permalink
chore: migrate to sage
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwenn committed Apr 3, 2022
1 parent a5a6ea2 commit b60403f
Show file tree
Hide file tree
Showing 33 changed files with 425 additions and 456 deletions.
File renamed without changes.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ updates:
directory: /
schedule:
interval: daily

- package-ecosystem: gomod
directory: .sage
schedule:
interval: weekly
60 changes: 0 additions & 60 deletions .github/workflows/ci.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: release

on:
push:
branches: [master]

permissions: write-all

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Setup Sage
uses: einride/sage/actions/setup@master

- name: Make
run: make

- name: Release
uses: go-semantic-release/action@v1.17
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
allow-initial-development-versions: true

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

- name: Run goreleaser
uses: goreleaser/goreleaser-action@v2.9.1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: review

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
make:
runs-on: ubuntu-latest
steps:
- name: Setup Sage
uses: einride/sage/actions/setup@master

- name: Make
run: make
30 changes: 0 additions & 30 deletions .golangci.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .sage/einrideeslint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

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

"go.einride.tech/sage/sg"
"go.einride.tech/sage/sgtool"
)

const (
name = "eslint"
packageJSONContent = `{
"dependencies": {
"@einride/eslint-plugin": "4.2.0",
"eslint": "8.5.0"
}
}`
)

func eslintCommand(ctx context.Context, args ...string) *exec.Cmd {
sg.Deps(ctx, prepareEslintCommand)
// eslint plugins should be resolved from the tool dir
defaultArgs := []string{
"--resolve-plugins-relative-to",
sg.FromToolsDir(name),
}
cmd := sg.Command(ctx, sg.FromBinDir(name), append(defaultArgs, args...)...)
return cmd
}

func prepareEslintCommand(ctx context.Context) error {
toolDir := sg.FromToolsDir(name)
binary := filepath.Join(toolDir, "node_modules", ".bin", name)
packageJSON := filepath.Join(toolDir, "package.json")
if err := os.MkdirAll(toolDir, 0o755); err != nil {
return err
}
if err := os.WriteFile(packageJSON, []byte(packageJSONContent), 0o600); err != nil {
return err
}
sg.Logger(ctx).Println("installing packages...")
if err := sg.Command(
ctx,
"npm",
"--silent",
"install",
"--prefix",
toolDir,
"--no-save",
"--no-audit",
"--ignore-script",
).Run(); err != nil {
return err
}
if _, err := sgtool.CreateSymlink(binary); err != nil {
return err
}
return nil
}
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.106.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.106.0 h1:HtfQDCPZTfNA3QLdB7lDqA8vPsgMmn6ERR4Y+qqJFcU=
go.einride.tech/sage v0.106.0/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ=
56 changes: 56 additions & 0 deletions .sage/proto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"context"

"go.einride.tech/sage/sg"
"go.einride.tech/sage/tools/sgbuf"
)

type Proto sg.Namespace

func (Proto) All(ctx context.Context) error {
sg.SerialDeps(ctx, Proto.Build)
sg.Deps(ctx, Proto.BufLint, Proto.BufFormat, Proto.BufGenerate)
return nil
}

func (Proto) Build(ctx context.Context) error {
sg.Logger(ctx).Println("installing binary...")
return sg.Command(
ctx,
"go",
"build",
"-o",
sg.FromBinDir("protoc-gen-typescript-http"),
".",
).Run()
}

func (Proto) BufLint(ctx context.Context) error {
sg.Logger(ctx).Println("linting proto files...")
cmd := sgbuf.Command(ctx, "lint")
cmd.Dir = sg.FromGitRoot("examples", "proto")
return cmd.Run()
}

func (Proto) BufFormat(ctx context.Context) error {
sg.Logger(ctx).Println("formatting proto files...")
cmd := sgbuf.Command(ctx, "format", "--write")
cmd.Dir = sg.FromGitRoot("examples", "proto")
return cmd.Run()
}

func (Proto) BufGenerate(ctx context.Context) error {
sg.Logger(ctx).Println("generating from proto files...")
cmd := sgbuf.Command(
ctx,
"generate",
"--template",
"buf.gen.yaml",
"--path",
"einride",
)
cmd.Dir = sg.FromGitRoot("examples", "proto")
return cmd.Run()
}
86 changes: 86 additions & 0 deletions .sage/sagefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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,
},
sg.Makefile{
Namespace: Proto{},
DefaultTarget: Proto.All,
Path: sg.FromGitRoot("examples", "proto", "Makefile"),
},
)
}

func All(ctx context.Context) error {
sg.Deps(ctx, ConvcoCheck, GoLint, GoReview, GoTest, FormatMarkdown, FormatYAML)
sg.SerialDeps(ctx, Proto.All, TypescriptLint)
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 GoLint(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)
}

func TypescriptLint(ctx context.Context) error {
sg.Logger(ctx).Println("linting typescript files...")
return eslintCommand(
ctx,
"--config",
sg.FromGitRoot(".eslintrc.js"),
"--quiet",
"examples/proto/gen/typescript/**/*.ts",
).Run()
}
Loading

0 comments on commit b60403f

Please sign in to comment.