Skip to content

Commit

Permalink
(#20) fix: comment out nilaway usage in
Browse files Browse the repository at this point in the history
           build.yml and build.sh
(#18) chore: update go 1.22.6=>1.23
(#22) chore: simplify EatTrailingEOL function
(#21) nf: add disableFlag and TaskDisabled
          function
  • Loading branch information
majohn-r committed Aug 21, 2024
1 parent d516a49 commit 80b2581
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 26 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Fetch go
uses: actions/setup-go@v5
with:
go-version: 1.22.6
go-version: 1.23
- name: Get dependencies
run: go get -u ./...
- name: Install linter
Expand All @@ -22,15 +22,15 @@ jobs:
with:
name: lint results
path: lint-issues.txt
- name: Install nilaway
run: go install go.uber.org/nilaway/cmd/nilaway@latest
- name: Run nilaway
run: nilaway ./... > nilaway-issues.txt
- name: Post nilaway issues
uses: actions/upload-artifact@v4
with:
name: nilaway results
path: nilaway-issues.txt
# - name: Install nilaway
# run: go install go.uber.org/nilaway/cmd/nilaway@latest
# - name: Run nilaway
# run: nilaway ./... > nilaway-issues.txt
# - name: Post nilaway issues
# uses: actions/upload-artifact@v4
# with:
# name: nilaway results
# path: nilaway-issues.txt
- name: Run format check
run: gofmt -d -e -l ./ > format-issues.txt
- name: Post format issues
Expand All @@ -43,7 +43,7 @@ jobs:
- name: Run vulnerability check
uses: golang/govulncheck-action@v1
with:
go-version-input: 1.22.6
go-version-input: 1.23
- name: Execute unit tests with code coverage
run: go test -coverprofile=coverage -covermode=atomic ./...
- name: Upload coverage to Codecov
Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ go mod tidy
echo "lint"
go install -v github.com/go-critic/go-critic/cmd/gocritic@latest
gocritic check -enableAll ./...
echo "nilaway"
go install -v go.uber.org/nilaway/cmd/nilaway@latest
nilaway ./...
#echo "nilaway"
#go install -v go.uber.org/nilaway/cmd/nilaway@latest
#nilaway ./...
echo "format"
gofmt -e -l -s -w .
echo "vulnerability check"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/majohn-r/tools-build

go 1.22
go 1.23

require (
github.com/goyek/goyek/v2 v2.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
go 1.22.2
go 1.23

toolchain go1.22.6
toolchain go1.23

use .
11 changes: 2 additions & 9 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ var (
PrintlnFn = fmt.Println
)

// EatTrailingEOL removes trailing \n and \r characters from the end of a string; recurses.
// EatTrailingEOL removes trailing \n and \r characters from the end of a string
func EatTrailingEOL(s string) string {
switch {
case strings.HasSuffix(s, "\n"):
return EatTrailingEOL(strings.TrimSuffix(s, "\n"))
case strings.HasSuffix(s, "\r"):
return EatTrailingEOL(strings.TrimSuffix(s, "\r"))
default:
return s
}
return strings.TrimRight(s, "\n\r")
}

// PrintBuffer sends the buffer contents to stdout, but first strips trailing EOL characters, and then only prints the
Expand Down
19 changes: 19 additions & 0 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ var (
false,
"set to make dependency updates more aggressive",
)
disableFlag = flag.String(
"disable",
"",
"set to a comma-delimited set of tasks to disable",
)
// NoFormatFlag is a flag to disable formatting from the deadcode command
NoFormatFlag = flag.Bool(
"noformat",
Expand Down Expand Up @@ -191,6 +196,20 @@ func RunCommand(a *goyek.A, command string) bool {
return dc.execute(a)
}

// TaskDisabled returns true if the provided taskName matches (case-insensitively)
// one of the comma-delimited values in the disable flag's value
func TaskDisabled(taskName string) (disabled bool) {
disabledTasks := *disableFlag
tasks := strings.Split(disabledTasks, ",")
for _, task := range tasks {
if strings.EqualFold(taskName, strings.Trim(task, " ")) {
disabled = true
break
}
}
return
}

// UnitTests runs all unit tests, with code coverage enabled; returns false on
// failure
func UnitTests(a *goyek.A) bool {
Expand Down
32 changes: 32 additions & 0 deletions tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,3 +956,35 @@ func Test_directedCommand_execute(t *testing.T) {
})
}
}

func TestTaskDisabled(t *testing.T) {
originalDisableFlag := disableFlag
defer func() {
disableFlag = originalDisableFlag
}()
tests := map[string]struct {
taskName string
disableValue string
wantDisabled bool
}{
"typical": {
taskName: "nilaway",
disableValue: "",
wantDisabled: false,
},
"real use case": {
taskName: "nilaway",
disableValue: "task1, task2, NilAway ",
wantDisabled: true,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
flag := tt.disableValue
disableFlag = &flag
if gotDisabled := TaskDisabled(tt.taskName); gotDisabled != tt.wantDisabled {
t.Errorf("TaskDisabled() = %v, want %v", gotDisabled, tt.wantDisabled)
}
})
}
}

0 comments on commit 80b2581

Please sign in to comment.