Skip to content

Commit 5e9851f

Browse files
authored
Update minimum go version (go-task#1758)
* feat: update minimum version to 1.22 * refactor: use int range iterator * refactor: loop variables * refactor: replace slicesext.FirstNonZero with cmp.Or * refactor: use slices.Concat instead of append * fix: unused param * fix: linting
1 parent 51c569e commit 5e9851f

File tree

18 files changed

+50
-60
lines changed

18 files changed

+50
-60
lines changed

.github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: Lint
1414
strategy:
1515
matrix:
16-
go-version: [1.21.x, 1.22.x]
16+
go-version: [1.22.x, 1.23.x]
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/setup-go@v5
@@ -25,7 +25,7 @@ jobs:
2525
- name: golangci-lint
2626
uses: golangci/golangci-lint-action@v6
2727
with:
28-
version: v1.55.2
28+
version: v1.60.1
2929

3030
lint-jsonschema:
3131
runs-on: ubuntu-latest

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Go
1616
uses: actions/setup-go@v5
1717
with:
18-
go-version: 1.21.x
18+
go-version: 1.22.x
1919

2020
- name: Run GoReleaser
2121
uses: goreleaser/goreleaser-action@v2

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: Test
1414
strategy:
1515
matrix:
16-
go-version: [1.21.x, 1.22.x]
16+
go-version: [1.22.x, 1.23.x]
1717
platform: [ubuntu-latest, macos-latest, windows-latest]
1818
runs-on: ${{matrix.platform}}
1919
steps:

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/go-task/task/v3
22

3-
go 1.21.0
3+
go 1.22.0
44

55
require (
66
github.com/Ladicle/tabwriter v1.0.0

hash.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package task
22

33
import (
4+
"cmp"
45
"fmt"
56

67
"github.com/go-task/task/v3/internal/hash"
7-
"github.com/go-task/task/v3/internal/slicesext"
88
"github.com/go-task/task/v3/taskfile/ast"
99
)
1010

1111
func (e *Executor) GetHash(t *ast.Task) (string, error) {
12-
r := slicesext.FirstNonZero(t.Run, e.Taskfile.Run)
12+
r := cmp.Or(t.Run, e.Taskfile.Run)
1313
var h hash.HashFunc
1414
switch r {
1515
case "always":

help.go

+13-15
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,21 @@ func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool) (*editors.Ta
160160
}
161161
var g errgroup.Group
162162
for i := range tasks {
163-
task := tasks[i]
164-
j := i
165163
aliases := []string{}
166-
if len(task.Aliases) > 0 {
167-
aliases = task.Aliases
164+
if len(tasks[i].Aliases) > 0 {
165+
aliases = tasks[i].Aliases
168166
}
169167
g.Go(func() error {
170-
o.Tasks[j] = editors.Task{
171-
Name: task.Name(),
172-
Desc: task.Desc,
173-
Summary: task.Summary,
168+
o.Tasks[i] = editors.Task{
169+
Name: tasks[i].Name(),
170+
Desc: tasks[i].Desc,
171+
Summary: tasks[i].Summary,
174172
Aliases: aliases,
175173
UpToDate: false,
176174
Location: &editors.Location{
177-
Line: task.Location.Line,
178-
Column: task.Location.Column,
179-
Taskfile: task.Location.Taskfile,
175+
Line: tasks[i].Location.Line,
176+
Column: tasks[i].Location.Column,
177+
Taskfile: tasks[i].Location.Taskfile,
180178
},
181179
}
182180

@@ -186,10 +184,10 @@ func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool) (*editors.Ta
186184

187185
// Get the fingerprinting method to use
188186
method := e.Taskfile.Method
189-
if task.Method != "" {
190-
method = task.Method
187+
if tasks[i].Method != "" {
188+
method = tasks[i].Method
191189
}
192-
upToDate, err := fingerprint.IsTaskUpToDate(context.Background(), task,
190+
upToDate, err := fingerprint.IsTaskUpToDate(context.Background(), tasks[i],
193191
fingerprint.WithMethod(method),
194192
fingerprint.WithTempDir(e.TempDir.Fingerprint),
195193
fingerprint.WithDry(e.Dry),
@@ -199,7 +197,7 @@ func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool) (*editors.Ta
199197
return err
200198
}
201199

202-
o.Tasks[j].UpToDate = upToDate
200+
o.Tasks[i].UpToDate = upToDate
203201

204202
return nil
205203
})

internal/deepcopy/deepcopy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TraverseStringsFunc[T any](v T, fn func(v string) (string, error)) (T, erro
8585

8686
case reflect.Struct:
8787
// Loop over each field and call traverseFunc recursively
88-
for i := 0; i < v.NumField(); i += 1 {
88+
for i := range v.NumField() {
8989
if err := traverseFunc(copy.Field(i), v.Field(i)); err != nil {
9090
return err
9191
}
@@ -95,7 +95,7 @@ func TraverseStringsFunc[T any](v T, fn func(v string) (string, error)) (T, erro
9595
// Create an empty copy from the original value's type
9696
copy.Set(reflect.MakeSlice(v.Type(), v.Len(), v.Cap()))
9797
// Loop over each element and call traverseFunc recursively
98-
for i := 0; i < v.Len(); i += 1 {
98+
for i := range v.Len() {
9999
if err := traverseFunc(copy.Index(i), v.Index(i)); err != nil {
100100
return err
101101
}

internal/logger/logger.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func envColor(env string, defaultColor color.Attribute) []color.Attribute {
8989
// Otherwise, split by semicolons (ANSI color codes) and use them as is.
9090
attributeStrs := strings.Split(override, ",")
9191
if len(attributeStrs) == 3 {
92-
attributeStrs = append([]string{"38", "2"}, attributeStrs...)
92+
attributeStrs = slices.Concat([]string{"38", "2"}, attributeStrs)
9393
} else {
9494
attributeStrs = strings.Split(override, ";")
9595
}

internal/slicesext/slicesext.go

-10
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,3 @@ func UniqueJoin[T cmp.Ordered](ss ...[]T) []T {
1818
slices.Sort(r)
1919
return slices.Compact(r)
2020
}
21-
22-
func FirstNonZero[T comparable](values ...T) T {
23-
var zero T
24-
for _, v := range values {
25-
if v != zero {
26-
return v
27-
}
28-
}
29-
return zero
30-
}

requires.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package task
22

33
import (
4-
"context"
5-
64
"github.com/go-task/task/v3/errors"
75
"github.com/go-task/task/v3/taskfile/ast"
86
)
97

10-
func (e *Executor) areTaskRequiredVarsSet(ctx context.Context, t *ast.Task, call *ast.Call) error {
8+
func (e *Executor) areTaskRequiredVarsSet(t *ast.Task, call *ast.Call) error {
119
if t.Requires == nil || len(t.Requires.Vars) == 0 {
1210
return nil
1311
}

setup.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"slices"
89
"strings"
910
"sync"
1011

@@ -95,7 +96,7 @@ func (e *Executor) setupFuzzyModel() {
9596
words = append(words, taskName)
9697

9798
for _, task := range e.Taskfile.Tasks.Values() {
98-
words = append(words, task.Aliases...)
99+
words = slices.Concat(words, task.Aliases)
99100
}
100101
}
101102

signals.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@ import (
88
"github.com/go-task/task/v3/internal/logger"
99
)
1010

11+
const interruptSignalsCount = 3
12+
1113
// NOTE(@andreynering): This function intercepts SIGINT and SIGTERM signals
1214
// so the Task process is not killed immediately and processes running have
1315
// time to do cleanup work.
1416
func (e *Executor) InterceptInterruptSignals() {
15-
ch := make(chan os.Signal, 3)
17+
ch := make(chan os.Signal, interruptSignalsCount)
1618
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
1719

1820
go func() {
19-
for i := 1; i <= 3; i++ {
21+
for i := range interruptSignalsCount {
2022
sig := <-ch
2123

22-
if i < 3 {
23-
e.Logger.Outf(logger.Yellow, "task: Signal received: %q\n", sig)
24-
continue
24+
if i+1 >= interruptSignalsCount {
25+
e.Logger.Errf(logger.Red, "task: Signal received for the third time: %q. Forcing shutdown\n", sig)
26+
os.Exit(1)
2527
}
2628

27-
e.Logger.Errf(logger.Red, "task: Signal received for the third time: %q. Forcing shutdown\n", sig)
28-
os.Exit(1)
29+
e.Logger.Outf(logger.Yellow, "task: Signal received: %q\n", sig)
2930
}
3031
}()
3132
}

signals_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import (
2020
"time"
2121
)
2222

23-
var (
24-
SLEEPIT, _ = filepath.Abs("./bin/sleepit")
25-
)
23+
var SLEEPIT, _ = filepath.Abs("./bin/sleepit")
2624

2725
func TestSignalSentToProcessGroup(t *testing.T) {
2826
task, err := getTaskPath()
@@ -147,7 +145,7 @@ func TestSignalSentToProcessGroup(t *testing.T) {
147145
// where the negative PID means the corresponding process group. Note that
148146
// this negative PID works only as long as the caller of the kill(2) system
149147
// call has a different PID, which is the case for this test.
150-
for i := 1; i <= tc.sendSigs; i++ {
148+
for range tc.sendSigs - 1 {
151149
if err := syscall.Kill(-sut.Process.Pid, syscall.SIGINT); err != nil {
152150
t.Fatalf("sending INT signal to the process group: %v", err)
153151
}

task.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (e *Executor) RunTask(ctx context.Context, call *ast.Call) error {
200200
return err
201201
}
202202

203-
if err := e.areTaskRequiredVarsSet(ctx, t, call); err != nil {
203+
if err := e.areTaskRequiredVarsSet(t, call); err != nil {
204204
return err
205205
}
206206

@@ -494,14 +494,12 @@ func (e *Executor) GetTaskList(filters ...FilterFunc) ([]*ast.Task, error) {
494494

495495
// Compile the list of tasks
496496
for i := range tasks {
497-
idx := i
498-
task := tasks[idx]
499497
g.Go(func() error {
500-
compiledTask, err := e.FastCompiledTask(&ast.Call{Task: task.Task})
498+
compiledTask, err := e.FastCompiledTask(&ast.Call{Task: tasks[i].Task})
501499
if err != nil {
502500
return err
503501
}
504-
tasks[idx] = compiledTask
502+
tasks[i] = compiledTask
505503
return nil
506504
})
507505
}

task_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ func TestListDescInterpolation(t *testing.T) {
825825
t.Error(err)
826826
}
827827

828-
assert.Contains(t, buff.String(), "bar")
828+
assert.Contains(t, buff.String(), "foo-var")
829+
assert.Contains(t, buff.String(), "bar-var")
829830
}
830831

831832
func TestStatusVariables(t *testing.T) {

taskfile/ast/tasks.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ast
22

33
import (
44
"fmt"
5+
"slices"
56
"strings"
67

78
"gopkg.in/yaml.v3"
@@ -111,7 +112,7 @@ func (t1 *Tasks) Merge(t2 Tasks, include *Include, includedTaskfileVars *Vars) {
111112
if t2.Get("default") != nil && t1.Get(include.Namespace) == nil {
112113
defaultTaskName := fmt.Sprintf("%s:default", include.Namespace)
113114
t1.Get(defaultTaskName).Aliases = append(t1.Get(defaultTaskName).Aliases, include.Namespace)
114-
t1.Get(defaultTaskName).Aliases = append(t1.Get(defaultTaskName).Aliases, include.Aliases...)
115+
t1.Get(defaultTaskName).Aliases = slices.Concat(t1.Get(defaultTaskName).Aliases, include.Aliases)
115116
}
116117
}
117118

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
version: '3'
22

33
vars:
4-
FOO: bar
4+
FOO: foo
5+
BAR: bar
56

67
tasks:
78
foo:
8-
desc: "task has desc with {{.FOO}} var"
9+
desc: "task has desc with {{.FOO}}-var"
10+
11+
bar:
12+
desc: "task has desc with {{.BAR}}-var"

variables.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func itemsFromFor(
266266
var keys []string // The list of keys to loop over (only if looping over a map)
267267
var values []any // The list of values to loop over
268268
// Get the list from the explicit for list
269-
if f.List != nil && len(f.List) > 0 {
269+
if len(f.List) > 0 {
270270
values = f.List
271271
}
272272
// Get the list from the task sources

0 commit comments

Comments
 (0)