mirror of
https://github.com/go-task/task.git
synced 2026-06-20 14:21:38 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57c094f415 | ||
|
|
2f4876b71c | ||
|
|
725f929778 | ||
|
|
8266b28b48 | ||
|
|
f5c7472f64 | ||
|
|
ced3e7a579 | ||
|
|
36dd71b122 | ||
|
|
21531b6291 | ||
|
|
bfc9d7847d | ||
|
|
3397f2855f | ||
|
|
78a69c4c3e | ||
|
|
01716f55b3 | ||
|
|
ca364c20bb |
@@ -71,7 +71,7 @@ brews:
|
||||
description: Task runner / simpler Make alternative written in Go
|
||||
license: MIT
|
||||
homepage: https://taskfile.dev
|
||||
folder: Formula
|
||||
directory: Formula
|
||||
repository:
|
||||
owner: go-task
|
||||
name: homebrew-tap
|
||||
|
||||
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,5 +1,16 @@
|
||||
# Changelog
|
||||
|
||||
## v3.37.2 - 2024-05-12
|
||||
|
||||
- Fixed a bug where an empty Taskfile would cause a panic (#1648 by @pd93).
|
||||
- Fixed a bug where includes Taskfile variable were not being merged correctly
|
||||
(#1643, #1649 by @pd93).
|
||||
|
||||
## v3.37.1 - 2024-05-09
|
||||
|
||||
- Fix bug where non-string values (numbers, bools) added to `env:` weren't been
|
||||
correctly exported (#1640, #1641 by @vmaerten and @andreynering).
|
||||
|
||||
## v3.37.0 - 2024-05-08
|
||||
|
||||
- Released the
|
||||
|
||||
16
internal/env/env.go
vendored
16
internal/env/env.go
vendored
@@ -13,19 +13,25 @@ func Get(t *ast.Task) []string {
|
||||
}
|
||||
|
||||
environ := os.Environ()
|
||||
|
||||
for k, v := range t.Env.ToCacheMap() {
|
||||
str, isString := v.(string)
|
||||
if !isString {
|
||||
if !isTypeAllowed(v) {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, alreadySet := os.LookupEnv(k); alreadySet {
|
||||
continue
|
||||
}
|
||||
|
||||
environ = append(environ, fmt.Sprintf("%s=%s", k, str))
|
||||
environ = append(environ, fmt.Sprintf("%s=%v", k, v))
|
||||
}
|
||||
|
||||
return environ
|
||||
}
|
||||
|
||||
func isTypeAllowed(v any) bool {
|
||||
switch v.(type) {
|
||||
case string, bool, int, float32, float64:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@go-task/cli",
|
||||
"version": "3.37.0",
|
||||
"version": "3.37.2",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@go-task/cli",
|
||||
"version": "3.37.0",
|
||||
"version": "3.37.2",
|
||||
"description": "A task runner / simpler Make alternative written in Go",
|
||||
"scripts": {
|
||||
"postinstall": "go-npm install",
|
||||
|
||||
42
task_test.go
42
task_test.go
@@ -95,14 +95,24 @@ func TestEmptyTask(t *testing.T) {
|
||||
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "default"}))
|
||||
}
|
||||
|
||||
func TestEmptyTaskfile(t *testing.T) {
|
||||
e := &task.Executor{
|
||||
Dir: "testdata/empty_taskfile",
|
||||
Stdout: io.Discard,
|
||||
Stderr: io.Discard,
|
||||
}
|
||||
require.Error(t, e.Setup(), "e.Setup()")
|
||||
}
|
||||
|
||||
func TestEnv(t *testing.T) {
|
||||
tt := fileContentTest{
|
||||
Dir: "testdata/env",
|
||||
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",
|
||||
"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",
|
||||
},
|
||||
}
|
||||
tt.Run(t)
|
||||
@@ -1227,6 +1237,34 @@ func TestIncludesInterpolation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncludedTaskfileVarMerging(t *testing.T) {
|
||||
const dir = "testdata/included_taskfile_var_merging"
|
||||
tests := []struct {
|
||||
name string
|
||||
task string
|
||||
expectedOutput string
|
||||
}{
|
||||
{"foo", "foo:pwd", "included_taskfile_var_merging/foo\n"},
|
||||
{"bar", "bar:pwd", "included_taskfile_var_merging/bar\n"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
Silent: true,
|
||||
}
|
||||
require.NoError(t, e.Setup())
|
||||
|
||||
err := e.Run(context.Background(), &ast.Call{Task: test.task})
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, buff.String(), test.expectedOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInternalTask(t *testing.T) {
|
||||
const dir = "testdata/internal_task"
|
||||
tests := []struct {
|
||||
|
||||
@@ -90,7 +90,7 @@ func (t1 *Tasks) Merge(t2 Tasks, include *Include, includedTaskfileVars *Vars) {
|
||||
task.IncludeVars = &Vars{}
|
||||
}
|
||||
task.IncludeVars.Merge(include.Vars, nil)
|
||||
task.IncludedTaskfileVars = includedTaskfileVars
|
||||
task.IncludedTaskfileVars = includedTaskfileVars.DeepCopy()
|
||||
}
|
||||
|
||||
// Add the task to the merged taskfile
|
||||
|
||||
@@ -263,23 +263,28 @@ func (r *Reader) readNode(node Node) (*ast.Taskfile, error) {
|
||||
}
|
||||
}
|
||||
|
||||
var t ast.Taskfile
|
||||
if err := yaml.Unmarshal(b, &t); err != nil {
|
||||
var tf ast.Taskfile
|
||||
if err := yaml.Unmarshal(b, &tf); err != nil {
|
||||
return nil, &errors.TaskfileInvalidError{URI: filepathext.TryAbsToRel(node.Location()), Err: err}
|
||||
}
|
||||
|
||||
// Check that the Taskfile is set and has a schema version
|
||||
if tf.Version == nil {
|
||||
return nil, &errors.TaskfileVersionCheckError{URI: node.Location()}
|
||||
}
|
||||
|
||||
// Set the taskfile/task's locations
|
||||
t.Location = node.Location()
|
||||
for _, task := range t.Tasks.Values() {
|
||||
tf.Location = node.Location()
|
||||
for _, task := range tf.Tasks.Values() {
|
||||
// If the task is not defined, create a new one
|
||||
if task == nil {
|
||||
task = &ast.Task{}
|
||||
}
|
||||
// Set the location of the taskfile for each task
|
||||
if task.Location.Taskfile == "" {
|
||||
task.Location.Taskfile = t.Location
|
||||
task.Location.Taskfile = tf.Location
|
||||
}
|
||||
}
|
||||
|
||||
return &t, nil
|
||||
return &tf, nil
|
||||
}
|
||||
|
||||
0
testdata/empty_taskfile/Taskfile.yml
vendored
Normal file
0
testdata/empty_taskfile/Taskfile.yml
vendored
Normal file
9
testdata/env/Taskfile.yml
vendored
9
testdata/env/Taskfile.yml
vendored
@@ -14,6 +14,7 @@ tasks:
|
||||
cmds:
|
||||
- task: local
|
||||
- task: global
|
||||
- task: multiple_type
|
||||
|
||||
local:
|
||||
vars:
|
||||
@@ -31,3 +32,11 @@ tasks:
|
||||
BAR: overriden
|
||||
cmds:
|
||||
- echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'" > global.txt
|
||||
|
||||
multiple_type:
|
||||
env:
|
||||
FOO: 1
|
||||
BAR: true
|
||||
BAZ: 1.1
|
||||
cmds:
|
||||
- echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'" > multiple_type.txt
|
||||
|
||||
12
testdata/included_taskfile_var_merging/Taskfile.yaml
vendored
Normal file
12
testdata/included_taskfile_var_merging/Taskfile.yaml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
version: "3"
|
||||
|
||||
includes:
|
||||
foo:
|
||||
taskfile: ./foo/Taskfile.yaml
|
||||
bar:
|
||||
taskfile: ./bar/Taskfile.yaml
|
||||
|
||||
tasks:
|
||||
stub:
|
||||
cmds:
|
||||
- echo 0
|
||||
11
testdata/included_taskfile_var_merging/bar/Taskfile.yaml
vendored
Normal file
11
testdata/included_taskfile_var_merging/bar/Taskfile.yaml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
version: "3"
|
||||
|
||||
vars:
|
||||
DIR: bar
|
||||
|
||||
tasks:
|
||||
pwd:
|
||||
dir: ./{{ .DIR }}
|
||||
cmds:
|
||||
- echo "{{ .DIR }}"
|
||||
- pwd
|
||||
11
testdata/included_taskfile_var_merging/foo/Taskfile.yaml
vendored
Normal file
11
testdata/included_taskfile_var_merging/foo/Taskfile.yaml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
version: "3"
|
||||
|
||||
vars:
|
||||
DIR: foo
|
||||
|
||||
tasks:
|
||||
pwd:
|
||||
dir: ./{{ .DIR }}
|
||||
cmds:
|
||||
- echo "{{ .DIR }}"
|
||||
- pwd
|
||||
@@ -6,7 +6,6 @@ authors: [pd93]
|
||||
tags: [experiments, variables]
|
||||
image: https://i.imgur.com/mErPwqL.png
|
||||
hide_table_of_contents: false
|
||||
draft: true
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
@@ -15,7 +14,7 @@ import TabItem from '@theme/TabItem';
|
||||
Task has always had variables, but even though you were able to define them
|
||||
using different YAML types, they would always be converted to strings by Task.
|
||||
This limited users to string manipulation and encouraged messy workarounds for
|
||||
simple problems. Starting from [v3.36.0][v3.36.0], this is no longer the case!
|
||||
simple problems. Starting from [v3.37.0][v3.37.0], this is no longer the case!
|
||||
Task now supports most variable types, including **booleans**, **integers**,
|
||||
**floats** and **arrays**!
|
||||
|
||||
@@ -175,7 +174,7 @@ We're looking for feedback on a couple of different proposals, so please give
|
||||
them a go and let us know what you think. :pray:
|
||||
|
||||
{/* prettier-ignore-start */}
|
||||
[v3.36.0]: https://github.com/go-task/task/releases/tag/v3.36.0
|
||||
[v3.37.0]: https://github.com/go-task/task/releases/tag/v3.37.0
|
||||
[slim-sprig-math]: https://go-task.github.io/slim-sprig/math.html
|
||||
[slim-sprig-list]: https://go-task.github.io/slim-sprig/lists.html
|
||||
[map-variables]: /experiments/map-variables
|
||||
@@ -5,6 +5,17 @@ sidebar_position: 14
|
||||
|
||||
# Changelog
|
||||
|
||||
## v3.37.2 - 2024-05-12
|
||||
|
||||
- Fixed a bug where an empty Taskfile would cause a panic (#1648 by @pd93).
|
||||
- Fixed a bug where includes Taskfile variable were not being merged correctly
|
||||
(#1643, #1649 by @pd93).
|
||||
|
||||
## v3.37.1 - 2024-05-09
|
||||
|
||||
- Fix bug where non-string values (numbers, bools) added to `env:` weren't been
|
||||
correctly exported (#1640, #1641 by @vmaerten and @andreynering).
|
||||
|
||||
## v3.37.0 - 2024-05-08
|
||||
|
||||
- Released the
|
||||
|
||||
@@ -148,6 +148,8 @@ If you have questions, feel free to ask them in the `#help` forum channel on our
|
||||
---
|
||||
|
||||
{/* prettier-ignore-start */}
|
||||
[experiments]: /experiments
|
||||
[experiments-workflow]: /experiments#workflow
|
||||
[task]: https://github.com/go-task/task
|
||||
[vscode-task]: https://github.com/go-task/vscode-task
|
||||
[go]: https://go.dev
|
||||
|
||||
@@ -285,9 +285,9 @@
|
||||
"yaml": {
|
||||
"type": "string",
|
||||
"description": "The value will parsed as a YAML string and stored in the variable"
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"task_call": {
|
||||
"type": "object",
|
||||
@@ -512,7 +512,7 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"exclude": {
|
||||
"description": "File or glob patter to exclude from the list",
|
||||
"description": "File or glob pattern to exclude from the list",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
@@ -648,7 +648,7 @@
|
||||
"$ref": "#/definitions/tasks"
|
||||
},
|
||||
"silent": {
|
||||
"description": "Default 'silent' options for this Taskfile. If `false`, can be overidden with `true` in a task by task basis.",
|
||||
"description": "Default 'silent' options for this Taskfile. If `false`, can be overridden with `true` in a task by task basis.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"set": {
|
||||
|
||||
@@ -5,6 +5,17 @@ sidebar_position: 14
|
||||
|
||||
# Changelog
|
||||
|
||||
## v3.37.2 - 2024-05-12
|
||||
|
||||
- Fixed a bug where an empty Taskfile would cause a panic (#1648 by @pd93).
|
||||
- Fixed a bug where includes Taskfile variable were not being merged correctly
|
||||
(#1643, #1649 by @pd93).
|
||||
|
||||
## v3.37.1 - 2024-05-09
|
||||
|
||||
- Fix bug where non-string values (numbers, bools) added to `env:` weren't been
|
||||
correctly exported (#1640, #1641 by @vmaerten and @andreynering).
|
||||
|
||||
## v3.37.0 - 2024-05-08
|
||||
|
||||
- Released the
|
||||
|
||||
@@ -148,6 +148,8 @@ If you have questions, feel free to ask them in the `#help` forum channel on our
|
||||
---
|
||||
|
||||
{/* prettier-ignore-start */}
|
||||
[experiments]: /experiments
|
||||
[experiments-workflow]: /experiments#workflow
|
||||
[task]: https://github.com/go-task/task
|
||||
[vscode-task]: https://github.com/go-task/vscode-task
|
||||
[go]: https://go.dev
|
||||
|
||||
Reference in New Issue
Block a user