Skip to content

Commit

Permalink
Merge pull request #130 from dogtools/v0.5
Browse files Browse the repository at this point in the history
New version v0.5
  • Loading branch information
xsb authored May 18, 2018
2 parents a8b1169 + be3a7d4 commit b40e61b
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 321 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
language: go

go:
- 1.7.x
- tip
- 1.10.x

install:
- go get -t ./...
- go get github.com/client9/misspell/cmd/misspell
- go get github.com/golang/lint/golint
- go get honnef.co/go/staticcheck/cmd/staticcheck
- go get honnef.co/go/tools/cmd/staticcheck
- go get github.com/kisielk/errcheck

script:
Expand Down
30 changes: 14 additions & 16 deletions DOGFILE_SPEC.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Dogfile Spec
# Dogfile Specification

*NOTE: This document is a draft and will probably change in the future. Most of its content is still open to discussion.*

[Dog](https://github.com/dogtools/dog) is the first tool that uses Dogfiles and is developed at the same time as the Dogfile Spec itself.
[Dog](https://github.com/dogtools/dog) is the first tool that uses a Dogfile and is developed at the same time as the Dogfile specification itself.

## File Format

Expand All @@ -18,7 +18,7 @@ Dogfiles are [YAML](http://yaml.org/) files that describe the execution of autom
code: echo bye
```
Multiple Dogfiles in the same directory are processed together as a single entity. Although the name `Dogfile.yml` is recommended, any file with a name that starts with `Dogfile` and follows this specification is a valid Dogfile.
Multiple Dogfiles in the same directory are processed together as a single entity. Although the name `dog.yml` is recommended, any file with a name that starts with `dog` and ends with `.yml` or `.yaml` is a valid Dogfile as long as it follows this specification.

## Task definition

Expand Down Expand Up @@ -54,33 +54,31 @@ Multiline scripts are supported.
code: |
echo "This is the Dogfile in your current directory:"
for dogfile in `ls -1 Dogfile*`; do
for dogfile in `ls -1 dog*yml`; do
cat $dogfile
done
```

### runner

When this directive is not defined, the default runner is `sh`. Additional runners are supported if they are present in the system. The following example uses the Ruby runner to print 'Hello World'.
When this directive is not defined, the default runner is `sh`. Additional runners are supported if they are present in the system. The following example uses the Bash runner to print 'Hello World'.

```yml
- task: hello-ruby
description: Hello World from Ruby
runner: ruby
- task: bash-loop
description: For loop ion Bash
runner: bash
code: |
hello = "Hello World"
puts hello
# this code includes a bashism may fail in some
# systems with a standard implementation of sh
for ((i=0; i<3; i++)); do
echo "$i"
done
```
The following list of runners are supported:
- sh
- bash
- python
- ruby
- perl
- nodejs
- go
### pre
Expand Down Expand Up @@ -117,7 +115,7 @@ Arrays are also accepted for multi task post-hooks.
### workdir
Sets the working directory for the task. Relative paths are considered relative to the location of the Dogfile.
Sets the working directory for the task. Relative paths are considered relative to the location of the Dogfile. The default workdir is the Dogfile location.
```yml
workdir: ./app/
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Dog

Dog is a command line application that executes automated tasks. It works in a similar way as GNU Make but it is a more generic task runner, not a build tool. Dog's default script syntax is `sh` but most interpreted languages like BASH, Python or Ruby can also be used.
Dog is a command line application that executes automated tasks.

## Using Dog

Expand All @@ -28,9 +28,9 @@ Execute a task, printing elapsed time and exit status

## What is a Dogfile?

Dogfile is a specification that uses YAML to describe the tasks related to a project. We think that the Spec will be finished (no further breaking changes) by the v1.0.0 version of Dog.
Dogfile is a specification that uses YAML to describe the tasks related to a project. We think that the specification will be finished (no further breaking changes) by the v1.0.0 version of Dog.

- Read Dog's own [Dogfile.yml][1]
- Read Dog's own [dog.yml][1]
- Read the [Dogfile Spec][2]

## Installing Dog
Expand Down Expand Up @@ -58,7 +58,7 @@ Check the `examples/` directory to see how it works.

If you want to help, take a look at the open [bugs][3], the list of all [issues][4] and our [Code of Conduct][5].

[1]: https://github.com/dogtools/dog/blob/master/Dogfile.yml
[1]: https://github.com/dogtools/dog/blob/master/dog.yml
[2]: https://github.com/dogtools/dog/blob/master/DOGFILE_SPEC.md
[3]: https://github.com/dogtools/dog/issues?q=is%3Aissue+is%3Aopen+label%3Abug
[4]: https://github.com/dogtools/dog/issues
Expand Down
32 changes: 13 additions & 19 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/dogtools/dog/run"
)

// ProvideExtraInfo specifies if dog needs to provide execution info (duration,
// exit status) after task execution.
var ProvideExtraInfo bool

// ErrCycleInTaskChain means that there is a loop in the path of tasks execution.
var ErrCycleInTaskChain = errors.New("TaskChain includes a cycle of tasks")

Expand All @@ -22,8 +26,8 @@ type TaskChain struct {
}

// NewTaskChain creates the task chain for a specific dogfile and task.
func NewTaskChain(d Dogfile, task string) (taskChain TaskChain, err error) {
err = taskChain.generate(d, task)
func NewTaskChain(dtasks Dogtasks, task string) (taskChain TaskChain, err error) {
err = taskChain.generate(dtasks, task)
if err != nil {
return
}
Expand All @@ -32,9 +36,9 @@ func NewTaskChain(d Dogfile, task string) (taskChain TaskChain, err error) {

// Generate recursively iterates over all tasks, including pre and post tasks for
// each of them, and adds all of them into a task chain.
func (taskChain *TaskChain) generate(d Dogfile, task string) error {
func (taskChain *TaskChain) generate(dtasks Dogtasks, task string) error {

t, found := d.Tasks[task]
t, found := dtasks.Tasks[task]
if !found {
return fmt.Errorf("Task %q does not exist", task)
}
Expand All @@ -49,30 +53,30 @@ func (taskChain *TaskChain) generate(d Dogfile, task string) error {
}

// Iterate over pre-tasks
if err := addToChain(taskChain, d, t.Pre); err != nil {
if err := addToChain(taskChain, dtasks, t.Pre); err != nil {
return err
}

// Add current task to chain
taskChain.Tasks = append(taskChain.Tasks, *t)

// Iterate over post-tasks
if err := addToChain(taskChain, d, t.Post); err != nil {
if err := addToChain(taskChain, dtasks, t.Post); err != nil {
return err
}
return nil
}

// addToChain adds found tasks into the task chain.
func addToChain(taskChain *TaskChain, d Dogfile, tasks []string) error {
func addToChain(taskChain *TaskChain, dtasks Dogtasks, tasks []string) error {
for _, name := range tasks {

t, found := d.Tasks[name]
t, found := dtasks.Tasks[name]
if !found {
return fmt.Errorf("Task %q does not exist", name)
}

if err := taskChain.generate(d, t.Name); err != nil {
if err := taskChain.generate(dtasks, t.Name); err != nil {
return err
}
}
Expand All @@ -97,16 +101,6 @@ func (taskChain *TaskChain) Run(stdout, stderr io.Writer) error {
runner, err = run.NewShRunner(t.Code, t.Workdir, env)
case "bash":
runner, err = run.NewBashRunner(t.Code, t.Workdir, env)
case "python":
runner, err = run.NewPythonRunner(t.Code, t.Workdir, env)
case "ruby":
runner, err = run.NewRubyRunner(t.Code, t.Workdir, env)
case "perl":
runner, err = run.NewPerlRunner(t.Code, t.Workdir, env)
case "nodejs":
runner, err = run.NewNodejsRunner(t.Code, t.Workdir, env)
case "go":
runner, err = run.NewGoRunner(t.Code, t.Workdir, env)
default:
if t.Runner == "" {
return errors.New("Runner not specified")
Expand Down
24 changes: 12 additions & 12 deletions chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestCycleDetection(t *testing.T) {
dogfile := Dogfile{
dtasks := Dogtasks{
Tasks: map[string]*Task{
"foo": {
Name: "foo",
Expand All @@ -24,13 +24,13 @@ func TestCycleDetection(t *testing.T) {
},
}

if _, err := NewTaskChain(dogfile, "foo"); err == nil {
if _, err := NewTaskChain(dtasks, "foo"); err == nil {
t.Errorf("Failed detecting a cycle in a task chain")
}
}

func TestRunTaskChain(t *testing.T) {
dogfile := Dogfile{
dtasks := Dogtasks{
Tasks: map[string]*Task{
"foo": {
Name: "foo",
Expand All @@ -41,7 +41,7 @@ func TestRunTaskChain(t *testing.T) {
},
}

taskChain, err := NewTaskChain(dogfile, "foo")
taskChain, err := NewTaskChain(dtasks, "foo")
if err != nil {
t.Fatalf("Failed generating a task chain: %v", err)
}
Expand All @@ -57,7 +57,7 @@ func TestRunTaskChain(t *testing.T) {
}

func TestRunTaskChainMustFail(t *testing.T) {
dogfile := Dogfile{
dtasks := Dogtasks{
Tasks: map[string]*Task{
"must-fail": {
Name: "must-fail",
Expand All @@ -68,7 +68,7 @@ func TestRunTaskChainMustFail(t *testing.T) {
},
}

taskChain, err := NewTaskChain(dogfile, "must-fail")
taskChain, err := NewTaskChain(dtasks, "must-fail")
if err != nil {
t.Fatalf("Failed generating a task chain: %v", err)
}
Expand All @@ -79,7 +79,7 @@ func TestRunTaskChainMustFail(t *testing.T) {
}

func TestRunTaskChainMultipleHooks(t *testing.T) {
dogfile := Dogfile{
dtasks := Dogtasks{
Tasks: map[string]*Task{
"pre-task": {
Name: "pre-task",
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestRunTaskChainMultipleHooks(t *testing.T) {
},
}

taskChain, err := NewTaskChain(dogfile, "main")
taskChain, err := NewTaskChain(dtasks, "main")
if err != nil {
t.Fatalf("Failed generating a task chain: %v", err)
}
Expand All @@ -126,7 +126,7 @@ func TestRunTaskChainMultipleHooks(t *testing.T) {
}

func TestRunTaskChainNoRunner(t *testing.T) {
dogfile := Dogfile{
dtasks := Dogtasks{
Tasks: map[string]*Task{
"foo": {
Name: "foo",
Expand All @@ -136,7 +136,7 @@ func TestRunTaskChainNoRunner(t *testing.T) {
},
}

taskChain, err := NewTaskChain(dogfile, "foo")
taskChain, err := NewTaskChain(dtasks, "foo")
if err != nil {
t.Fatalf("Failed generating a task chain: %v", err)
}
Expand All @@ -147,7 +147,7 @@ func TestRunTaskChainNoRunner(t *testing.T) {
}

func TestRunTaskChainUnsupportedRunner(t *testing.T) {
dogfile := Dogfile{
dtasks := Dogtasks{
Tasks: map[string]*Task{
"foo": {
Name: "foo",
Expand All @@ -158,7 +158,7 @@ func TestRunTaskChainUnsupportedRunner(t *testing.T) {
},
}

taskChain, err := NewTaskChain(dogfile, "foo")
taskChain, err := NewTaskChain(dtasks, "foo")
if err != nil {
t.Fatalf("Failed generating a task chain: %v", err)
}
Expand Down
10 changes: 0 additions & 10 deletions cmd/dog/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "fmt"

type userArgs struct {
help bool
workdir string
directory string
version bool
info bool
Expand All @@ -15,7 +14,6 @@ type userArgs struct {

var knownFlags = [...]string{
"-i", "--info",
"-w", "--workdir",
"-h", "--help",
"-v", "--version",
"-d", "--directory",
Expand All @@ -34,7 +32,6 @@ func printHelp() {
Dog is a command line application that executes tasks.
Options:
-i, --info Print execution info (duration, exit status) after task execution
-w, --workdir Specify the working directory
-d, --directory Specify the dogfiles' directory
-h, --help Print usage information and help
-v, --version Print version information
Expand All @@ -52,7 +49,6 @@ func parseArgs(args []string) (a userArgs, err error) {
// default values
a = userArgs{
help: false,
workdir: "",
directory: "",
version: false,
info: false,
Expand Down Expand Up @@ -103,12 +99,6 @@ func parseArgs(args []string) (a userArgs, err error) {
}
}

if arg == "--workdir" || arg == "-w" {
next := i + 1
a.workdir = args[next]
skipArgument = true
}

if arg == "--directory" || arg == "-d" {
next := i + 1
a.directory = args[next]
Expand Down
Loading

0 comments on commit b40e61b

Please sign in to comment.