Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit ecf992a

Browse files
authored
Bump goyek to v2 (#61)
1 parent c8c554d commit ecf992a

14 files changed

+1271
-1684
lines changed

.github/dependabot.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ updates:
1717
schedule:
1818
interval: "weekly"
1919

20+
- package-ecosystem: "gomod"
21+
directory: "/tools"
22+
schedule:
23+
interval: "weekly"
24+
2025
- package-ecosystem: "docker"
21-
directory: "/build"
26+
directory: "/tools"
2227
schedule:
2328
interval: "weekly"
2429

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/[email protected]
1515
- uses: actions/[email protected]
1616
with:
17-
go-version: 1.18
17+
go-version: '1.19'
1818
- run: ./goyek.sh
1919
- name: Upload HTML coverage
2020
uses: actions/[email protected]

.golangci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ linters-settings:
77
check-shadowing: true
88
misspell:
99
locale: US
10+
ignore-words:
11+
- importas
1012
nolintlint:
1113
allow-leading-space: false # require machine-readable nolint directives (with no leading space)
1214
allow-unused: false # report any unused nolint directives

build/build.go

+73-98
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,85 @@
1-
// Build is the build pipeline for this repository.
21
package main
32

43
import (
5-
"fmt"
64
"os"
75
"os/exec"
6+
"strings"
87

9-
"github.com/goyek/goyek"
10-
"github.com/mattn/go-shellwords"
8+
"github.com/goyek/goyek/v2"
119
)
1210

13-
const buildDir = "build"
14-
15-
func main() {
16-
flow().Main()
17-
}
18-
19-
func flow() *goyek.Flow {
20-
flow := &goyek.Flow{}
21-
22-
test := flow.Register(taskTest())
23-
lint := flow.Register(taskLint())
24-
misspell := flow.Register(taskMisspell())
25-
markdownlint := flow.Register(taskMarkdownLint())
26-
all := flow.Register(taskAll(goyek.Deps{
27-
test, lint, misspell, markdownlint,
28-
}))
29-
30-
flow.DefaultTask = all
31-
return flow
32-
}
33-
34-
func taskTest() goyek.Task {
35-
return goyek.Task{
36-
Name: "test",
37-
Usage: "go test with code covarage",
38-
Action: func(tf *goyek.TF) {
39-
Exec(tf, buildDir, "go test")
40-
Exec(tf, "", "go test -covermode=atomic -coverprofile=coverage.out ./...")
41-
},
42-
}
43-
}
44-
45-
func taskLint() goyek.Task {
46-
return goyek.Task{
47-
Name: "lint",
48-
Usage: "golangci-lint",
49-
Action: func(tf *goyek.TF) {
50-
Exec(tf, buildDir, "go install github.com/golangci/golangci-lint/cmd/golangci-lint")
51-
Exec(tf, buildDir, "golangci-lint run")
52-
Exec(tf, "", "golangci-lint run")
53-
},
54-
}
55-
}
56-
57-
func taskMisspell() goyek.Task {
58-
return goyek.Task{
59-
Name: "misspell",
60-
Usage: "misspell",
61-
Action: func(tf *goyek.TF) {
62-
Exec(tf, buildDir, "go install github.com/client9/misspell/cmd/misspell")
63-
Exec(tf, "", "misspell -error -locale=US *.md")
64-
},
65-
}
66-
}
67-
68-
func taskMarkdownLint() goyek.Task {
69-
return goyek.Task{
70-
Name: "markdownlint",
71-
Usage: "markdownlint-cli (uses docker)",
72-
Action: func(tf *goyek.TF) {
73-
if _, err := exec.LookPath("docker"); err != nil {
74-
tf.Skip(err)
75-
}
76-
77-
curDir, err := os.Getwd()
78-
if err != nil {
79-
tf.Fatal(err)
80-
}
81-
dockerTag := "markdownlint-cli"
82-
buildCmd := fmt.Sprintf("docker build -t %s -f build/markdownlint-cli.dockerfile .", dockerTag)
83-
Exec(tf, "", buildCmd)
84-
runCmd := fmt.Sprintf("docker run --rm -v %s:/workdir %s *.md", curDir, dockerTag)
85-
Exec(tf, "", runCmd)
86-
},
87-
}
88-
}
11+
const (
12+
rootDir = "."
13+
buildDir = "build"
14+
toolsDir = "tools"
15+
)
8916

90-
func taskAll(deps goyek.Deps) goyek.Task {
91-
return goyek.Task{
17+
func configure() {
18+
flow.SetDefault(flow.Define(goyek.Task{
9219
Name: "all",
9320
Usage: "build pipeline",
94-
Deps: deps,
95-
}
96-
}
97-
98-
// Exec runs the provided command line.
99-
// It fails the task in case of any problems.
100-
func Exec(tf *goyek.TF, workDir string, cmdLine string) {
101-
args, err := shellwords.Parse(cmdLine)
102-
if err != nil {
103-
tf.Fatalf("parse command line: %v", err)
104-
}
105-
cmd := tf.Cmd(args[0], args[1:]...)
106-
cmd.Dir = workDir
107-
if err := cmd.Run(); err != nil {
108-
tf.Fatalf("run command: %v", err)
109-
}
21+
Deps: goyek.Deps{
22+
flow.Define(goyek.Task{
23+
Name: "mod",
24+
Usage: "go mod tidy",
25+
Action: func(tf *goyek.TF) {
26+
Exec(tf, rootDir, "go mod tidy")
27+
Exec(tf, buildDir, "go mod tidy")
28+
Exec(tf, toolsDir, "go mod tidy")
29+
},
30+
}),
31+
flow.Define(goyek.Task{
32+
Name: "install",
33+
Usage: "go install tools",
34+
Action: func(tf *goyek.TF) {
35+
tools := &strings.Builder{}
36+
toolsCmd := tf.Cmd("go", "list", `-f={{ join .Imports " " }}`, "-tags=tools")
37+
toolsCmd.Dir = toolsDir
38+
toolsCmd.Stdout = tools
39+
if err := toolsCmd.Run(); err != nil {
40+
tf.Fatal(err)
41+
}
42+
Exec(tf, toolsDir, "go install "+strings.TrimSpace(tools.String()))
43+
},
44+
}),
45+
flow.Define(goyek.Task{
46+
Name: "golint",
47+
Usage: "golangci-lint",
48+
Action: func(tf *goyek.TF) {
49+
Exec(tf, rootDir, "golangci-lint run --fix")
50+
Exec(tf, buildDir, "golangci-lint run --fix")
51+
},
52+
}),
53+
flow.Define(goyek.Task{
54+
Name: "spell",
55+
Usage: "misspell",
56+
Action: func(tf *goyek.TF) {
57+
Exec(tf, rootDir, "misspell -error -locale=US -i=importas -w .")
58+
},
59+
}),
60+
flow.Define(goyek.Task{
61+
Name: "mdlint",
62+
Usage: "markdownlint-cli (uses docker)",
63+
Action: func(tf *goyek.TF) {
64+
if _, err := exec.LookPath("docker"); err != nil {
65+
tf.Skip(err)
66+
}
67+
curDir, err := os.Getwd()
68+
if err != nil {
69+
tf.Fatal(err)
70+
}
71+
dockerTag := "markdownlint-cli"
72+
Exec(tf, rootDir, "docker build -t "+dockerTag+" -f "+toolsDir+"/markdownlint-cli.dockerfile .")
73+
Exec(tf, rootDir, "docker run --rm -v '"+curDir+":/workdir' "+dockerTag+" *.md")
74+
},
75+
}),
76+
flow.Define(goyek.Task{
77+
Name: "test",
78+
Usage: "go test with code covarage",
79+
Action: func(tf *goyek.TF) {
80+
Exec(tf, rootDir, "go test -covermode=atomic -coverprofile=coverage.out ./...")
81+
},
82+
}),
83+
},
84+
}))
11085
}

build/exec.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"github.com/goyek/goyek/v2"
5+
"github.com/mattn/go-shellwords"
6+
)
7+
8+
// Exec runs the provided command line.
9+
// It fails the task in case of any problems.
10+
func Exec(tf *goyek.TF, workDir string, cmdLine string) {
11+
tf.Logf("Run %q in %s", cmdLine, workDir)
12+
args, err := shellwords.Parse(cmdLine)
13+
if err != nil {
14+
tf.Fatalf("parse command line: %v", err)
15+
}
16+
cmd := tf.Cmd(args[0], args[1:]...)
17+
cmd.Dir = workDir
18+
if err := cmd.Run(); err != nil {
19+
tf.Error(err)
20+
}
21+
}

build/go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module github.com/fluentassert/verify/build
22

3-
go 1.16
3+
go 1.19
44

55
require (
6-
github.com/client9/misspell v0.3.4
7-
github.com/golangci/golangci-lint v1.50.0
8-
github.com/goyek/goyek v1.1.0
6+
github.com/goyek/goyek/v2 v2.0.0-rc.2
97
github.com/mattn/go-shellwords v1.0.12
108
)

0 commit comments

Comments
 (0)