diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6bff518..4c845b34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,9 @@ name: ci on: [push, pull_request] +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest @@ -10,6 +13,10 @@ jobs: matrix: go-version: - stable + - 1.25.x + - 1.24.x + - 1.23.x + - 1.22.x - 1.21.x - 1.20.x - 1.19.x @@ -20,11 +27,10 @@ jobs: - 1.14.x - 1.13.x - 1.12.x - - 1.11.x steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - name: Set up Go ${{ matrix.go-version }} - uses: actions/setup-go@v4 + uses: actions/setup-go@v6 with: go-version: ${{ matrix.go-version }} diff --git a/install_test.go b/install_test.go index 8e3cf9e7..c6f754a0 100644 --- a/install_test.go +++ b/install_test.go @@ -4,12 +4,17 @@ package main import ( - "io/ioutil" "os" "os/exec" "path/filepath" "runtime" + "strings" "testing" + + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace ioutil.TempDir with os.MkdirTemp when minimum Go version + // is raised to 1.16+. See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" ) func TestBootstrap(t *testing.T) { @@ -27,7 +32,19 @@ func TestBootstrap(t *testing.T) { if runtime.GOOS == "windows" { name += ".exe" } - if _, err := os.Stat(filepath.Join(os.Getenv("GOPATH"), "bin", name)); err != nil { + + // Use `go env GOBIN` to determine install location, as GOPATH may not be + // set in module-aware mode. Falls back to GOPATH/bin if GOBIN is empty. + binDir, err := run("go", "env", "GOBIN") + if err != nil { + t.Fatalf("failed to get GOBIN: %v", err) + } + binDir = strings.TrimSpace(binDir) + if binDir == "" { + binDir = filepath.Join(os.Getenv("GOPATH"), "bin") + } + + if _, err := os.Stat(filepath.Join(binDir, name)); err != nil { t.Fatal(err) } } diff --git a/internal/run.go b/internal/run.go index 79b4f049..94e6a907 100644 --- a/internal/run.go +++ b/internal/run.go @@ -3,12 +3,16 @@ package internal import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" "runtime" "strings" + + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace ioutil.Discard with io.Discard when minimum Go version + // is raised to 1.16+. See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" ) var debug *log.Logger = log.New(ioutil.Discard, "", 0) diff --git a/mage/main.go b/mage/main.go index 0062bd35..9fe37087 100644 --- a/mage/main.go +++ b/mage/main.go @@ -8,7 +8,6 @@ import ( "fmt" "go/build" "io" - "io/ioutil" "log" "os" "os/exec" @@ -22,6 +21,12 @@ import ( "text/template" "time" + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace ioutil.Discard with io.Discard and ioutil.ReadDir with + // os.ReadDir when minimum Go version is raised to 1.16+. + // See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" + "github.com/magefile/mage/internal" "github.com/magefile/mage/mg" "github.com/magefile/mage/parse" diff --git a/mage/main_test.go b/mage/main_test.go index 8b21fb4b..298f8b91 100644 --- a/mage/main_test.go +++ b/mage/main_test.go @@ -12,7 +12,6 @@ import ( "go/parser" "go/token" "io" - "io/ioutil" "log" "os" "os/exec" @@ -26,6 +25,12 @@ import ( "testing" "time" + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace with os.MkdirTemp, os.WriteFile, and io.Discard when + // minimum Go version is raised to 1.16+. + // See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" + "github.com/magefile/mage/internal" "github.com/magefile/mage/mg" ) diff --git a/mage/template.go b/mage/template.go index e6dc1306..3c048260 100644 --- a/mage/template.go +++ b/mage/template.go @@ -3,6 +3,11 @@ package mage // this template uses the "data" // var only for tests +// +// NOTE: This template generates code that uses io/ioutil which was deprecated +// in Go 1.16. When mage's minimum Go version is raised to 1.16+, update +// _ioutil "io/ioutil" to _io "io" and _ioutil.Discard to _io.Discard. +// See: https://go.dev/doc/go1.16#ioutil var mageMainfileTplString = `//go:build ignore // +build ignore diff --git a/mage/testdata/setdir/setdir.go b/mage/testdata/setdir/setdir.go index 9b8571d6..b5c1027e 100644 --- a/mage/testdata/setdir/setdir.go +++ b/mage/testdata/setdir/setdir.go @@ -5,8 +5,12 @@ package main import ( "fmt" - "io/ioutil" "strings" + + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace ioutil.ReadDir with os.ReadDir when minimum Go version + // is raised to 1.16+. See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" ) func TestCurrentDir() error { diff --git a/mage/testdata/setworkdir/magefile.go b/mage/testdata/setworkdir/magefile.go index d0c0ab78..7f2e1ceb 100644 --- a/mage/testdata/setworkdir/magefile.go +++ b/mage/testdata/setworkdir/magefile.go @@ -5,8 +5,12 @@ package main import ( "fmt" - "io/ioutil" "strings" + + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace ioutil.ReadDir with os.ReadDir when minimum Go version + // is raised to 1.16+. See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" ) func TestWorkingDir() error { diff --git a/parse/parse.go b/parse/parse.go index c64e7cc2..7e768815 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -7,13 +7,17 @@ import ( "go/doc" "go/parser" "go/token" - "io/ioutil" "log" "os" "sort" "strings" "time" + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace ioutil.Discard with io.Discard when minimum Go version + // is raised to 1.16+. See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" + "github.com/magefile/mage/internal" ) diff --git a/parse/testdata/subcommand_1.9.go b/parse/testdata/subcommand_1.9.go deleted file mode 100644 index ee820ae5..00000000 --- a/parse/testdata/subcommand_1.9.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build mage && go1.9 -// +build mage,go1.9 - -package main - -// this causes a panic defined in issue #126 -// Note this is only valid in go 1.9+, thus the additional build tag above. -type Foo = map[string]string diff --git a/parse/testdata/subcommands.go b/parse/testdata/subcommands.go index 502f00e2..9b06220f 100644 --- a/parse/testdata/subcommands.go +++ b/parse/testdata/subcommands.go @@ -5,6 +5,11 @@ package main import "github.com/magefile/mage/mg" +// Foo is a type alias to test that type aliases don't cause panics during +// parsing. See issue #126. Type aliases were introduced in Go 1.9, which is +// now well below the minimum supported version (1.12). +type Foo = map[string]string + type Build mg.Namespace func (Build) Foobar() error { diff --git a/sh/helpers_test.go b/sh/helpers_test.go index 54e78aa1..a56bd103 100644 --- a/sh/helpers_test.go +++ b/sh/helpers_test.go @@ -3,11 +3,16 @@ package sh_test import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "testing" + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace with os.ReadFile, os.MkdirTemp, and os.WriteFile when + // minimum Go version is raised to 1.16+. + // See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" + "github.com/magefile/mage/sh" ) diff --git a/target/newer_test.go b/target/newer_test.go index f7974371..5e58de25 100644 --- a/target/newer_test.go +++ b/target/newer_test.go @@ -1,11 +1,15 @@ package target import ( - "io/ioutil" "os" "path/filepath" "testing" "time" + + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace with os.MkdirTemp and os.WriteFile when minimum Go + // version is raised to 1.16+. See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" ) func TestNewestModTime(t *testing.T) { diff --git a/target/target_test.go b/target/target_test.go index 70f8dea9..c79fcd4a 100644 --- a/target/target_test.go +++ b/target/target_test.go @@ -1,11 +1,15 @@ package target import ( - "io/ioutil" "os" "path/filepath" "testing" "time" + + // DEPRECATED: The ioutil package was deprecated in Go 1.16. + // TODO: Replace with os.MkdirTemp and os.WriteFile when minimum Go + // version is raised to 1.16+. See: https://go.dev/doc/go1.16#ioutil + "io/ioutil" ) func TestPathMissingDest(t *testing.T) {