diff --git a/.golangci.yml b/.golangci.yml index cc3bc235ce..fec3baa882 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,11 +5,23 @@ linters: enable: + - depguard - goimports - gofmt - gofumpt + - misspell linters-settings: + depguard: + rules: + main: + files: + - "$all" + - "!$test" + - "!**/errors/*.go" + deny: + - pkg: "errors" + desc: "Use github.com/go-task/task/v3/errors instead" goimports: local-prefixes: github.com/go-task gofmt: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d0dd55229..c6eba66ac7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog -## Unreleased +## v3.40.1 - 2024-12-06 + +- Fixed a security issue in `git-urls` by switching to the maintained fork `chainguard-dev/git-urls` (#1917 by + @AlekSi). +- Added missing `platforms` property to `cmds` that use `for` (#1915 by @dkarter). +- Added misspell linter to check for misspelled English words (#1883 by @christiandins). + +## v3.40.0 - 2024-11-05 - Fixed output of some functions (e.g. `splitArgs`/`splitLines`) not working in for loops (#1822, #1823 by @stawii). @@ -9,13 +16,24 @@ #1716 by @vmaerten and @pd93). - Fixed a bug where multiple remote includes caused all prompts to display without waiting for user input (#1832, #1833 by @vmaerten and @pd93). -- When using the "[Remote Taskfiles](https://taskfile.dev/experiments/remote-taskfiles/)". - experiment, you can now include Taskfiles from Git repositories (#1652 by @vmaerten). -- Improved the error message when a dotenv file cannot be parsed (#1842 by @pbitty). +- When using the + "[Remote Taskfiles](https://taskfile.dev/experiments/remote-taskfiles/)". + experiment, you can now include Taskfiles from Git repositories (#1652 by + @vmaerten). +- Improved the error message when a dotenv file cannot be parsed (#1842 by + @pbitty). - Fix issue with directory when using the remote experiment (#1757 by @pbitty). -- Fixed an issue where a special variable was used in combination with a dotenv file (#1232, #1810 by @vmaerten). -- Refactor the way Task reads Taskfiles to improve readability (#1771 by @pbitty). -- Added a new option to ensure variable is within the list of values (#1827 by @vmaerten). +- Fixed an issue where a special variable was used in combination with a dotenv + file (#1232, #1810 by @vmaerten). +- Refactor the way Task reads Taskfiles to improve readability (#1771 by + @pbitty). +- Added a new option to ensure variable is within the list of values (#1827 by + @vmaerten). +- Allow multiple prompts to be specified for a task (#1861, #1866 by @mfbmina). +- Added new template function: `numCPU`, which returns the number of logical + CPUs usable (#1890, #1887 by @Amoghrd). +- Fixed a bug where non-nil, empty dynamic variables are returned as an empty + interface (#1903, #1904 by @pd93). ## v3.39.2 - 2024-09-19 @@ -281,7 +299,7 @@ - Added the [Remote Taskfiles experiment](https://taskfile.dev/experiments/remote-taskfiles) as a draft (#1152, #1317 by @pd93). -- Improve performance of content checksuming on `sources:` by replacing md5 with +- Improve performance of content checksumming on `sources:` by replacing md5 with [XXH3](https://xxhash.com/) which is much faster. This is a soft breaking change because checksums will be invalidated when upgrading to this release (#1325 by @ReillyBrogan). @@ -341,7 +359,7 @@ - Deprecated `version: 2` schema. This will be removed in the next major release (#1197, #1198, #1199 by @pd93). - Added a new `prompt:` prop to set a warning prompt to be shown before running - a potential dangurous task (#100, #1163 by @MaxCheetham, + a potential dangerous task (#100, #1163 by @MaxCheetham, [Documentation](https://taskfile.dev/usage/#warning-prompts)). - Added support for single command task syntax. With this change, it's now possible to declare just `cmd:` in a task, avoiding the more complex @@ -356,7 +374,7 @@ percentage (#1173 by @misitebao). - Starting on this release, official binaries for FreeBSD will be available to download (#1068 by @andreynering). -- Fix some errors being unintendedly supressed (#1134 by @clintmod). +- Fix some errors being unintendedly suppressed (#1134 by @clintmod). - Fix a nil pointer error when `version` is omitted from a Taskfile (#1148, #1149 by @pd93). - Fix duplicate error message when a task does not exists (#1141, #1144 by @@ -430,7 +448,7 @@ it a go and let us know what you think via a by @pd93). - Update to Go 1.20 (bump minimum version to 1.19) (#1010 by @pd93) - Added environment variable `FORCE_COLOR` support to force color output. - Usefull for environments without TTY (#1003 by @automation-stack) + Useful for environments without TTY (#1003 by @automation-stack) ## v3.20.0 - 2023-01-14 @@ -785,7 +803,7 @@ it a go and let us know what you think via a - Fix error code for the `--help` flag (#300, #330). - Print version to stdout instead of stderr (#299, #329). -- Supress `context` errors when using the `--watch` flag (#313, #317). +- Suppress `context` errors when using the `--watch` flag (#313, #317). - Support templating on description (#276, #283). ## v2.8.0 - 2019-12-07 @@ -794,7 +812,7 @@ it a go and let us know what you think via a parallel (#266). - Fixed bug where calling the `task` CLI only informing global vars would not execute the `default` task. -- Add hability to silent all tasks by adding `silent: true` a the root of the +- Add ability to silent all tasks by adding `silent: true` a the root of the Taskfile. ## v2.7.1 - 2019-11-10 @@ -936,7 +954,7 @@ document, since it describes in depth what changed for this version. ## v1.4.3 - 2017-09-07 - Allow assigning variables to tasks at run time via CLI (#33) -- Added suport for multiline variables from sh (#64) +- Added support for multiline variables from sh (#64) - Fixes env: remove square braces and evaluate shell (#62) - Watch: change watch library and few fixes and improvements - When use watching, cancel and restart long running process on file change (#59 @@ -996,7 +1014,7 @@ document, since it describes in depth what changed for this version. - More tests and Travis integration - Watch a task (experimental) - Possibility to call another task -- Fix "=" not being reconized in variables/environment variables +- Fix "=" not being recognized in variables/environment variables - Tasks can now have a description, and help will print them (#10) - Task dependencies now run concurrently - Support for a default task (#16) diff --git a/Taskfile.yml b/Taskfile.yml index ee30430f9b..ec13fd0cc4 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -122,7 +122,7 @@ tasks: goreleaser:install: desc: Installs goreleaser cmds: - - go install github.com/goreleaser/goreleaser@latest + - go install github.com/goreleaser/goreleaser/v2@latest release:*: desc: Prepare the project for a new release diff --git a/cmd/release/main.go b/cmd/release/main.go index efccff9e53..dfe0960a01 100644 --- a/cmd/release/main.go +++ b/cmd/release/main.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "os" "os/exec" @@ -12,6 +11,8 @@ import ( "github.com/Masterminds/semver/v3" "github.com/otiai10/copy" "github.com/spf13/pflag" + + "github.com/go-task/task/v3/errors" ) const ( diff --git a/cmd/sleepit/sleepit.go b/cmd/sleepit/sleepit.go index f9644053ec..957dd0384f 100644 --- a/cmd/sleepit/sleepit.go +++ b/cmd/sleepit/sleepit.go @@ -159,7 +159,7 @@ func worker( return workerDone } -// Do some work and then return, so that the caller can decide wether to continue or not. +// Do some work and then return, so that the caller can decide whether to continue or not. // Return true when all work is done. func doSomeWork(deadline time.Time) bool { if time.Now().After(deadline) { diff --git a/go.mod b/go.mod index b3cc9e60a8..27fa62475e 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,13 @@ go 1.22.0 require ( github.com/Ladicle/tabwriter v1.0.0 - github.com/Masterminds/semver/v3 v3.3.0 + github.com/Masterminds/semver/v3 v3.3.1 github.com/alecthomas/chroma/v2 v2.14.0 + github.com/chainguard-dev/git-urls v1.0.2 github.com/davecgh/go-spew v1.1.1 github.com/dominikbraun/graph v0.23.0 - github.com/fatih/color v1.17.0 - github.com/go-git/go-billy/v5 v5.5.0 + github.com/fatih/color v1.18.0 + github.com/go-git/go-billy/v5 v5.6.0 github.com/go-git/go-git/v5 v5.12.0 github.com/go-task/slim-sprig/v3 v3.0.0 github.com/go-task/template v0.1.0 @@ -20,11 +21,10 @@ require ( github.com/radovskyb/watcher v1.0.7 github.com/sajari/fuzzy v1.0.0 github.com/spf13/pflag v1.0.5 - github.com/stretchr/testify v1.9.0 - github.com/whilp/git-urls v1.0.0 + github.com/stretchr/testify v1.10.0 github.com/zeebo/xxh3 v1.0.2 - golang.org/x/sync v0.8.0 - golang.org/x/term v0.25.0 + golang.org/x/sync v0.9.0 + golang.org/x/term v0.26.0 gopkg.in/yaml.v3 v3.0.1 mvdan.cc/sh/v3 v3.10.0 ) @@ -34,7 +34,7 @@ require ( github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect - github.com/cyphar/filepath-securejoin v0.2.4 // indirect + github.com/cyphar/filepath-securejoin v0.2.5 // indirect github.com/dlclark/regexp2 v1.11.0 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect @@ -51,10 +51,10 @@ require ( github.com/skeema/knownhosts v1.2.2 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.25.0 // indirect golang.org/x/mod v0.18.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/sys v0.26.0 // indirect + golang.org/x/net v0.27.0 // indirect + golang.org/x/sys v0.27.0 // indirect golang.org/x/tools v0.22.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum index 8e76207d71..8ec7b4feee 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/Ladicle/tabwriter v1.0.0 h1:DZQqPvMumBDwVNElso13afjYLNp0Z7pHqHnu0r4t9Dg= github.com/Ladicle/tabwriter v1.0.0/go.mod h1:c4MdCjxQyTbGuQO/gvqJ+IA/89UEwrsD6hUCW98dyp4= -github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= -github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= +github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4= +github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= @@ -20,13 +20,15 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuW github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/chainguard-dev/git-urls v1.0.2 h1:pSpT7ifrpc5X55n4aTTm7FFUE+ZQHKiqpiwNkJrVcKQ= +github.com/chainguard-dev/git-urls v1.0.2/go.mod h1:rbGgj10OS7UgZlbzdUQIQpT0k/D4+An04HJY7Ol+Y/o= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= -github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= -github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= -github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= -github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/creack/pty v1.1.23 h1:4M6+isWdcStXEf15G/RbrMPOQj1dZ7HPZCGwE4kOeP0= +github.com/creack/pty v1.1.23/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= +github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo= +github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -38,14 +40,14 @@ github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcej github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= -github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= -github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= -github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-billy/v5 v5.6.0 h1:w2hPNtoehvJIxR00Vb4xX94qHQi/ApZfX+nBE2Cjio8= +github.com/go-git/go-billy/v5 v5.6.0/go.mod h1:sFDq7xD3fn3E0GOwUSZqHo9lrkmx8xJhA0ZrfvjBRGM= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= @@ -88,8 +90,8 @@ github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4 github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= +github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks= @@ -102,8 +104,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/radovskyb/watcher v1.0.7 h1:AYePLih6dpmS32vlHfhCeli8127LzkIgwJGcwwe8tUE= github.com/radovskyb/watcher v1.0.7/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= +github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= github.com/sajari/fuzzy v1.0.0 h1:+FmwVvJErsd0d0hAPlj4CxqxUtQY/fOoY0DwX4ykpRY= github.com/sajari/fuzzy v1.0.0/go.mod h1:OjYR6KxoWOe9+dOlXeiCJd4dIbED4Oo8wpS89o0pwOo= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= @@ -118,10 +120,8 @@ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/whilp/git-urls v1.0.0 h1:95f6UMWN5FKW71ECsXRUd3FVYiXdrE7aX4NZKcPmIjU= -github.com/whilp/git-urls v1.0.0/go.mod h1:J16SAmobsqc3Qcy98brfl5f5+e0clUvg1krgwk/qCfE= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -134,14 +134,12 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -151,15 +149,13 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -174,15 +170,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= -golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= +golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= +golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -190,14 +186,12 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= -golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -211,7 +205,5 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -mvdan.cc/sh/v3 v3.9.0 h1:it14fyjCdQUk4jf/aYxLO3FG8jFarR9GzMCtnlvvD7c= -mvdan.cc/sh/v3 v3.9.0/go.mod h1:cdBk8bgoiBI7lSZqK5JhUuq7OB64VQ7fgm85xelw3Nk= mvdan.cc/sh/v3 v3.10.0 h1:v9z7N1DLZ7owyLM/SXZQkBSXcwr2IGMm2LY2pmhVXj4= mvdan.cc/sh/v3 v3.10.0/go.mod h1:z/mSSVyLFGZzqb3ZIKojjyqIx/xbmz/UHdCSv9HmqXY= diff --git a/internal/compiler/compiler.go b/internal/compiler/compiler.go index 67ea07e456..f6a9f1a53a 100644 --- a/internal/compiler/compiler.go +++ b/internal/compiler/compiler.go @@ -74,8 +74,8 @@ func (c *Compiler) getVariables(t *ast.Task, call *ast.Call, evaluateShVars bool if err := cache.Err(); err != nil { return err } - // If the variable is not dynamic, we can set it and return - if newVar.Value != nil || newVar.Sh == "" { + // If the variable is already set, we can set it and return + if newVar.Value != nil { result.Set(k, ast.Var{Value: newVar.Value}) return nil } @@ -136,10 +136,15 @@ func (c *Compiler) HandleDynamicVar(v ast.Var, dir string) (string, error) { c.muDynamicCache.Lock() defer c.muDynamicCache.Unlock() + // If the variable is not dynamic or it is empty, return an empty string + if v.Sh == nil || *v.Sh == "" { + return "", nil + } + if c.dynamicCache == nil { c.dynamicCache = make(map[string]string, 30) } - if result, ok := c.dynamicCache[v.Sh]; ok { + if result, ok := c.dynamicCache[*v.Sh]; ok { return result, nil } @@ -150,7 +155,7 @@ func (c *Compiler) HandleDynamicVar(v ast.Var, dir string) (string, error) { var stdout bytes.Buffer opts := &execext.RunCommandOptions{ - Command: v.Sh, + Command: *v.Sh, Dir: dir, Stdout: &stdout, Stderr: c.Logger.Stderr, @@ -164,13 +169,13 @@ func (c *Compiler) HandleDynamicVar(v ast.Var, dir string) (string, error) { result := strings.TrimSuffix(stdout.String(), "\r\n") result = strings.TrimSuffix(result, "\n") - c.dynamicCache[v.Sh] = result + c.dynamicCache[*v.Sh] = result c.Logger.VerboseErrf(logger.Magenta, "task: dynamic variable: %q result: %q\n", v.Sh, result) return result, nil } -// ResetCache clear the dymanic variables cache +// ResetCache clear the dynamic variables cache func (c *Compiler) ResetCache() { c.muDynamicCache.Lock() defer c.muDynamicCache.Unlock() diff --git a/internal/execext/exec.go b/internal/execext/exec.go index 69ab8865f3..1de964e76d 100644 --- a/internal/execext/exec.go +++ b/internal/execext/exec.go @@ -2,7 +2,6 @@ package execext import ( "context" - "errors" "fmt" "io" "os" @@ -14,6 +13,8 @@ import ( "mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/shell" "mvdan.cc/sh/v3/syntax" + + "github.com/go-task/task/v3/errors" ) // RunCommandOptions is the options for the RunCommand func diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 8ce7783504..58762c405d 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -2,7 +2,6 @@ package flags import ( "cmp" - "errors" "log" "os" "strconv" @@ -10,6 +9,7 @@ import ( "github.com/spf13/pflag" + "github.com/go-task/task/v3/errors" "github.com/go-task/task/v3/internal/experiments" "github.com/go-task/task/v3/taskfile/ast" ) @@ -109,7 +109,7 @@ func init() { pflag.StringVar(&Output.Group.End, "output-group-end", "", "Message template to print after a task's grouped output.") pflag.BoolVar(&Output.Group.ErrorOnly, "output-group-error-only", false, "Swallow output from successful tasks.") pflag.BoolVarP(&Color, "color", "c", true, "Colored output. Enabled by default. Set flag to false or use NO_COLOR=1 to disable.") - pflag.IntVarP(&Concurrency, "concurrency", "C", 0, "Limit number tasks to run concurrently.") + pflag.IntVarP(&Concurrency, "concurrency", "C", 0, "Limit number of tasks to run concurrently.") pflag.DurationVarP(&Interval, "interval", "I", 0, "Interval to watch for changes.") pflag.BoolVarP(&Global, "global", "g", false, "Runs global Taskfile, from $HOME/{T,t}askfile.{yml,yaml}.") pflag.BoolVar(&Experiments, "experiments", false, "Lists all the available experiments and whether or not they are enabled.") diff --git a/internal/templater/funcs.go b/internal/templater/funcs.go index 1d9d9068c1..79c837a3c3 100644 --- a/internal/templater/funcs.go +++ b/internal/templater/funcs.go @@ -17,8 +17,9 @@ var templateFuncs template.FuncMap func init() { taskFuncs := template.FuncMap{ - "OS": func() string { return runtime.GOOS }, - "ARCH": func() string { return runtime.GOARCH }, + "OS": func() string { return runtime.GOOS }, + "ARCH": func() string { return runtime.GOARCH }, + "numCPU": func() int { return runtime.NumCPU() }, "catLines": func(s string) string { s = strings.ReplaceAll(s, "\r\n", " ") return strings.ReplaceAll(s, "\n", " ") diff --git a/package-lock.json b/package-lock.json index 9d7efe1a52..b0fe77bcce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@go-task/cli", - "version": "3.39.2", + "version": "3.40.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 00f849e7a4..54263e8cdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@go-task/cli", - "version": "3.39.2", + "version": "3.40.1", "description": "A task runner / simpler Make alternative written in Go", "scripts": { "postinstall": "go-npm install", diff --git a/precondition.go b/precondition.go index 3ae9ad0466..1f25bd37f5 100644 --- a/precondition.go +++ b/precondition.go @@ -2,8 +2,8 @@ package task import ( "context" - "errors" + "github.com/go-task/task/v3/errors" "github.com/go-task/task/v3/internal/env" "github.com/go-task/task/v3/internal/execext" "github.com/go-task/task/v3/internal/logger" diff --git a/task.go b/task.go index 5c63de346b..b183014271 100644 --- a/task.go +++ b/task.go @@ -235,13 +235,15 @@ func (e *Executor) RunTask(ctx context.Context, call *ast.Call) error { } } - if t.Prompt != "" && !e.Dry { - if err := e.Logger.Prompt(logger.Yellow, t.Prompt, "n", "y", "yes"); errors.Is(err, logger.ErrNoTerminal) { - return &errors.TaskCancelledNoTerminalError{TaskName: call.Task} - } else if errors.Is(err, logger.ErrPromptCancelled) { - return &errors.TaskCancelledByUserError{TaskName: call.Task} - } else if err != nil { - return err + for _, p := range t.Prompt { + if p != "" && !e.Dry { + if err := e.Logger.Prompt(logger.Yellow, p, "n", "y", "yes"); errors.Is(err, logger.ErrNoTerminal) { + return &errors.TaskCancelledNoTerminalError{TaskName: call.Task} + } else if errors.Is(err, logger.ErrPromptCancelled) { + return &errors.TaskCancelledByUserError{TaskName: call.Task} + } else if err != nil { + return err + } } } diff --git a/task_test.go b/task_test.go index 599277c8c5..afb40fa19d 100644 --- a/task_test.go +++ b/task_test.go @@ -120,10 +120,10 @@ func TestEnv(t *testing.T) { Target: "default", TrimSpace: false, Files: map[string]string{ - "local.txt": "GOOS='linux' GOARCH='amd64' CGO_ENABLED='0'\n", - "global.txt": "FOO='foo' BAR='overriden' BAZ='baz'\n", - "multiple_type.txt": "FOO='1' BAR='true' BAZ='1.1'\n", - "not-overriden.txt": "QUX='from_os'\n", + "local.txt": "GOOS='linux' GOARCH='amd64' CGO_ENABLED='0'\n", + "global.txt": "FOO='foo' BAR='overridden' BAZ='baz'\n", + "multiple_type.txt": "FOO='1' BAR='true' BAZ='1.1'\n", + "not-overridden.txt": "QUX='from_os'\n", }, } tt.Run(t) @@ -131,10 +131,10 @@ func TestEnv(t *testing.T) { experiments.EnvPrecedence = experiments.New("ENV_PRECEDENCE") ttt := fileContentTest{ Dir: "testdata/env", - Target: "overriden", + Target: "overridden", TrimSpace: false, Files: map[string]string{ - "overriden.txt": "QUX='from_taskfile'\n", + "overridden.txt": "QUX='from_taskfile'\n", }, } ttt.Run(t) diff --git a/taskfile/ast/prompt.go b/taskfile/ast/prompt.go new file mode 100644 index 0000000000..073ec05e80 --- /dev/null +++ b/taskfile/ast/prompt.go @@ -0,0 +1,29 @@ +package ast + +import ( + "gopkg.in/yaml.v3" + + "github.com/go-task/task/v3/errors" +) + +type Prompt []string + +func (p *Prompt) UnmarshalYAML(node *yaml.Node) error { + switch node.Kind { + case yaml.ScalarNode: + var str string + if err := node.Decode(&str); err != nil { + return errors.NewTaskfileDecodeError(err, node) + } + *p = []string{str} + return nil + case yaml.SequenceNode: + var list []string + if err := node.Decode(&list); err != nil { + return errors.NewTaskfileDecodeError(err, node) + } + *p = list + return nil + } + return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("prompt") +} diff --git a/taskfile/ast/task.go b/taskfile/ast/task.go index de6986c6b8..17fa976ae5 100644 --- a/taskfile/ast/task.go +++ b/taskfile/ast/task.go @@ -18,7 +18,7 @@ type Task struct { Deps []*Dep Label string Desc string - Prompt string + Prompt Prompt Summary string Requires *Requires Aliases []string @@ -115,7 +115,7 @@ func (t *Task) UnmarshalYAML(node *yaml.Node) error { Deps []*Dep Label string Desc string - Prompt string + Prompt Prompt Summary string Aliases []string Sources []*Glob diff --git a/taskfile/ast/var.go b/taskfile/ast/var.go index dce6288452..88d407943e 100644 --- a/taskfile/ast/var.go +++ b/taskfile/ast/var.go @@ -20,7 +20,7 @@ type Vars struct { func (vs *Vars) ToCacheMap() (m map[string]any) { m = make(map[string]any, vs.Len()) _ = vs.Range(func(k string, v Var) error { - if v.Sh != "" { + if v.Sh != nil && *v.Sh != "" { // Dynamic variable is not yet resolved; trigger // to be used in templates. return nil @@ -81,7 +81,7 @@ func (vs *Vars) DeepCopy() *Vars { type Var struct { Value any Live any - Sh string + Sh *string Ref string Dir string } @@ -98,7 +98,7 @@ func (v *Var) UnmarshalYAML(node *yaml.Node) error { // If the value is a string and it starts with $, then it's a shell command if str, ok := value.(string); ok { if str, ok = strings.CutPrefix(str, "$"); ok { - v.Sh = str + v.Sh = &str return nil } if str, ok = strings.CutPrefix(str, "#"); ok { @@ -118,7 +118,7 @@ func (v *Var) UnmarshalYAML(node *yaml.Node) error { switch key { case "sh", "ref", "map": var m struct { - Sh string + Sh *string Ref string Map any } @@ -150,7 +150,7 @@ func (v *Var) UnmarshalYAML(node *yaml.Node) error { switch key { case "sh", "ref": var m struct { - Sh string + Sh *string Ref string } if err := node.Decode(&m); err != nil { diff --git a/taskfile/node.go b/taskfile/node.go index 8f09bc5e1d..74b3245eaf 100644 --- a/taskfile/node.go +++ b/taskfile/node.go @@ -7,7 +7,7 @@ import ( "strings" "time" - giturls "github.com/whilp/git-urls" + giturls "github.com/chainguard-dev/git-urls" "github.com/go-task/task/v3/errors" "github.com/go-task/task/v3/internal/experiments" diff --git a/taskfile/node_git.go b/taskfile/node_git.go index 26d287a129..557986d541 100644 --- a/taskfile/node_git.go +++ b/taskfile/node_git.go @@ -8,11 +8,11 @@ import ( "path/filepath" "strings" + giturls "github.com/chainguard-dev/git-urls" "github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/storage/memory" - giturls "github.com/whilp/git-urls" "github.com/go-task/task/v3/errors" "github.com/go-task/task/v3/internal/execext" diff --git a/testdata/env/Taskfile.yml b/testdata/env/Taskfile.yml index d2b802fc2d..aa213201d9 100644 --- a/testdata/env/Taskfile.yml +++ b/testdata/env/Taskfile.yml @@ -15,7 +15,7 @@ tasks: cmds: - task: local - task: global - - task: not-overriden + - task: not-overridden - task: multiple_type local: @@ -31,7 +31,7 @@ tasks: global: env: - BAR: overriden + BAR: overridden cmds: - echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'" > global.txt @@ -43,10 +43,10 @@ tasks: cmds: - echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'" > multiple_type.txt - not-overriden: + not-overridden: cmds: - - echo "QUX='$QUX'" > not-overriden.txt + - echo "QUX='$QUX'" > not-overridden.txt - overriden: + overridden: cmds: - - echo "QUX='$QUX'" > overriden.txt + - echo "QUX='$QUX'" > overridden.txt diff --git a/testdata/exit_immediately/Taskfile.yml b/testdata/exit_immediately/Taskfile.yml index 247165c9fb..bf6fcf772d 100644 --- a/testdata/exit_immediately/Taskfile.yml +++ b/testdata/exit_immediately/Taskfile.yml @@ -3,4 +3,4 @@ version: '3' tasks: default: | this_should_fail - echo "This shoudn't be print" + echo "This shouldn't be print" diff --git a/testdata/prompt/Taskfile.yml b/testdata/prompt/Taskfile.yml index 4fdd4dde65..806e1233c8 100644 --- a/testdata/prompt/Taskfile.yml +++ b/testdata/prompt/Taskfile.yml @@ -14,3 +14,10 @@ tasks: prompt: Do you want to continue? cmds: - echo 'show-prompt' + + multi-prompt: + prompt: + - Do you want to continue? + - Are you sure? + cmds: + - echo 'multi-prompt' diff --git a/testdata/summary/Taskfile.yml b/testdata/summary/Taskfile.yml index 7b857f76b0..8833502cb1 100644 --- a/testdata/summary/Taskfile.yml +++ b/testdata/summary/Taskfile.yml @@ -2,7 +2,7 @@ version: '3' tasks: task-with-summary: - deps: [dependend-task-1, dependend-task-2] + deps: [dependent-task-1, dependent-task-2] summary: | summary of task-with-summary - line 1 line 2 @@ -17,10 +17,10 @@ tasks: cmds: - echo 'other-task-with-summary was executed' - dependend-task-1: + dependent-task-1: cmds: - - echo 'dependend-task-1 was executed' + - echo 'dependent-task-1 was executed' - dependend-task-2: + dependent-task-2: cmds: - - echo 'dependend-task-2 was executed' + - echo 'dependent-task-2 was executed' diff --git a/testdata/summary/task-with-summary.txt b/testdata/summary/task-with-summary.txt index 8071130028..3e2eba73c5 100644 --- a/testdata/summary/task-with-summary.txt +++ b/testdata/summary/task-with-summary.txt @@ -5,8 +5,8 @@ line 2 line 3 dependencies: - - dependend-task-1 - - dependend-task-2 + - dependent-task-1 + - dependent-task-2 commands: - echo 'task-with-summary was executed' diff --git a/variables.go b/variables.go index 6dac3a6c3e..67703e810b 100644 --- a/variables.go +++ b/variables.go @@ -112,7 +112,7 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task, if evaluateShVars { err = new.Env.Range(func(k string, v ast.Var) error { // If the variable is not dynamic, we can set it and return - if v.Value != nil || v.Sh == "" { + if v.Value != nil || v.Sh == nil { new.Env.Set(k, ast.Var{Value: v.Value}) return nil } @@ -301,7 +301,7 @@ func itemsFromFor( // If the variable is dynamic, then it hasn't been resolved yet // and we can't use it as a list. This happens when fast compiling a task // for use in --list or --list-all etc. - if v.Value != nil && v.Sh == "" { + if v.Value != nil && v.Sh == nil { switch value := v.Value.(type) { case string: if f.Split != "" { diff --git a/website/docs/changelog.mdx b/website/docs/changelog.mdx index 368437c853..7f17d975d4 100644 --- a/website/docs/changelog.mdx +++ b/website/docs/changelog.mdx @@ -5,6 +5,41 @@ sidebar_position: 14 # Changelog +## v3.40.1 - 2024-12-06 + +- Fixed a security issue in `git-urls` by switching to the maintained fork `chainguard-dev/git-urls` (#1917 by + @AlekSi). +- Added missing `platforms` property to `cmds` that use `for` (#1915 by @dkarter). +- Added misspell linter to check for misspelled English words (#1883 by @christiandins). + +## v3.40.0 - 2024-11-05 + +- Fixed output of some functions (e.g. `splitArgs`/`splitLines`) not working in + for loops (#1822, #1823 by @stawii). +- Added a new `TASK_OFFLINE` environment variable to configure the `--offline` + flag and expose it as a special variable in the templating system (#1470, + #1716 by @vmaerten and @pd93). +- Fixed a bug where multiple remote includes caused all prompts to display + without waiting for user input (#1832, #1833 by @vmaerten and @pd93). +- When using the + "[Remote Taskfiles](https://taskfile.dev/experiments/remote-taskfiles/)". + experiment, you can now include Taskfiles from Git repositories (#1652 by + @vmaerten). +- Improved the error message when a dotenv file cannot be parsed (#1842 by + @pbitty). +- Fix issue with directory when using the remote experiment (#1757 by @pbitty). +- Fixed an issue where a special variable was used in combination with a dotenv + file (#1232, #1810 by @vmaerten). +- Refactor the way Task reads Taskfiles to improve readability (#1771 by + @pbitty). +- Added a new option to ensure variable is within the list of values (#1827 by + @vmaerten). +- Allow multiple prompts to be specified for a task (#1861, #1866 by @mfbmina). +- Added new template function: `numCPU`, which returns the number of logical + CPUs usable (#1890, #1887 by @Amoghrd). +- Fixed a bug where non-nil, empty dynamic variables are returned as an empty + interface (#1903, #1904 by @pd93). + ## v3.39.2 - 2024-09-19 - Fix dynamic variables not working properly for a defer: statement (#1803, @@ -269,7 +304,7 @@ sidebar_position: 14 - Added the [Remote Taskfiles experiment](https://taskfile.dev/experiments/remote-taskfiles) as a draft (#1152, #1317 by @pd93). -- Improve performance of content checksuming on `sources:` by replacing md5 with +- Improve performance of content checksumming on `sources:` by replacing md5 with [XXH3](https://xxhash.com/) which is much faster. This is a soft breaking change because checksums will be invalidated when upgrading to this release (#1325 by @ReillyBrogan). @@ -329,7 +364,7 @@ sidebar_position: 14 - Deprecated `version: 2` schema. This will be removed in the next major release (#1197, #1198, #1199 by @pd93). - Added a new `prompt:` prop to set a warning prompt to be shown before running - a potential dangurous task (#100, #1163 by @MaxCheetham, + a potential dangerous task (#100, #1163 by @MaxCheetham, [Documentation](https://taskfile.dev/usage/#warning-prompts)). - Added support for single command task syntax. With this change, it's now possible to declare just `cmd:` in a task, avoiding the more complex @@ -344,7 +379,7 @@ sidebar_position: 14 percentage (#1173 by @misitebao). - Starting on this release, official binaries for FreeBSD will be available to download (#1068 by @andreynering). -- Fix some errors being unintendedly supressed (#1134 by @clintmod). +- Fix some errors being unintendedly suppressed (#1134 by @clintmod). - Fix a nil pointer error when `version` is omitted from a Taskfile (#1148, #1149 by @pd93). - Fix duplicate error message when a task does not exists (#1141, #1144 by @@ -418,7 +453,7 @@ it a go and let us know what you think via a by @pd93). - Update to Go 1.20 (bump minimum version to 1.19) (#1010 by @pd93) - Added environment variable `FORCE_COLOR` support to force color output. - Usefull for environments without TTY (#1003 by @automation-stack) + Useful for environments without TTY (#1003 by @automation-stack) ## v3.20.0 - 2023-01-14 @@ -773,7 +808,7 @@ it a go and let us know what you think via a - Fix error code for the `--help` flag (#300, #330). - Print version to stdout instead of stderr (#299, #329). -- Supress `context` errors when using the `--watch` flag (#313, #317). +- Suppress `context` errors when using the `--watch` flag (#313, #317). - Support templating on description (#276, #283). ## v2.8.0 - 2019-12-07 @@ -782,7 +817,7 @@ it a go and let us know what you think via a parallel (#266). - Fixed bug where calling the `task` CLI only informing global vars would not execute the `default` task. -- Add hability to silent all tasks by adding `silent: true` a the root of the +- Add ability to silent all tasks by adding `silent: true` a the root of the Taskfile. ## v2.7.1 - 2019-11-10 @@ -924,7 +959,7 @@ document, since it describes in depth what changed for this version. ## v1.4.3 - 2017-09-07 - Allow assigning variables to tasks at run time via CLI (#33) -- Added suport for multiline variables from sh (#64) +- Added support for multiline variables from sh (#64) - Fixes env: remove square braces and evaluate shell (#62) - Watch: change watch library and few fixes and improvements - When use watching, cancel and restart long running process on file change (#59 @@ -984,7 +1019,7 @@ document, since it describes in depth what changed for this version. - More tests and Travis integration - Watch a task (experimental) - Possibility to call another task -- Fix "=" not being reconized in variables/environment variables +- Fix "=" not being recognized in variables/environment variables - Tasks can now have a description, and help will print them (#10) - Task dependencies now run concurrently - Support for a default task (#16) diff --git a/website/docs/reference/schema.mdx b/website/docs/reference/schema.mdx index e67a033c23..7066f54504 100644 --- a/website/docs/reference/schema.mdx +++ b/website/docs/reference/schema.mdx @@ -88,7 +88,7 @@ vars: | `deps` | [`[]Dependency`](#dependency) | | A list of dependencies of this task. Tasks defined here will run in parallel before this task. | | `label` | `string` | | Overrides the name of the task in the output when a task is run. Supports variables. | | `desc` | `string` | | A short description of the task. This is displayed when calling `task --list`. | -| `prompt` | `string` | | A prompt that will be presented before a task is run. Declining will cancel running the current and any subsequent tasks. | +| `prompt` | `[]string` | | One or more prompts that will be presented before a task is run. Declining will cancel running the current and any subsequent tasks. | | `summary` | `string` | | A longer description of the task. This is displayed when calling `task --summary [task]`. | | `aliases` | `[]string` | | A list of alternative names by which the task can be called. | | `sources` | `[]string` | | A list of sources to check before running this task. Relevant for `checksum` and `timestamp` methods. Can be file paths or star globs. | diff --git a/website/docs/reference/templating.mdx b/website/docs/reference/templating.mdx index 6c9f738f4a..468a4333b3 100644 --- a/website/docs/reference/templating.mdx +++ b/website/docs/reference/templating.mdx @@ -374,7 +374,8 @@ Lastly, Task itself provides a few functions: | Function | Description | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `OS` | Returns the operating system. Possible values are `windows`, `linux`, `darwin` (macOS) and `freebsd`. | -| `ARCH` | return the architecture Task was compiled to: `386`, `amd64`, `arm` or `s390x`. | +| `ARCH` | Returns the architecture Task was compiled to: `386`, `amd64`, `arm` or `s390x`. | +| `numCPU` | Returns the number of logical CPU's usable by the current process. | | `splitLines` | Splits Unix (`\n`) and Windows (`\r\n`) styled newlines. | | `catLines` | Replaces Unix (`\n`) and Windows (`\r\n`) styled newlines with a space. | | `toSlash` | Does nothing on Unix, but on Windows converts a string from `\` path format to `/`. | diff --git a/website/docs/usage.mdx b/website/docs/usage.mdx index 0cb12c246f..2f5baa4773 100644 --- a/website/docs/usage.mdx +++ b/website/docs/usage.mdx @@ -1212,6 +1212,28 @@ tasks: - echo "{{.GREETING}}" ``` +Example of a `default` value to be overridden from CLI: + +```yaml +version: '3' + + greet_user: + desc: "Greet the user with a name." + vars: + USER_NAME: '{{.USER_NAME| default "DefaultUser"}}' + cmds: + - echo "Hello, {{.USER_NAME}}!" +``` + +```shell +$ task greet_user +task: [greet_user] echo "Hello, DefaultUser!" +Hello, DefaultUser! +$ task greet_user USER_NAME="Bob" +task: [greet_user] echo "Hello, Bob!" +Hello, Bob! +``` + ### Dynamic variables The below syntax (`sh:` prop in a variable) is considered a dynamic variable. @@ -1878,6 +1900,24 @@ tasks: task: "This is a dangerous command... Do you want to continue?" [y/N] ``` +Prompts can be a single value or a list of prompts, like below: + +```yaml +version: '3' + +tasks: + example: + cmds: + - task: dangerous + + dangerous: + prompt: + - This is a dangerous command... Do you want to continue? + - Are you sure? + cmds: + - echo 'dangerous command' +``` + Warning prompts are called before executing a task. If a prompt is denied Task will exit with [exit code](/api#exit-codes) 205. If approved, Task will continue as normal. diff --git a/website/static/schema.json b/website/static/schema.json index b2b2d875aa..9389d04c50 100644 --- a/website/static/schema.json +++ b/website/static/schema.json @@ -6,6 +6,12 @@ "env": { "$ref": "#/definitions/vars" }, + "platforms": { + "type": "array", + "items": { + "type": "string" + } + }, "tasks": { "type": "object", "patternProperties": { @@ -59,8 +65,18 @@ "type": "string" }, "prompt": { - "description": "A prompt that will be presented before a task is run. Declining will cancel running the current and any subsequent tasks.", - "type": "string" + "description": "One or more prompts that will be presented before a task is run. Declining will cancel running the current and any subsequent tasks.", + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] }, "summary": { "description": "A longer description of the task. This is displayed when calling `task --summary [task]`.", @@ -169,10 +185,7 @@ }, "platforms": { "description": "Specifies which platforms the task should be run on.", - "type": "array", - "items": { - "type": "string" - } + "$ref": "#/definitions/platforms" }, "requires": { "description": "A list of variables which should be set if this task is to run, if any of these variables are unset the task will error and not run", @@ -331,10 +344,7 @@ }, "platforms": { "description": "Specifies which platforms the command should be run on.", - "type": "array", - "items": { - "type": "string" - } + "$ref": "#/definitions/platforms" } }, "additionalProperties": false, @@ -386,6 +396,10 @@ "vars": { "description": "Values passed to the task called", "$ref": "#/definitions/vars" + }, + "platforms": { + "description": "Specifies which platforms the command should be run on.", + "$ref": "#/definitions/platforms" } }, "oneOf": [ diff --git a/website/versioned_docs/version-latest/changelog.mdx b/website/versioned_docs/version-latest/changelog.mdx index 368437c853..7f17d975d4 100644 --- a/website/versioned_docs/version-latest/changelog.mdx +++ b/website/versioned_docs/version-latest/changelog.mdx @@ -5,6 +5,41 @@ sidebar_position: 14 # Changelog +## v3.40.1 - 2024-12-06 + +- Fixed a security issue in `git-urls` by switching to the maintained fork `chainguard-dev/git-urls` (#1917 by + @AlekSi). +- Added missing `platforms` property to `cmds` that use `for` (#1915 by @dkarter). +- Added misspell linter to check for misspelled English words (#1883 by @christiandins). + +## v3.40.0 - 2024-11-05 + +- Fixed output of some functions (e.g. `splitArgs`/`splitLines`) not working in + for loops (#1822, #1823 by @stawii). +- Added a new `TASK_OFFLINE` environment variable to configure the `--offline` + flag and expose it as a special variable in the templating system (#1470, + #1716 by @vmaerten and @pd93). +- Fixed a bug where multiple remote includes caused all prompts to display + without waiting for user input (#1832, #1833 by @vmaerten and @pd93). +- When using the + "[Remote Taskfiles](https://taskfile.dev/experiments/remote-taskfiles/)". + experiment, you can now include Taskfiles from Git repositories (#1652 by + @vmaerten). +- Improved the error message when a dotenv file cannot be parsed (#1842 by + @pbitty). +- Fix issue with directory when using the remote experiment (#1757 by @pbitty). +- Fixed an issue where a special variable was used in combination with a dotenv + file (#1232, #1810 by @vmaerten). +- Refactor the way Task reads Taskfiles to improve readability (#1771 by + @pbitty). +- Added a new option to ensure variable is within the list of values (#1827 by + @vmaerten). +- Allow multiple prompts to be specified for a task (#1861, #1866 by @mfbmina). +- Added new template function: `numCPU`, which returns the number of logical + CPUs usable (#1890, #1887 by @Amoghrd). +- Fixed a bug where non-nil, empty dynamic variables are returned as an empty + interface (#1903, #1904 by @pd93). + ## v3.39.2 - 2024-09-19 - Fix dynamic variables not working properly for a defer: statement (#1803, @@ -269,7 +304,7 @@ sidebar_position: 14 - Added the [Remote Taskfiles experiment](https://taskfile.dev/experiments/remote-taskfiles) as a draft (#1152, #1317 by @pd93). -- Improve performance of content checksuming on `sources:` by replacing md5 with +- Improve performance of content checksumming on `sources:` by replacing md5 with [XXH3](https://xxhash.com/) which is much faster. This is a soft breaking change because checksums will be invalidated when upgrading to this release (#1325 by @ReillyBrogan). @@ -329,7 +364,7 @@ sidebar_position: 14 - Deprecated `version: 2` schema. This will be removed in the next major release (#1197, #1198, #1199 by @pd93). - Added a new `prompt:` prop to set a warning prompt to be shown before running - a potential dangurous task (#100, #1163 by @MaxCheetham, + a potential dangerous task (#100, #1163 by @MaxCheetham, [Documentation](https://taskfile.dev/usage/#warning-prompts)). - Added support for single command task syntax. With this change, it's now possible to declare just `cmd:` in a task, avoiding the more complex @@ -344,7 +379,7 @@ sidebar_position: 14 percentage (#1173 by @misitebao). - Starting on this release, official binaries for FreeBSD will be available to download (#1068 by @andreynering). -- Fix some errors being unintendedly supressed (#1134 by @clintmod). +- Fix some errors being unintendedly suppressed (#1134 by @clintmod). - Fix a nil pointer error when `version` is omitted from a Taskfile (#1148, #1149 by @pd93). - Fix duplicate error message when a task does not exists (#1141, #1144 by @@ -418,7 +453,7 @@ it a go and let us know what you think via a by @pd93). - Update to Go 1.20 (bump minimum version to 1.19) (#1010 by @pd93) - Added environment variable `FORCE_COLOR` support to force color output. - Usefull for environments without TTY (#1003 by @automation-stack) + Useful for environments without TTY (#1003 by @automation-stack) ## v3.20.0 - 2023-01-14 @@ -773,7 +808,7 @@ it a go and let us know what you think via a - Fix error code for the `--help` flag (#300, #330). - Print version to stdout instead of stderr (#299, #329). -- Supress `context` errors when using the `--watch` flag (#313, #317). +- Suppress `context` errors when using the `--watch` flag (#313, #317). - Support templating on description (#276, #283). ## v2.8.0 - 2019-12-07 @@ -782,7 +817,7 @@ it a go and let us know what you think via a parallel (#266). - Fixed bug where calling the `task` CLI only informing global vars would not execute the `default` task. -- Add hability to silent all tasks by adding `silent: true` a the root of the +- Add ability to silent all tasks by adding `silent: true` a the root of the Taskfile. ## v2.7.1 - 2019-11-10 @@ -924,7 +959,7 @@ document, since it describes in depth what changed for this version. ## v1.4.3 - 2017-09-07 - Allow assigning variables to tasks at run time via CLI (#33) -- Added suport for multiline variables from sh (#64) +- Added support for multiline variables from sh (#64) - Fixes env: remove square braces and evaluate shell (#62) - Watch: change watch library and few fixes and improvements - When use watching, cancel and restart long running process on file change (#59 @@ -984,7 +1019,7 @@ document, since it describes in depth what changed for this version. - More tests and Travis integration - Watch a task (experimental) - Possibility to call another task -- Fix "=" not being reconized in variables/environment variables +- Fix "=" not being recognized in variables/environment variables - Tasks can now have a description, and help will print them (#10) - Task dependencies now run concurrently - Support for a default task (#16) diff --git a/website/versioned_docs/version-latest/experiments/remote_taskfiles.mdx b/website/versioned_docs/version-latest/experiments/remote_taskfiles.mdx index 8a85ccd0b6..45e6617edf 100644 --- a/website/versioned_docs/version-latest/experiments/remote_taskfiles.mdx +++ b/website/versioned_docs/version-latest/experiments/remote_taskfiles.mdx @@ -62,6 +62,16 @@ includes: `TOKEN=my-token task my-remote-namespace:hello` will be resolved by Task to `https://my-token@raw.githubusercontent.com/my-org/my-repo/main/Taskfile.yml` +## Git nodes + +You can also include a Taskfile from a Git node. We currently support ssh-style and http / https addresses like `git@example.com/foo/bar.git//Taskfiles.yml?ref=v1` and `https://example.com/foo/bar.git//Taskfiles.yml?ref=v1`. + +You need to follow this pattern : `.git//?ref=`. +The `ref` parameter, optional, can be a branch name or a tag, if not provided it'll pick up the default branch. +The `path` is the path to the Taskfile in the repository. + +If you want to use the SSH protocol, you need to make sure that your ssh-agent has your private ssh keys added so that they can be used during authentication. + ## Security Running commands from sources that you do not control is always a potential diff --git a/website/versioned_docs/version-latest/reference/cli.mdx b/website/versioned_docs/version-latest/reference/cli.mdx index 9beb1a8302..893236d148 100644 --- a/website/versioned_docs/version-latest/reference/cli.mdx +++ b/website/versioned_docs/version-latest/reference/cli.mdx @@ -62,25 +62,26 @@ four groups with the following ranges: A full list of the exit codes and their descriptions can be found below: -| Code | Description | -| ---- | ------------------------------------------------------------ | -| 0 | Success | -| 1 | An unknown error occurred | -| 100 | No Taskfile was found | -| 101 | A Taskfile already exists when trying to initialize one | -| 102 | The Taskfile is invalid or cannot be parsed | -| 103 | A remote Taskfile could not be downloaded | -| 104 | A remote Taskfile was not trusted by the user | -| 105 | A remote Taskfile was could not be fetched securely | -| 106 | No cache was found for a remote Taskfile in offline mode | -| 107 | No schema version was defined in the Taskfile | -| 200 | The specified task could not be found | -| 201 | An error occurred while executing a command inside of a task | -| 202 | The user tried to invoke a task that is internal | -| 203 | There a multiple tasks with the same name or alias | -| 204 | A task was called too many times | -| 205 | A task was cancelled by the user | -| 206 | A task was not executed due to missing required variables | +| Code | Description | +|------|---------------------------------------------------------------------| +| 0 | Success | +| 1 | An unknown error occurred | +| 100 | No Taskfile was found | +| 101 | A Taskfile already exists when trying to initialize one | +| 102 | The Taskfile is invalid or cannot be parsed | +| 103 | A remote Taskfile could not be downloaded | +| 104 | A remote Taskfile was not trusted by the user | +| 105 | A remote Taskfile was could not be fetched securely | +| 106 | No cache was found for a remote Taskfile in offline mode | +| 107 | No schema version was defined in the Taskfile | +| 200 | The specified task could not be found | +| 201 | An error occurred while executing a command inside of a task | +| 202 | The user tried to invoke a task that is internal | +| 203 | There a multiple tasks with the same name or alias | +| 204 | A task was called too many times | +| 205 | A task was cancelled by the user | +| 206 | A task was not executed due to missing required variables | +| 207 | A task was not executed due to a variable having an incorrect value | These codes can also be found in the repository in [`errors/errors.go`](https://github.com/go-task/task/blob/main/errors/errors.go). diff --git a/website/versioned_docs/version-latest/reference/environment.mdx b/website/versioned_docs/version-latest/reference/environment.mdx index ce9b7334b3..40ccfb6344 100644 --- a/website/versioned_docs/version-latest/reference/environment.mdx +++ b/website/versioned_docs/version-latest/reference/environment.mdx @@ -8,16 +8,17 @@ sidebar_position: 4 Task allows you to configure some behavior using environment variables. This page lists all the environment variables that Task supports. -| ENV | Default | Description | -| ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | -| `TASK_TEMP_DIR` | `.task` | Location of the temp dir. Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. | -| `TASK_REMOTE_DIR` | `TASK_TEMP_DIR` | Location of the remote temp dir (used for caching). Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. | -| `FORCE_COLOR` | | Force color output usage. | +| ENV | Default | Description | +|-------------------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------| +| `TASK_TEMP_DIR` | `.task` | Location of the temp dir. Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. | +| `TASK_REMOTE_DIR` | `TASK_TEMP_DIR` | Location of the remote temp dir (used for caching). Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. | +| `TASK_OFFLINE` | `false` | Set the `--offline` flag through the environment variable. Only for remote experiment. CLI flag `--offline` takes precedence over the env variable | +| `FORCE_COLOR` | | Force color output usage. | ## Custom Colors | ENV | Default | Description | -| --------------------------- | ------- | ----------------------- | +|-----------------------------|---------|-------------------------| | `TASK_COLOR_RESET` | `0` | Color used for white. | | `TASK_COLOR_RED` | `31` | Color used for red. | | `TASK_COLOR_GREEN` | `32` | Color used for green. | diff --git a/website/versioned_docs/version-latest/reference/schema.mdx b/website/versioned_docs/version-latest/reference/schema.mdx index e67a033c23..7066f54504 100644 --- a/website/versioned_docs/version-latest/reference/schema.mdx +++ b/website/versioned_docs/version-latest/reference/schema.mdx @@ -88,7 +88,7 @@ vars: | `deps` | [`[]Dependency`](#dependency) | | A list of dependencies of this task. Tasks defined here will run in parallel before this task. | | `label` | `string` | | Overrides the name of the task in the output when a task is run. Supports variables. | | `desc` | `string` | | A short description of the task. This is displayed when calling `task --list`. | -| `prompt` | `string` | | A prompt that will be presented before a task is run. Declining will cancel running the current and any subsequent tasks. | +| `prompt` | `[]string` | | One or more prompts that will be presented before a task is run. Declining will cancel running the current and any subsequent tasks. | | `summary` | `string` | | A longer description of the task. This is displayed when calling `task --summary [task]`. | | `aliases` | `[]string` | | A list of alternative names by which the task can be called. | | `sources` | `[]string` | | A list of sources to check before running this task. Relevant for `checksum` and `timestamp` methods. Can be file paths or star globs. | diff --git a/website/versioned_docs/version-latest/reference/templating.mdx b/website/versioned_docs/version-latest/reference/templating.mdx index 33df58e876..468a4333b3 100644 --- a/website/versioned_docs/version-latest/reference/templating.mdx +++ b/website/versioned_docs/version-latest/reference/templating.mdx @@ -106,6 +106,7 @@ special variable will be overridden. | `CLI_FORCE` | A boolean containing whether the `--force` or `--force-all` flags were set. | | `CLI_SILENT` | A boolean containing whether the `--silent` flag was set. | | `CLI_VERBOSE` | A boolean containing whether the `--verbose` flag was set. | +| `CLI_OFFLINE` | A boolean containing whether the `--offline` flag was set. | | `TASK` | The name of the current task. | | `ALIAS` | The alias used for the current task, otherwise matches `TASK`. | | `TASK_EXE` | The Task executable name or path. | @@ -373,7 +374,8 @@ Lastly, Task itself provides a few functions: | Function | Description | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `OS` | Returns the operating system. Possible values are `windows`, `linux`, `darwin` (macOS) and `freebsd`. | -| `ARCH` | return the architecture Task was compiled to: `386`, `amd64`, `arm` or `s390x`. | +| `ARCH` | Returns the architecture Task was compiled to: `386`, `amd64`, `arm` or `s390x`. | +| `numCPU` | Returns the number of logical CPU's usable by the current process. | | `splitLines` | Splits Unix (`\n`) and Windows (`\r\n`) styled newlines. | | `catLines` | Replaces Unix (`\n`) and Windows (`\r\n`) styled newlines with a space. | | `toSlash` | Does nothing on Unix, but on Windows converts a string from `\` path format to `/`. | diff --git a/website/versioned_docs/version-latest/usage.mdx b/website/versioned_docs/version-latest/usage.mdx index e05f726827..2f5baa4773 100644 --- a/website/versioned_docs/version-latest/usage.mdx +++ b/website/versioned_docs/version-latest/usage.mdx @@ -1060,6 +1060,40 @@ tasks: vars: [IMAGE_NAME, IMAGE_TAG] ``` +### Ensuring required variables have allowed values + +If you want to ensure that a variable is set to one of a predefined set of valid values before executing a task, you can use requires. +This is particularly useful when there are strict requirements for what values a variable can take, and you want to provide clear feedback to the user when an invalid value is detected. + +To use `requires`, you specify an array of allowed values in the vars sub-section under requires. Task will check if the variable is set to one of the allowed values. +If the variable does not match any of these values, the task will raise an error and stop execution. + +This check applies both to user-defined variables and environment variables. + +Example of using `requires`: + +```yaml +version: '3' + +tasks: + deploy: + cmds: + - echo "deploying to {{.ENV}}" + + requires: + vars: + - name: ENV + enum: [dev, beta, prod] +``` + +If `ENV` is not one of 'dev', 'beta' or 'prod' an error will be raised. + +:::note + +This is supported only for string variables. + +::: + ## Variables Task allows you to set variables using the `vars` keyword. The following @@ -1178,6 +1212,28 @@ tasks: - echo "{{.GREETING}}" ``` +Example of a `default` value to be overridden from CLI: + +```yaml +version: '3' + + greet_user: + desc: "Greet the user with a name." + vars: + USER_NAME: '{{.USER_NAME| default "DefaultUser"}}' + cmds: + - echo "Hello, {{.USER_NAME}}!" +``` + +```shell +$ task greet_user +task: [greet_user] echo "Hello, DefaultUser!" +Hello, DefaultUser! +$ task greet_user USER_NAME="Bob" +task: [greet_user] echo "Hello, Bob!" +Hello, Bob! +``` + ### Dynamic variables The below syntax (`sh:` prop in a variable) is considered a dynamic variable. @@ -1844,6 +1900,24 @@ tasks: task: "This is a dangerous command... Do you want to continue?" [y/N] ``` +Prompts can be a single value or a list of prompts, like below: + +```yaml +version: '3' + +tasks: + example: + cmds: + - task: dangerous + + dangerous: + prompt: + - This is a dangerous command... Do you want to continue? + - Are you sure? + cmds: + - echo 'dangerous command' +``` + Warning prompts are called before executing a task. If a prompt is denied Task will exit with [exit code](/api#exit-codes) 205. If approved, Task will continue as normal. diff --git a/website/yarn.lock b/website/yarn.lock index d64761de5d..39d6517b3d 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -2591,9 +2591,9 @@ vfile "^6.0.0" "@mdx-js/react@^3.0.0": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-3.0.1.tgz#997a19b3a5b783d936c75ae7c47cfe62f967f746" - integrity sha512-9ZrPIU4MGf6et1m1ov3zKf+q9+deetI51zprKB1D/z3NOb+rUxxtEl3mCjW5wTGh6VhRdwPueh1oRzi6ezkA8A== + version "3.1.0" + resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-3.1.0.tgz#c4522e335b3897b9a845db1dbdd2f966ae8fb0ed" + integrity sha512-QjHtSaoameoalGnKDT3FoIl4+9RwyTmo9ZJGBdLOks/YOiWHoRDI3PUwEzOE7kEmGcV3AFcp9K6dYu9rEuKLAQ== dependencies: "@types/mdx" "^2.0.0" @@ -3042,9 +3042,9 @@ csstype "^3.0.2" "@types/react@^18.2.29": - version "18.3.11" - resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.11.tgz#9d530601ff843ee0d7030d4227ea4360236bd537" - integrity sha512-r6QZ069rFTjrEYgFdOck1gK7FLVsgJE7tTz0pQBczlBNUhBNk0MQH4UbnFSwjpQLMkLzgqvBBa+qGpLje16eTQ== + version "18.3.12" + resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.12.tgz#99419f182ccd69151813b7ee24b792fe08774f60" + integrity sha512-D2wOSq/d6Agt28q7rSI3jhU7G6aiuzljDGZ2hTZHIkrTLUI+AF3WMeKkEZ9nN2fkBAlcktT6vcZjDFiIhMYEQw== dependencies: "@types/prop-types" "*" csstype "^3.0.2" @@ -4135,9 +4135,9 @@ cosmiconfig@^8.1.3, cosmiconfig@^8.2.0: path-type "^4.0.0" cross-spawn@^7.0.3: - version "7.0.3" - resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz" - integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0" @@ -5566,9 +5566,9 @@ http-parser-js@>=0.5.1: integrity sha512-SGeBX54F94Wgu5RH3X5jsDtf4eHyRogWX1XGT3b4HuW3tQPM4AaBzoUji/4AAJNXCEOWZ5O0DgZmJw1947gD5Q== http-proxy-middleware@^2.0.3: - version "2.0.6" - resolved "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-2.0.6.tgz" - integrity sha512-ya/UeJ6HVBYxrgYotAZo1KvPWlgB48kUJLDePFeneHsVujFaW5WNj2NgWCAE//B1Dl02BIfYlpNgBy8Kf8Rjmw== + version "2.0.7" + resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.7.tgz#915f236d92ae98ef48278a95dedf17e991936ec6" + integrity sha512-fgVY8AV7qU7z/MmXJ/rxwbrtQH4jBQ9m7kp3llF0liB7glmFeVZFBepQb32T3y8n8k2+AEYuMPCpinYW+/CuRA== dependencies: "@types/http-proxy" "^1.17.8" http-proxy "^1.18.1" @@ -8927,9 +8927,9 @@ typedarray-to-buffer@^3.1.5: is-typedarray "^1.0.0" typescript@^5.3.3: - version "5.6.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0" - integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw== + version "5.6.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b" + integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw== undici-types@~5.26.4: version "5.26.5"