mirror of
https://github.com/go-task/task.git
synced 2026-06-23 20:55:52 +00:00
Compare commits
61 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c420f3a34 | ||
|
|
84da80356d | ||
|
|
bcbb85eac3 | ||
|
|
0e1d8a72e6 | ||
|
|
bbdd698869 | ||
|
|
8f684ffa6d | ||
|
|
9be3666fe7 | ||
|
|
b7785678f4 | ||
|
|
d8005b4cf6 | ||
|
|
52028fc3bc | ||
|
|
5285ec23ae | ||
|
|
3c882e5c57 | ||
|
|
ad569a8a36 | ||
|
|
0d9fdbaac1 | ||
|
|
f5cd3eab9e | ||
|
|
8987cd64a0 | ||
|
|
fac51dcf03 | ||
|
|
01101a4c9b | ||
|
|
d561e40817 | ||
|
|
0cb298ebdf | ||
|
|
a149368725 | ||
|
|
afeefe8259 | ||
|
|
690d3c27a2 | ||
|
|
3d56ea5ce5 | ||
|
|
fdff7f80a3 | ||
|
|
fe6978b107 | ||
|
|
57db6865d2 | ||
|
|
d235d5ab28 | ||
|
|
613dfe06d3 | ||
|
|
a312d61d68 | ||
|
|
e414c1f7b0 | ||
|
|
955359b073 | ||
|
|
26e0c0887a | ||
|
|
4c295b564a | ||
|
|
2eb52da0db | ||
|
|
d8bfb3ab13 | ||
|
|
d970e93507 | ||
|
|
762714de68 | ||
|
|
82a3651a18 | ||
|
|
abe0352de9 | ||
|
|
4cee4aa5a8 | ||
|
|
9c68c7c50b | ||
|
|
0608782cfa | ||
|
|
edeaf3794a | ||
|
|
fe2b8c8afa | ||
|
|
b66bf58064 | ||
|
|
957dfa9cdf | ||
|
|
cc9264854e | ||
|
|
d1463b3e24 | ||
|
|
f1082520e1 | ||
|
|
733c563194 | ||
|
|
0200d043c3 | ||
|
|
9c475c36e7 | ||
|
|
c663c5c507 | ||
|
|
1e93c38307 | ||
|
|
81baf808c9 | ||
|
|
74537689dc | ||
|
|
12ab01d5e6 | ||
|
|
044d3a0ff9 | ||
|
|
659cae6a4c | ||
|
|
bd5882f0f0 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
open_collective: task
|
||||||
59
.github/workflows/test.yml
vendored
Normal file
59
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
name: Test
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
linux:
|
||||||
|
name: Linux
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Go 1.13
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.13
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -o ./task -v ./cmd/task
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: ./task test
|
||||||
|
|
||||||
|
windows:
|
||||||
|
name: Windows
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Go 1.13
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.13
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go install -v ./cmd/task
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test -v ./...
|
||||||
|
|
||||||
|
macos:
|
||||||
|
name: MacOS
|
||||||
|
runs-on: macOS-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Go 1.13
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.13
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -o ./task -v ./cmd/task
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: ./task test
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -21,3 +21,8 @@ dist/
|
|||||||
|
|
||||||
# intellij idea/goland
|
# intellij idea/goland
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
# exuberant ctags
|
||||||
|
tags
|
||||||
|
|
||||||
|
/bin
|
||||||
|
|||||||
@@ -14,12 +14,11 @@ build:
|
|||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
|
|
||||||
archive:
|
archives:
|
||||||
name_template: "{{.Binary}}_{{.Os}}_{{.Arch}}"
|
- name_template: "{{.Binary}}_{{.Os}}_{{.Arch}}"
|
||||||
|
format_overrides:
|
||||||
format_overrides:
|
- goos: windows
|
||||||
- goos: windows
|
format: zip
|
||||||
format: zip
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
draft: true
|
draft: true
|
||||||
@@ -30,15 +29,15 @@ snapshot:
|
|||||||
checksum:
|
checksum:
|
||||||
name_template: "task_checksums.txt"
|
name_template: "task_checksums.txt"
|
||||||
|
|
||||||
nfpm:
|
nfpms:
|
||||||
vendor: Task
|
- vendor: Task
|
||||||
homepage: https://github.com/go-task/task
|
homepage: https://github.com/go-task/task
|
||||||
maintainer: Andrey Nering <andrey.nering@gmail.com>
|
maintainer: Andrey Nering <andrey.nering@gmail.com>
|
||||||
description: Simple task runner written in Go
|
description: Simple task runner written in Go
|
||||||
license: MIT
|
license: MIT
|
||||||
conflicts:
|
conflicts:
|
||||||
- taskwarrior
|
- taskwarrior
|
||||||
formats:
|
formats:
|
||||||
- deb
|
- deb
|
||||||
- rpm
|
- rpm
|
||||||
name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}"
|
name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.11.x
|
|
||||||
- 1.12.x
|
- 1.12.x
|
||||||
|
- 1.13.x
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
@@ -10,7 +10,7 @@ addons:
|
|||||||
- rpm
|
- rpm
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- go install github.com/go-task/task/cmd/task
|
- go install -v ./cmd/task
|
||||||
- task ci
|
- task ci
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
|
|||||||
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,5 +1,25 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v2.7.0 - 2019-09-22
|
||||||
|
|
||||||
|
- Fixed panic bug when assigning a global variable
|
||||||
|
([#229](https://github.com/go-task/task/issues/229), [#243](https://github.com/go-task/task/issues/234)).
|
||||||
|
- A task with `method: checksum` will now re-run if generated files are deleted
|
||||||
|
([#228](https://github.com/go-task/task/pull/228), [#238](https://github.com/go-task/task/issues/238)).
|
||||||
|
|
||||||
|
## v2.6.0 - 2019-07-21
|
||||||
|
|
||||||
|
- Fixed some bugs regarding minor version checks on `version:`.
|
||||||
|
- Add `preconditions:` to task
|
||||||
|
([#205](https://github.com/go-task/task/pull/205)).
|
||||||
|
- Create directory informed on `dir:` if it doesn't exist
|
||||||
|
([#209](https://github.com/go-task/task/issues/209), [#211](https://github.com/go-task/task/pull/211)).
|
||||||
|
- We now have a `--taskfile` flag (alias `-t`), which can be used to run
|
||||||
|
another Taskfile (other than the default `Taskfile.yml`)
|
||||||
|
([#221](https://github.com/go-task/task/pull/221)).
|
||||||
|
- It's now possible to install Task using Homebrew on Linux
|
||||||
|
([go-task/homebrew-tap#1](https://github.com/go-task/homebrew-tap/pull/1)).
|
||||||
|
|
||||||
## v2.5.2 - 2019-05-11
|
## v2.5.2 - 2019-05-11
|
||||||
|
|
||||||
- Reverted YAML upgrade due issues with CRLF on Windows
|
- Reverted YAML upgrade due issues with CRLF on Windows
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/go-task/task/v2"
|
"github.com/go-task/task/v2"
|
||||||
@@ -17,7 +18,7 @@ var (
|
|||||||
version = "master"
|
version = "master"
|
||||||
)
|
)
|
||||||
|
|
||||||
const usage = `Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--dry] [--summary] [task...]
|
const usage = `Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--taskfile] [--dry] [--summary] [task...]
|
||||||
|
|
||||||
Runs the specified task(s). Falls back to the "default" task if no task name
|
Runs the specified task(s). Falls back to the "default" task if no task name
|
||||||
was specified, or lists all tasks if an unknown task name was specified.
|
was specified, or lists all tasks if an unknown task name was specified.
|
||||||
@@ -58,6 +59,7 @@ func main() {
|
|||||||
dry bool
|
dry bool
|
||||||
summary bool
|
summary bool
|
||||||
dir string
|
dir string
|
||||||
|
entrypoint string
|
||||||
output string
|
output string
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -72,6 +74,7 @@ func main() {
|
|||||||
pflag.BoolVar(&dry, "dry", false, "compiles and prints tasks in the order that they would be run, without executing them")
|
pflag.BoolVar(&dry, "dry", false, "compiles and prints tasks in the order that they would be run, without executing them")
|
||||||
pflag.BoolVar(&summary, "summary", false, "show summary about a task")
|
pflag.BoolVar(&summary, "summary", false, "show summary about a task")
|
||||||
pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution")
|
pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution")
|
||||||
|
pflag.StringVarP(&entrypoint, "taskfile", "t", "", `choose which Taskfile to run. Defaults to "Taskfile.yml"`)
|
||||||
pflag.StringVarP(&output, "output", "o", "", "sets output style: [interleaved|group|prefixed]")
|
pflag.StringVarP(&output, "output", "o", "", "sets output style: [interleaved|group|prefixed]")
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
@@ -91,14 +94,26 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dir != "" && entrypoint != "" {
|
||||||
|
log.Fatal("task: You can't set both --dir and --taskfile")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if entrypoint != "" {
|
||||||
|
dir = filepath.Dir(entrypoint)
|
||||||
|
entrypoint = filepath.Base(entrypoint)
|
||||||
|
} else {
|
||||||
|
entrypoint = "Taskfile.yml"
|
||||||
|
}
|
||||||
|
|
||||||
e := task.Executor{
|
e := task.Executor{
|
||||||
Force: force,
|
Force: force,
|
||||||
Watch: watch,
|
Watch: watch,
|
||||||
Verbose: verbose,
|
Verbose: verbose,
|
||||||
Silent: silent,
|
Silent: silent,
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
Dry: dry,
|
Dry: dry,
|
||||||
Summary: summary,
|
Entrypoint: entrypoint,
|
||||||
|
Summary: summary,
|
||||||
|
|
||||||
Stdin: os.Stdin,
|
Stdin: os.Stdin,
|
||||||
Stdout: os.Stdout,
|
Stdout: os.Stdout,
|
||||||
|
|||||||
@@ -8,13 +8,15 @@ The `task_checksums.txt` file contains the sha256 checksum for each file.
|
|||||||
|
|
||||||
## Homebrew
|
## Homebrew
|
||||||
|
|
||||||
If you're on macOS and have [Homebrew][homebrew] installed, getting Task is
|
If you're on macOS or Linux and have [Homebrew][homebrew] installed, getting
|
||||||
as simple as running:
|
Task is as simple as running:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew install go-task/tap/go-task
|
brew install go-task/tap/go-task
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> This installation method is only currently supported on amd64 architectures.
|
||||||
|
|
||||||
## Snap
|
## Snap
|
||||||
|
|
||||||
Task is available for [Snapcraft][snapcraft], but keep in mind that your
|
Task is available for [Snapcraft][snapcraft], but keep in mind that your
|
||||||
|
|||||||
@@ -141,6 +141,21 @@ includes:
|
|||||||
docker: ./DockerTasks.yml
|
docker: ./DockerTasks.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Version 2.6
|
||||||
|
|
||||||
|
Version 2.6 comes with `preconditions` stanza in tasks.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
upload_environment:
|
||||||
|
preconditions:
|
||||||
|
- test -f .env
|
||||||
|
cmds:
|
||||||
|
- aws s3 cp .env s3://myenvironment
|
||||||
|
```
|
||||||
|
|
||||||
Please check the [documentation][includes]
|
Please check the [documentation][includes]
|
||||||
|
|
||||||
[output]: usage.md#output-syntax
|
[output]: usage.md#output-syntax
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ tasks:
|
|||||||
- caddy
|
- caddy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If the directory doesn't exist, `task` creates it.
|
||||||
|
|
||||||
## Task dependencies
|
## Task dependencies
|
||||||
|
|
||||||
You may have tasks that depend on others. Just pointing them on `deps` will
|
You may have tasks that depend on others. Just pointing them on `deps` will
|
||||||
@@ -344,12 +346,61 @@ up-to-date.
|
|||||||
Also, `task --status [tasks]...` will exit with a non-zero exit code if any of
|
Also, `task --status [tasks]...` will exit with a non-zero exit code if any of
|
||||||
the tasks are not up-to-date.
|
the tasks are not up-to-date.
|
||||||
|
|
||||||
|
If you need a certain set of conditions to be _true_ you can use the
|
||||||
|
`preconditions` stanza. `preconditions` are very similar to `status`
|
||||||
|
lines except they support `sh` expansion and they SHOULD all return 0.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
generate-files:
|
||||||
|
cmds:
|
||||||
|
- mkdir directory
|
||||||
|
- touch directory/file1.txt
|
||||||
|
- touch directory/file2.txt
|
||||||
|
# test existence of files
|
||||||
|
preconditions:
|
||||||
|
- test -f .env
|
||||||
|
- sh: "[ 1 = 0 ]"
|
||||||
|
msg: "One doesn't equal Zero, Halting"
|
||||||
|
```
|
||||||
|
|
||||||
|
Preconditions can set specific failure messages that can tell
|
||||||
|
a user what steps to take using the `msg` field.
|
||||||
|
|
||||||
|
If a task has a dependency on a sub-task with a precondition, and that
|
||||||
|
precondition is not met - the calling task will fail. Note that a task
|
||||||
|
executed with a failing precondition will not run unless `--force` is
|
||||||
|
given.
|
||||||
|
|
||||||
|
Unlike `status` which will skip a task if it is up to date, and continue
|
||||||
|
executing tasks that depend on it, a `precondition` will fail a task, along
|
||||||
|
with any other tasks that depend on it.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '2'
|
||||||
|
tasks:
|
||||||
|
task_will_fail:
|
||||||
|
preconditions:
|
||||||
|
- sh: "exit 1"
|
||||||
|
|
||||||
|
task_will_also_fail:
|
||||||
|
deps:
|
||||||
|
- task_will_fail
|
||||||
|
|
||||||
|
task_will_still_fail:
|
||||||
|
cmds:
|
||||||
|
- task: task_will_fail
|
||||||
|
- echo "I will not run"
|
||||||
|
```
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
||||||
When doing interpolation of variables, Task will look for the below.
|
When doing interpolation of variables, Task will look for the below.
|
||||||
They are listed below in order of importance (e.g. most important first):
|
They are listed below in order of importance (e.g. most important first):
|
||||||
|
|
||||||
- Variables declared locally in the task
|
- Variables declared in the task definition
|
||||||
- Variables given while calling a task from another.
|
- Variables given while calling a task from another.
|
||||||
(See [Calling another task](#calling-another-task) above)
|
(See [Calling another task](#calling-another-task) above)
|
||||||
- Variables declared in the `vars:` option in the `Taskfile`
|
- Variables declared in the `vars:` option in the `Taskfile`
|
||||||
@@ -385,7 +436,7 @@ version: '2'
|
|||||||
tasks:
|
tasks:
|
||||||
print-var:
|
print-var:
|
||||||
cmds:
|
cmds:
|
||||||
echo "{{.VAR}}"
|
- echo "{{.VAR}}"
|
||||||
vars:
|
vars:
|
||||||
VAR: Hello!
|
VAR: Hello!
|
||||||
```
|
```
|
||||||
|
|||||||
13
go.mod
13
go.mod
@@ -1,23 +1,20 @@
|
|||||||
module github.com/go-task/task/v2
|
module github.com/go-task/task/v2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/semver v1.4.2
|
github.com/Masterminds/semver v1.4.2 // indirect
|
||||||
github.com/Masterminds/sprig v2.16.0+incompatible
|
github.com/Masterminds/sprig v2.16.0+incompatible
|
||||||
github.com/aokoli/goutils v1.0.1 // indirect
|
github.com/aokoli/goutils v1.0.1 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/google/uuid v1.0.0 // indirect
|
github.com/google/uuid v1.0.0 // indirect
|
||||||
github.com/huandu/xstrings v1.1.0 // indirect
|
github.com/huandu/xstrings v1.1.0 // indirect
|
||||||
github.com/imdario/mergo v0.3.6 // indirect
|
github.com/imdario/mergo v0.3.6 // indirect
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
|
||||||
github.com/mattn/go-zglob v0.0.1
|
github.com/mattn/go-zglob v0.0.1
|
||||||
github.com/mitchellh/go-homedir v1.0.0
|
|
||||||
github.com/radovskyb/watcher v1.0.5
|
github.com/radovskyb/watcher v1.0.5
|
||||||
github.com/spf13/pflag v1.0.3
|
github.com/spf13/pflag v1.0.3
|
||||||
github.com/stretchr/testify v1.3.0
|
github.com/stretchr/testify v1.3.0
|
||||||
golang.org/x/crypto v0.0.0-20180830192347-182538f80094 // indirect
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
|
|
||||||
golang.org/x/sys v0.0.0-20180831094639-fa5fdf94c789 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.2.1
|
gopkg.in/yaml.v2 v2.2.1
|
||||||
mvdan.cc/sh v2.6.4+incompatible
|
mvdan.cc/sh/v3 v3.0.0-alpha2.0.20190908210725-4a0ebd2f3c1b
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|||||||
29
go.sum
29
go.sum
@@ -20,28 +20,33 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/mattn/go-zglob v0.0.1 h1:xsEx/XUoVlI6yXjqBK062zYhRTZltCNmYPx6v+8DNaY=
|
github.com/mattn/go-zglob v0.0.1 h1:xsEx/XUoVlI6yXjqBK062zYhRTZltCNmYPx6v+8DNaY=
|
||||||
github.com/mattn/go-zglob v0.0.1/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
|
github.com/mattn/go-zglob v0.0.1/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
|
||||||
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
|
|
||||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/radovskyb/watcher v1.0.5 h1:wqt7gb+HjGacvFoLTKeT44C+XVPxu7bvHvKT1IvZ7rw=
|
github.com/radovskyb/watcher v1.0.5 h1:wqt7gb+HjGacvFoLTKeT44C+XVPxu7bvHvKT1IvZ7rw=
|
||||||
github.com/radovskyb/watcher v1.0.5/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg=
|
github.com/radovskyb/watcher v1.0.5/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg=
|
||||||
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
golang.org/x/crypto v0.0.0-20180830192347-182538f80094 h1:rVTAlhYa4+lCfNxmAIEOGQRoD23UqP72M3+rSWVGDTg=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20180830192347-182538f80094/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20180831094639-fa5fdf94c789 h1:T8D7l6WB3tLu+VpKvw06ieD/OhBi1XpJmG1U/FtttZg=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20180831094639-fa5fdf94c789/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
|
||||||
|
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
mvdan.cc/sh v2.6.4+incompatible h1:eD6tDeh0pw+/TOTI1BBEryZ02rD2nMcFsgcvde7jffM=
|
mvdan.cc/sh/v3 v3.0.0-alpha2.0.20190908210725-4a0ebd2f3c1b h1:kzTXBacNrjp7n8ncNC894X9NUeL8yeKVS5MS0bigJwE=
|
||||||
mvdan.cc/sh v2.6.4+incompatible/go.mod h1:IeeQbZq+x2SUGBensq/jge5lLQbS3XT2ktyp3wrt4x8=
|
mvdan.cc/sh/v3 v3.0.0-alpha2.0.20190908210725-4a0ebd2f3c1b/go.mod h1:6Cd5lQRZZIHeKAdYoLvhhse0oDOIrS5gBoGacWnuiUE=
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"mvdan.cc/sh/expand"
|
"mvdan.cc/sh/v3/expand"
|
||||||
"mvdan.cc/sh/interp"
|
"mvdan.cc/sh/v3/interp"
|
||||||
"mvdan.cc/sh/shell"
|
"mvdan.cc/sh/v3/shell"
|
||||||
"mvdan.cc/sh/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunCommandOptions is the options for the RunCommand func
|
// RunCommandOptions is the options for the RunCommand func
|
||||||
@@ -49,8 +49,7 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
|
|||||||
interp.Dir(opts.Dir),
|
interp.Dir(opts.Dir),
|
||||||
interp.Env(expand.ListEnviron(environ...)),
|
interp.Env(expand.ListEnviron(environ...)),
|
||||||
|
|
||||||
interp.Module(interp.DefaultExec),
|
interp.WithOpenModules(interp.OpenDevImpls),
|
||||||
interp.Module(interp.OpenDevImpls(interp.DefaultOpen)),
|
|
||||||
|
|
||||||
interp.StdIO(opts.Stdin, opts.Stdout, opts.Stderr),
|
interp.StdIO(opts.Stdin, opts.Stdout, opts.Stderr),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ import (
|
|||||||
// Checksum validades if a task is up to date by calculating its source
|
// Checksum validades if a task is up to date by calculating its source
|
||||||
// files checksum
|
// files checksum
|
||||||
type Checksum struct {
|
type Checksum struct {
|
||||||
Dir string
|
Dir string
|
||||||
Task string
|
Task string
|
||||||
Sources []string
|
Sources []string
|
||||||
Dry bool
|
Generates []string
|
||||||
|
Dry bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsUpToDate implements the Checker interface
|
// IsUpToDate implements the Checker interface
|
||||||
@@ -27,7 +28,7 @@ func (c *Checksum) IsUpToDate() (bool, error) {
|
|||||||
data, _ := ioutil.ReadFile(checksumFile)
|
data, _ := ioutil.ReadFile(checksumFile)
|
||||||
oldMd5 := strings.TrimSpace(string(data))
|
oldMd5 := strings.TrimSpace(string(data))
|
||||||
|
|
||||||
sources, err := glob(c.Dir, c.Sources)
|
sources, err := globs(c.Dir, c.Sources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -43,6 +44,23 @@ func (c *Checksum) IsUpToDate() (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(c.Generates) > 0 {
|
||||||
|
// For each specified 'generates' field, check whether the files actually exist
|
||||||
|
for _, g := range c.Generates {
|
||||||
|
generates, err := glob(c.Dir, g)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if len(generates) == 0 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return oldMd5 == newMd5, nil
|
return oldMd5 == newMd5, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,21 +68,14 @@ func (c *Checksum) checksum(files ...string) (string, error) {
|
|||||||
h := md5.New()
|
h := md5.New()
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
|
// also sum the filename, so checksum changes for renaming a file
|
||||||
|
if _, err := io.Copy(h, strings.NewReader(filepath.Base(f))); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
f, err := os.Open(f)
|
f, err := os.Open(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
info, err := f.Stat()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if info.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// also sum the filename, so checksum changes for renaming a file
|
|
||||||
if _, err = io.Copy(h, strings.NewReader(info.Name())); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if _, err = io.Copy(h, f); err != nil {
|
if _, err = io.Copy(h, f); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package status
|
package status
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
@@ -9,21 +10,41 @@ import (
|
|||||||
"github.com/mattn/go-zglob"
|
"github.com/mattn/go-zglob"
|
||||||
)
|
)
|
||||||
|
|
||||||
func glob(dir string, globs []string) (files []string, err error) {
|
func globs(dir string, globs []string) ([]string, error) {
|
||||||
|
files := make([]string, 0)
|
||||||
for _, g := range globs {
|
for _, g := range globs {
|
||||||
if !filepath.IsAbs(g) {
|
f, err := glob(dir, g)
|
||||||
g = filepath.Join(dir, g)
|
|
||||||
}
|
|
||||||
g, err = execext.Expand(g)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
f, err := zglob.Glob(g)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
files = append(files, f...)
|
files = append(files, f...)
|
||||||
}
|
}
|
||||||
sort.Strings(files)
|
sort.Strings(files)
|
||||||
return
|
return files, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func glob(dir string, g string) ([]string, error) {
|
||||||
|
files := make([]string, 0)
|
||||||
|
if !filepath.IsAbs(g) {
|
||||||
|
g = filepath.Join(dir, g)
|
||||||
|
}
|
||||||
|
g, err := execext.Expand(g)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fs, err := zglob.Glob(g)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, f := range fs {
|
||||||
|
info, err := os.Stat(f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if info.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
files = append(files, f)
|
||||||
|
}
|
||||||
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ func (t *Timestamp) IsUpToDate() (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sources, err := glob(t.Dir, t.Sources)
|
sources, err := globs(t.Dir, t.Sources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
generates, err := glob(t.Dir, t.Generates)
|
generates, err := globs(t.Dir, t.Generates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|||||||
45
internal/taskfile/precondition.go
Normal file
45
internal/taskfile/precondition.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package taskfile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrCantUnmarshalPrecondition is returned for invalid precond YAML.
|
||||||
|
ErrCantUnmarshalPrecondition = errors.New("task: Can't unmarshal precondition value")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Precondition represents a precondition necessary for a task to run
|
||||||
|
type Precondition struct {
|
||||||
|
Sh string
|
||||||
|
Msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML implements yaml.Unmarshaler interface.
|
||||||
|
func (p *Precondition) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
var cmd string
|
||||||
|
|
||||||
|
if err := unmarshal(&cmd); err == nil {
|
||||||
|
p.Sh = cmd
|
||||||
|
p.Msg = fmt.Sprintf("`%s` failed", cmd)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var sh struct {
|
||||||
|
Sh string
|
||||||
|
Msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := unmarshal(&sh); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Sh = sh.Sh
|
||||||
|
p.Msg = sh.Msg
|
||||||
|
if p.Msg == "" {
|
||||||
|
p.Msg = fmt.Sprintf("%s failed", sh.Sh)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
48
internal/taskfile/precondition_test.go
Normal file
48
internal/taskfile/precondition_test.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package taskfile_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/go-task/task/v2/internal/taskfile"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPreconditionParse(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
content string
|
||||||
|
v interface{}
|
||||||
|
expected interface{}
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"test -f foo.txt",
|
||||||
|
&taskfile.Precondition{},
|
||||||
|
&taskfile.Precondition{Sh: `test -f foo.txt`, Msg: "`test -f foo.txt` failed"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"sh: '[ 1 = 0 ]'",
|
||||||
|
&taskfile.Precondition{},
|
||||||
|
&taskfile.Precondition{Sh: "[ 1 = 0 ]", Msg: "[ 1 = 0 ] failed"},
|
||||||
|
},
|
||||||
|
{`
|
||||||
|
sh: "[ 1 = 2 ]"
|
||||||
|
msg: "1 is not 2"
|
||||||
|
`,
|
||||||
|
&taskfile.Precondition{},
|
||||||
|
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
|
||||||
|
},
|
||||||
|
{`
|
||||||
|
sh: "[ 1 = 2 ]"
|
||||||
|
msg: "1 is not 2"
|
||||||
|
`,
|
||||||
|
&taskfile.Precondition{},
|
||||||
|
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
err := yaml.Unmarshal([]byte(test.content), test.v)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, test.expected, test.v)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,16 +15,13 @@ import (
|
|||||||
var (
|
var (
|
||||||
// ErrIncludedTaskfilesCantHaveIncludes is returned when a included Taskfile contains includes
|
// ErrIncludedTaskfilesCantHaveIncludes is returned when a included Taskfile contains includes
|
||||||
ErrIncludedTaskfilesCantHaveIncludes = errors.New("task: Included Taskfiles can't have includes. Please, move the include to the main Taskfile")
|
ErrIncludedTaskfilesCantHaveIncludes = errors.New("task: Included Taskfiles can't have includes. Please, move the include to the main Taskfile")
|
||||||
|
|
||||||
// ErrNoTaskfileFound is returned when Taskfile.yml is not found
|
|
||||||
ErrNoTaskfileFound = errors.New(`task: No Taskfile.yml found. Use "task --init" to create a new one`)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Taskfile reads a Taskfile for a given directory
|
// Taskfile reads a Taskfile for a given directory
|
||||||
func Taskfile(dir string) (*taskfile.Taskfile, error) {
|
func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
|
||||||
path := filepath.Join(dir, "Taskfile.yml")
|
path := filepath.Join(dir, entrypoint)
|
||||||
if _, err := os.Stat(path); err != nil {
|
if _, err := os.Stat(path); err != nil {
|
||||||
return nil, ErrNoTaskfileFound
|
return nil, fmt.Errorf(`task: No Taskfile found on "%s". Use "task --init" to create a new one`, path)
|
||||||
}
|
}
|
||||||
t, err := readTaskfile(path)
|
t, err := readTaskfile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,19 +5,20 @@ type Tasks map[string]*Task
|
|||||||
|
|
||||||
// Task represents a task
|
// Task represents a task
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Task string
|
Task string
|
||||||
Cmds []*Cmd
|
Cmds []*Cmd
|
||||||
Deps []*Dep
|
Deps []*Dep
|
||||||
Desc string
|
Desc string
|
||||||
Summary string
|
Summary string
|
||||||
Sources []string
|
Sources []string
|
||||||
Generates []string
|
Generates []string
|
||||||
Status []string
|
Status []string
|
||||||
Dir string
|
Preconditions []*Precondition
|
||||||
Vars Vars
|
Dir string
|
||||||
Env Vars
|
Vars Vars
|
||||||
Silent bool
|
Env Vars
|
||||||
Method string
|
Silent bool
|
||||||
Prefix string
|
Method string
|
||||||
IgnoreError bool `yaml:"ignore_error"`
|
Prefix string
|
||||||
|
IgnoreError bool `yaml:"ignore_error"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,5 +40,8 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
if tf.Expansions <= 0 {
|
if tf.Expansions <= 0 {
|
||||||
tf.Expansions = 2
|
tf.Expansions = 2
|
||||||
}
|
}
|
||||||
|
if tf.Vars == nil {
|
||||||
|
tf.Vars = make(Vars)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package version
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/Masterminds/semver"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
v1 = mustVersion("1")
|
|
||||||
v2 = mustVersion("2")
|
|
||||||
v21 = mustVersion("2.1")
|
|
||||||
v22 = mustVersion("2.2")
|
|
||||||
v23 = mustVersion("2.3")
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsV1 returns if is a given Taskfile version is version 1
|
|
||||||
func IsV1(v *semver.Constraints) bool {
|
|
||||||
return v.Check(v1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsV2 returns if is a given Taskfile version is at least version 2
|
|
||||||
func IsV2(v *semver.Constraints) bool {
|
|
||||||
return v.Check(v2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsV21 returns if is a given Taskfile version is at least version 2.1
|
|
||||||
func IsV21(v *semver.Constraints) bool {
|
|
||||||
return v.Check(v21)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsV22 returns if is a given Taskfile version is at least version 2.2
|
|
||||||
func IsV22(v *semver.Constraints) bool {
|
|
||||||
return v.Check(v22)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsV23 returns if is a given Taskfile version is at least version 2.3
|
|
||||||
func IsV23(v *semver.Constraints) bool {
|
|
||||||
return v.Check(v23)
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustVersion(s string) *semver.Version {
|
|
||||||
v, err := semver.NewVersion(s)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
31
precondition.go
Normal file
31
precondition.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/go-task/task/v2/internal/execext"
|
||||||
|
"github.com/go-task/task/v2/internal/taskfile"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrPreconditionFailed is returned when a precondition fails
|
||||||
|
ErrPreconditionFailed = errors.New("task: precondition not met")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (e *Executor) areTaskPreconditionsMet(ctx context.Context, t *taskfile.Task) (bool, error) {
|
||||||
|
for _, p := range t.Preconditions {
|
||||||
|
err := execext.RunCommand(ctx, &execext.RunCommandOptions{
|
||||||
|
Command: p.Sh,
|
||||||
|
Dir: t.Dir,
|
||||||
|
Env: getEnviron(t),
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Errf("task: %s", p.Msg)
|
||||||
|
return false, ErrPreconditionFailed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
11
status.go
11
status.go
@@ -58,10 +58,11 @@ func (e *Executor) getStatusChecker(t *taskfile.Task) (status.Checker, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
case "checksum":
|
case "checksum":
|
||||||
return &status.Checksum{
|
return &status.Checksum{
|
||||||
Dir: t.Dir,
|
Dir: t.Dir,
|
||||||
Task: t.Task,
|
Task: t.Task,
|
||||||
Sources: t.Sources,
|
Sources: t.Sources,
|
||||||
Dry: e.Dry,
|
Generates: t.Generates,
|
||||||
|
Dry: e.Dry,
|
||||||
}, nil
|
}, nil
|
||||||
case "none":
|
case "none":
|
||||||
return status.None{}, nil
|
return status.None{}, nil
|
||||||
@@ -78,8 +79,10 @@ func (e *Executor) isTaskUpToDateStatus(ctx context.Context, t *taskfile.Task) (
|
|||||||
Env: getEnviron(t),
|
Env: getEnviron(t),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
e.Logger.VerboseOutf("task: status command %s exited non-zero: %s", s, err)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
e.Logger.VerboseOutf("task: status command %s exited zero", s)
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
117
task.go
117
task.go
@@ -2,9 +2,12 @@ package task
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/go-task/task/v2/internal/compiler"
|
"github.com/go-task/task/v2/internal/compiler"
|
||||||
@@ -16,9 +19,7 @@ import (
|
|||||||
"github.com/go-task/task/v2/internal/summary"
|
"github.com/go-task/task/v2/internal/summary"
|
||||||
"github.com/go-task/task/v2/internal/taskfile"
|
"github.com/go-task/task/v2/internal/taskfile"
|
||||||
"github.com/go-task/task/v2/internal/taskfile/read"
|
"github.com/go-task/task/v2/internal/taskfile/read"
|
||||||
"github.com/go-task/task/v2/internal/taskfile/version"
|
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,13 +32,15 @@ const (
|
|||||||
// Executor executes a Taskfile
|
// Executor executes a Taskfile
|
||||||
type Executor struct {
|
type Executor struct {
|
||||||
Taskfile *taskfile.Taskfile
|
Taskfile *taskfile.Taskfile
|
||||||
Dir string
|
|
||||||
Force bool
|
Dir string
|
||||||
Watch bool
|
Entrypoint string
|
||||||
Verbose bool
|
Force bool
|
||||||
Silent bool
|
Watch bool
|
||||||
Dry bool
|
Verbose bool
|
||||||
Summary bool
|
Silent bool
|
||||||
|
Dry bool
|
||||||
|
Summary bool
|
||||||
|
|
||||||
Stdin io.Reader
|
Stdin io.Reader
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
@@ -51,6 +54,7 @@ type Executor struct {
|
|||||||
taskvars taskfile.Vars
|
taskvars taskfile.Vars
|
||||||
|
|
||||||
taskCallCount map[string]*int32
|
taskCallCount map[string]*int32
|
||||||
|
mkdirMutexMap map[string]*sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs Task
|
// Run runs Task
|
||||||
@@ -83,8 +87,12 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
|
|||||||
|
|
||||||
// Setup setups Executor's internal state
|
// Setup setups Executor's internal state
|
||||||
func (e *Executor) Setup() error {
|
func (e *Executor) Setup() error {
|
||||||
|
if e.Entrypoint == "" {
|
||||||
|
e.Entrypoint = "Taskfile.yml"
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
e.Taskfile, err = read.Taskfile(e.Dir)
|
e.Taskfile, err = read.Taskfile(e.Dir, e.Entrypoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -93,11 +101,6 @@ func (e *Executor) Setup() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
v, err := semver.NewConstraint(e.Taskfile.Version)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf(`task: could not parse taskfile version "%s": %v`, e.Taskfile.Version, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.Stdin == nil {
|
if e.Stdin == nil {
|
||||||
e.Stdin = os.Stdin
|
e.Stdin = os.Stdin
|
||||||
}
|
}
|
||||||
@@ -112,14 +115,30 @@ func (e *Executor) Setup() error {
|
|||||||
Stderr: e.Stderr,
|
Stderr: e.Stderr,
|
||||||
Verbose: e.Verbose,
|
Verbose: e.Verbose,
|
||||||
}
|
}
|
||||||
switch {
|
|
||||||
case version.IsV1(v):
|
v, err := strconv.ParseFloat(e.Taskfile.Version, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf(`task: Could not parse taskfile version "%s": %v`, e.Taskfile.Version, err)
|
||||||
|
}
|
||||||
|
// consider as equal to the greater version if round
|
||||||
|
if v == 2.0 {
|
||||||
|
v = 2.6
|
||||||
|
}
|
||||||
|
|
||||||
|
if v < 1 {
|
||||||
|
return fmt.Errorf(`task: Taskfile version should be greater or equal to v1`)
|
||||||
|
}
|
||||||
|
if v > 2.6 {
|
||||||
|
return fmt.Errorf(`task: Taskfile versions greater than v2.6 not implemented in the version of Task`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v < 2 {
|
||||||
e.Compiler = &compilerv1.CompilerV1{
|
e.Compiler = &compilerv1.CompilerV1{
|
||||||
Dir: e.Dir,
|
Dir: e.Dir,
|
||||||
Vars: e.taskvars,
|
Vars: e.taskvars,
|
||||||
Logger: e.Logger,
|
Logger: e.Logger,
|
||||||
}
|
}
|
||||||
case version.IsV2(v), version.IsV21(v), version.IsV22(v):
|
} else { // v >= 2
|
||||||
e.Compiler = &compilerv2.CompilerV2{
|
e.Compiler = &compilerv2.CompilerV2{
|
||||||
Dir: e.Dir,
|
Dir: e.Dir,
|
||||||
Taskvars: e.taskvars,
|
Taskvars: e.taskvars,
|
||||||
@@ -127,16 +146,15 @@ func (e *Executor) Setup() error {
|
|||||||
Expansions: e.Taskfile.Expansions,
|
Expansions: e.Taskfile.Expansions,
|
||||||
Logger: e.Logger,
|
Logger: e.Logger,
|
||||||
}
|
}
|
||||||
case version.IsV23(v):
|
|
||||||
return fmt.Errorf(`task: Taskfile versions greater than v2.3 not implemented in the version of Task`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !version.IsV21(v) && e.Taskfile.Output != "" {
|
if v < 2.1 && e.Taskfile.Output != "" {
|
||||||
return fmt.Errorf(`task: Taskfile option "output" is only available starting on Taskfile version v2.1`)
|
return fmt.Errorf(`task: Taskfile option "output" is only available starting on Taskfile version v2.1`)
|
||||||
}
|
}
|
||||||
if !version.IsV22(v) && len(e.Taskfile.Includes) > 0 {
|
if v < 2.2 && len(e.Taskfile.Includes) > 0 {
|
||||||
return fmt.Errorf(`task: Including Taskfiles is only available starting on Taskfile version v2.2`)
|
return fmt.Errorf(`task: Including Taskfiles is only available starting on Taskfile version v2.2`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.OutputStyle != "" {
|
if e.OutputStyle != "" {
|
||||||
e.Taskfile.Output = e.OutputStyle
|
e.Taskfile.Output = e.OutputStyle
|
||||||
}
|
}
|
||||||
@@ -151,8 +169,8 @@ func (e *Executor) Setup() error {
|
|||||||
return fmt.Errorf(`task: output option "%s" not recognized`, e.Taskfile.Output)
|
return fmt.Errorf(`task: output option "%s" not recognized`, e.Taskfile.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !version.IsV21(v) {
|
if v <= 2.1 {
|
||||||
err := fmt.Errorf(`task: Taskfile option "ignore_error" is only available starting on Taskfile version v2.1`)
|
err := errors.New(`task: Taskfile option "ignore_error" is only available starting on Taskfile version v2.1`)
|
||||||
|
|
||||||
for _, task := range e.Taskfile.Tasks {
|
for _, task := range e.Taskfile.Tasks {
|
||||||
if task.IgnoreError {
|
if task.IgnoreError {
|
||||||
@@ -166,9 +184,19 @@ func (e *Executor) Setup() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v < 2.6 {
|
||||||
|
for _, task := range e.Taskfile.Tasks {
|
||||||
|
if len(task.Preconditions) > 0 {
|
||||||
|
return errors.New(`task: Task option "preconditions" is only available starting on Taskfile version v2.6`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks))
|
e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks))
|
||||||
|
e.mkdirMutexMap = make(map[string]*sync.Mutex, len(e.Taskfile.Tasks))
|
||||||
for k := range e.Taskfile.Tasks {
|
for k := range e.Taskfile.Tasks {
|
||||||
e.taskCallCount[k] = new(int32)
|
e.taskCallCount[k] = new(int32)
|
||||||
|
e.mkdirMutexMap[k] = &sync.Mutex{}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -188,11 +216,17 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !e.Force {
|
if !e.Force {
|
||||||
|
preCondMet, err := e.areTaskPreconditionsMet(ctx, t)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
upToDate, err := e.isTaskUpToDate(ctx, t)
|
upToDate, err := e.isTaskUpToDate(ctx, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if upToDate {
|
|
||||||
|
if upToDate && preCondMet {
|
||||||
if !e.Silent {
|
if !e.Silent {
|
||||||
e.Logger.Errf(`task: Task "%s" is up to date`, t.Task)
|
e.Logger.Errf(`task: Task "%s" is up to date`, t.Task)
|
||||||
}
|
}
|
||||||
@@ -200,6 +234,10 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := e.mkdir(t); err != nil {
|
||||||
|
e.Logger.Errf("task: cannot make directory %q: %v", t.Dir, err)
|
||||||
|
}
|
||||||
|
|
||||||
for i := range t.Cmds {
|
for i := range t.Cmds {
|
||||||
if err := e.runCommand(ctx, t, call, i); err != nil {
|
if err := e.runCommand(ctx, t, call, i); err != nil {
|
||||||
if err2 := e.statusOnError(t); err2 != nil {
|
if err2 := e.statusOnError(t); err2 != nil {
|
||||||
@@ -217,6 +255,23 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Executor) mkdir(t *taskfile.Task) error {
|
||||||
|
if t.Dir == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex := e.mkdirMutexMap[t.Task]
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
|
|
||||||
|
if _, err := os.Stat(t.Dir); os.IsNotExist(err) {
|
||||||
|
if err := os.MkdirAll(t.Dir, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Executor) runDeps(ctx context.Context, t *taskfile.Task) error {
|
func (e *Executor) runDeps(ctx context.Context, t *taskfile.Task) error {
|
||||||
g, ctx := errgroup.WithContext(ctx)
|
g, ctx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
@@ -224,7 +279,11 @@ func (e *Executor) runDeps(ctx context.Context, t *taskfile.Task) error {
|
|||||||
d := d
|
d := d
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return e.RunTask(ctx, taskfile.Call{Task: d.Task, Vars: d.Vars})
|
err := e.RunTask(ctx, taskfile.Call{Task: d.Task, Vars: d.Vars})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,7 +295,11 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case cmd.Task != "":
|
case cmd.Task != "":
|
||||||
return e.RunTask(ctx, taskfile.Call{Task: cmd.Task, Vars: cmd.Vars})
|
err := e.RunTask(ctx, taskfile.Call{Task: cmd.Task, Vars: cmd.Vars})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
case cmd.Cmd != "":
|
case cmd.Cmd != "":
|
||||||
if e.Verbose || (!cmd.Silent && !t.Silent && !e.Silent) {
|
if e.Verbose || (!cmd.Silent && !t.Silent && !e.Silent) {
|
||||||
e.Logger.Errf(cmd.Cmd)
|
e.Logger.Errf(cmd.Cmd)
|
||||||
|
|||||||
136
task_test.go
136
task_test.go
@@ -7,13 +7,13 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-task/task/v2"
|
"github.com/go-task/task/v2"
|
||||||
"github.com/go-task/task/v2/internal/taskfile"
|
"github.com/go-task/task/v2/internal/taskfile"
|
||||||
|
|
||||||
"github.com/mitchellh/go-homedir"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ func TestDeps(t *testing.T) {
|
|||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
f = filepath.Join(dir, f)
|
f = filepath.Join(dir, f)
|
||||||
if _, err := os.Stat(f); err != nil {
|
if _, err := os.Stat(f); err != nil {
|
||||||
t.Errorf("File %s should exists", f)
|
t.Errorf("File %s should exist", f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ func TestStatus(t *testing.T) {
|
|||||||
_ = os.Remove(file)
|
_ = os.Remove(file)
|
||||||
|
|
||||||
if _, err := os.Stat(file); err == nil {
|
if _, err := os.Stat(file); err == nil {
|
||||||
t.Errorf("File should not exists: %v", err)
|
t.Errorf("File should not exist: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
@@ -262,7 +262,7 @@ func TestStatus(t *testing.T) {
|
|||||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-foo"}))
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-foo"}))
|
||||||
|
|
||||||
if _, err := os.Stat(file); err != nil {
|
if _, err := os.Stat(file); err != nil {
|
||||||
t.Errorf("File should exists: %v", err)
|
t.Errorf("File should exist: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Silent = false
|
e.Silent = false
|
||||||
@@ -273,6 +273,47 @@ func TestStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrecondition(t *testing.T) {
|
||||||
|
const dir = "testdata/precondition"
|
||||||
|
|
||||||
|
var buff bytes.Buffer
|
||||||
|
e := &task.Executor{
|
||||||
|
Dir: dir,
|
||||||
|
Stdout: &buff,
|
||||||
|
Stderr: &buff,
|
||||||
|
}
|
||||||
|
|
||||||
|
// A precondition that has been met
|
||||||
|
assert.NoError(t, e.Setup())
|
||||||
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
|
||||||
|
if buff.String() != "" {
|
||||||
|
t.Errorf("Got Output when none was expected: %s", buff.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// A precondition that was not met
|
||||||
|
assert.Error(t, e.Run(context.Background(), taskfile.Call{Task: "impossible"}))
|
||||||
|
|
||||||
|
if buff.String() != "task: 1 != 0 obviously!\n" {
|
||||||
|
t.Errorf("Wrong output message: %s", buff.String())
|
||||||
|
}
|
||||||
|
buff.Reset()
|
||||||
|
|
||||||
|
// Calling a task with a precondition in a dependency fails the task
|
||||||
|
assert.Error(t, e.Run(context.Background(), taskfile.Call{Task: "depends_on_impossible"}))
|
||||||
|
|
||||||
|
if buff.String() != "task: 1 != 0 obviously!\n" {
|
||||||
|
t.Errorf("Wrong output message: %s", buff.String())
|
||||||
|
}
|
||||||
|
buff.Reset()
|
||||||
|
|
||||||
|
// Calling a task with a precondition in a cmd fails the task
|
||||||
|
assert.Error(t, e.Run(context.Background(), taskfile.Call{Task: "executes_failing_task_as_cmd"}))
|
||||||
|
if buff.String() != "task: 1 != 0 obviously!\n" {
|
||||||
|
t.Errorf("Wrong output message: %s", buff.String())
|
||||||
|
}
|
||||||
|
buff.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
func TestGenerates(t *testing.T) {
|
func TestGenerates(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
srcTask = "sub/src.txt"
|
srcTask = "sub/src.txt"
|
||||||
@@ -290,7 +331,7 @@ func TestGenerates(t *testing.T) {
|
|||||||
path := filepath.Join(dir, task)
|
path := filepath.Join(dir, task)
|
||||||
_ = os.Remove(path)
|
_ = os.Remove(path)
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
t.Errorf("File should not exists: %v", err)
|
t.Errorf("File should not exist: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,10 +352,10 @@ func TestGenerates(t *testing.T) {
|
|||||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: theTask}))
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: theTask}))
|
||||||
|
|
||||||
if _, err := os.Stat(srcFile); err != nil {
|
if _, err := os.Stat(srcFile); err != nil {
|
||||||
t.Errorf("File should exists: %v", err)
|
t.Errorf("File should exist: %v", err)
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(destFile); err != nil {
|
if _, err := os.Stat(destFile); err != nil {
|
||||||
t.Errorf("File should exists: %v", err)
|
t.Errorf("File should exist: %v", err)
|
||||||
}
|
}
|
||||||
// Ensure task was not incorrectly found to be up-to-date on first run.
|
// Ensure task was not incorrectly found to be up-to-date on first run.
|
||||||
if buff.String() == upToDate {
|
if buff.String() == upToDate {
|
||||||
@@ -371,7 +412,7 @@ func TestInit(t *testing.T) {
|
|||||||
|
|
||||||
_ = os.Remove(file)
|
_ = os.Remove(file)
|
||||||
if _, err := os.Stat(file); err == nil {
|
if _, err := os.Stat(file); err == nil {
|
||||||
t.Errorf("Taskfile.yml should not exists")
|
t.Errorf("Taskfile.yml should not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.InitTaskfile(ioutil.Discard, dir); err != nil {
|
if err := task.InitTaskfile(ioutil.Discard, dir); err != nil {
|
||||||
@@ -379,7 +420,7 @@ func TestInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(file); err != nil {
|
if _, err := os.Stat(file); err != nil {
|
||||||
t.Errorf("Taskfile.yml should exists")
|
t.Errorf("Taskfile.yml should exist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,7 +478,7 @@ func TestTaskIgnoreErrors(t *testing.T) {
|
|||||||
func TestExpand(t *testing.T) {
|
func TestExpand(t *testing.T) {
|
||||||
const dir = "testdata/expand"
|
const dir = "testdata/expand"
|
||||||
|
|
||||||
home, err := homedir.Dir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Couldn't get $HOME: %v", err)
|
t.Errorf("Couldn't get $HOME: %v", err)
|
||||||
}
|
}
|
||||||
@@ -567,11 +608,76 @@ func TestSummary(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.NoError(t, e.Setup())
|
assert.NoError(t, e.Setup())
|
||||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary"}, taskfile.Call{Task: "other-task-with-summary"}))
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary"}, taskfile.Call{Task: "other-task-with-summary"}))
|
||||||
assert.Equal(t, readTestFixture(t, dir, "task-with-summary.txt"), buff.String())
|
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(dir, "task-with-summary.txt"))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
expectedOutput := string(data)
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
expectedOutput = strings.Replace(expectedOutput, "\r\n", "\n", -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, expectedOutput, buff.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func readTestFixture(t *testing.T, dir string, file string) string {
|
func TestWhenNoDirAttributeItRunsInSameDirAsTaskfile(t *testing.T) {
|
||||||
b, err := ioutil.ReadFile(dir + "/" + file)
|
const expected = "dir"
|
||||||
assert.NoError(t, err, "error reading text fixture")
|
const dir = "testdata/" + expected
|
||||||
return string(b)
|
var out bytes.Buffer
|
||||||
|
e := &task.Executor{
|
||||||
|
Dir: dir,
|
||||||
|
Stdout: &out,
|
||||||
|
Stderr: &out,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, e.Setup())
|
||||||
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "whereami"}))
|
||||||
|
|
||||||
|
// got should be the "dir" part of "testdata/dir"
|
||||||
|
got := strings.TrimSuffix(filepath.Base(out.String()), "\n")
|
||||||
|
assert.Equal(t, expected, got, "Mismatch in the working directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWhenDirAttributeAndDirExistsItRunsInThatDir(t *testing.T) {
|
||||||
|
const expected = "exists"
|
||||||
|
const dir = "testdata/dir/explicit_exists"
|
||||||
|
var out bytes.Buffer
|
||||||
|
e := &task.Executor{
|
||||||
|
Dir: dir,
|
||||||
|
Stdout: &out,
|
||||||
|
Stderr: &out,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, e.Setup())
|
||||||
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "whereami"}))
|
||||||
|
|
||||||
|
got := strings.TrimSuffix(filepath.Base(out.String()), "\n")
|
||||||
|
assert.Equal(t, expected, got, "Mismatch in the working directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWhenDirAttributeItCreatesMissingAndRunsInThatDir(t *testing.T) {
|
||||||
|
const expected = "createme"
|
||||||
|
const dir = "testdata/dir/explicit_doesnt_exist/"
|
||||||
|
const toBeCreated = dir + expected
|
||||||
|
const target = "whereami"
|
||||||
|
var out bytes.Buffer
|
||||||
|
e := &task.Executor{
|
||||||
|
Dir: dir,
|
||||||
|
Stdout: &out,
|
||||||
|
Stderr: &out,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that the directory to be created doesn't actually exist.
|
||||||
|
_ = os.Remove(toBeCreated)
|
||||||
|
if _, err := os.Stat(toBeCreated); err == nil {
|
||||||
|
t.Errorf("Directory should not exist: %v", err)
|
||||||
|
}
|
||||||
|
assert.NoError(t, e.Setup())
|
||||||
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: target}))
|
||||||
|
|
||||||
|
got := strings.TrimSuffix(filepath.Base(out.String()), "\n")
|
||||||
|
assert.Equal(t, expected, got, "Mismatch in the working directory")
|
||||||
|
|
||||||
|
// Clean-up after ourselves only if no error.
|
||||||
|
_ = os.Remove(toBeCreated)
|
||||||
}
|
}
|
||||||
|
|||||||
7
testdata/dir/Taskfile.yml
vendored
Normal file
7
testdata/dir/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
whereami:
|
||||||
|
cmds:
|
||||||
|
- pwd
|
||||||
|
silent: true
|
||||||
8
testdata/dir/explicit_doesnt_exist/Taskfile.yml
vendored
Normal file
8
testdata/dir/explicit_doesnt_exist/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
whereami:
|
||||||
|
dir: createme
|
||||||
|
cmds:
|
||||||
|
- pwd
|
||||||
|
silent: true
|
||||||
8
testdata/dir/explicit_exists/Taskfile.yml
vendored
Normal file
8
testdata/dir/explicit_exists/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
whereami:
|
||||||
|
dir: exists
|
||||||
|
cmds:
|
||||||
|
- pwd
|
||||||
|
silent: true
|
||||||
0
testdata/dir/explicit_exists/exists/.keep
vendored
Normal file
0
testdata/dir/explicit_exists/exists/.keep
vendored
Normal file
19
testdata/precondition/Taskfile.yml
vendored
Normal file
19
testdata/precondition/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
foo:
|
||||||
|
preconditions:
|
||||||
|
- test -f foo.txt
|
||||||
|
|
||||||
|
impossible:
|
||||||
|
preconditions:
|
||||||
|
- sh: "[ 1 = 0 ]"
|
||||||
|
msg: "1 != 0 obviously!"
|
||||||
|
|
||||||
|
depends_on_impossible:
|
||||||
|
deps:
|
||||||
|
- impossible
|
||||||
|
|
||||||
|
executes_failing_task_as_cmd:
|
||||||
|
cmds:
|
||||||
|
- task: impossible
|
||||||
0
testdata/precondition/foo.txt
vendored
Normal file
0
testdata/precondition/foo.txt
vendored
Normal file
10
variables.go
10
variables.go
@@ -84,5 +84,15 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(origTask.Preconditions) > 0 {
|
||||||
|
new.Preconditions = make([]*taskfile.Precondition, len(origTask.Preconditions))
|
||||||
|
for i, precond := range origTask.Preconditions {
|
||||||
|
new.Preconditions[i] = &taskfile.Precondition{
|
||||||
|
Sh: r.Replace(precond.Sh),
|
||||||
|
Msg: r.Replace(precond.Msg),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &new, r.Err()
|
return &new, r.Err()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user