Skip to content

Commit

Permalink
Create dog and dog/run packages (#113)
Browse files Browse the repository at this point in the history
* Create dog and dog/run packages

* Add example exposing tasks through HTTP

* CombinedOutput returns an io.Reader

* Format error using fmt.Errorf

* Add error handling to ListenAndServe

* Typo

* Remove unnecessary string concatenation

* Revert "Remove unnecessary string concatenation"

This reverts commit ead3340.

* Fix unnecessary concatenation, improve code comment.

* Add fail if task does not exist at package level

* No need to declare timeMsg variable

* Run accepts two io.Writers to collect stdout and stderr separately

* Update examples, now passing stdout and stderr to Run()
  • Loading branch information
xsb authored Jan 30, 2017
1 parent a5435d7 commit 8b696fb
Show file tree
Hide file tree
Showing 34 changed files with 920 additions and 738 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
dog-*/
*tar.gz
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ go:
install:
- go get -t ./...
- go get github.com/golang/lint/golint
- go get honnef.co/go/staticcheck/cmd/staticcheck
- go get github.com/kisielk/errcheck

script:
- diff <(echo -n) <(gofmt -s -d .)
Expand All @@ -15,11 +17,5 @@ script:

after_script:
- golint ./...

notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/87d757f61554eae3d779
on_success: change
on_failure: always
on_start: never
- staticcheck ./...
- errcheck ./...
28 changes: 14 additions & 14 deletions DOGFILE_SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Dogfiles are [YAML](http://yaml.org/) files that describe the execution of autom
```yml
- task: hello
description: Say Hello
run: echo hello
code: echo hello

- task: bye
description: Say Good Bye
run: echo bye
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.
Expand All @@ -40,39 +40,39 @@ Description of the task. Tasks that avoid this directive are not shown in the ta
description: This task does some cool stuff
```

### run
### code

The code that will be executed.

```yml
run: echo 'hello'
code: echo 'hello'
```

Multiline scripts are supported.

```yml
run: |
code: |
echo "This is the Dogfile in your current directory:"
for dogfile in `ls -1 Dogfile*`; do
cat $dogfile
done
```

### exec
### runner

When this directive is not defined, the default executor is `sh`. Additional executors are supported if they are present in the system. The following example uses the Ruby executor 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 Ruby runner to print 'Hello World'.

```yml
task: hello-ruby
description: Hello World from Ruby
exec: ruby
run: |
runner: ruby
code: |
hello = "Hello World"
puts hello
```
The following list of executors are known to work:
The following list of runners are supported:
- sh
- bash
Expand Down Expand Up @@ -179,7 +179,7 @@ Additional parameters can be provided to the task that will be executed. All par
- name: age
regex: ^\d+$

run: echo "Hello, I'm in the city of $1, planet $2. I am a $3 and I'm $4 years old"
code: echo "Hello, I'm in the city of $1, planet $2. I am a $3 and I'm $4 years old"
```
The *regex* option and the *choices* option are mutually exclusive.
Expand All @@ -190,13 +190,13 @@ Registers store the STDOUT of executed tasks as environment variables so other t
```yml
task: get-dog-version
run: dog --version | awk '{print $3}'
code: dog --version | awk '{print $3}'
register: DOG_VERSION

task: print-dog-version
description: Print Dog version
pre: get-dog-version
run: echo "I am running Dog $DOG_VERSION"
code: echo "I am running Dog $DOG_VERSION"
```
Dogfiles don't have global variables, use registers instead.
Expand All @@ -210,7 +210,7 @@ Tools using Dogfiles and having special requirements can define their own direct
description: Clear the cache
x_path: /task/clear-cache
x_tls_required: true
run: ./scripts/cache-clear.sh
code: ./scripts/cache-clear.sh
```

(*) Not implemented yet
24 changes: 13 additions & 11 deletions Dogfile.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
- task: clean
description: Clean compiled binaries
run: rm -rf dist
code: rm -rf dist dog-*

- task: build
description: Build dog binary for current platform
env:
- OUTPUT_PATH=dist/current
- REV=v0.3.0
run: |
- REV=v0.4.0
code: |
go build \
-ldflags "-X main.Release=$REV -w" \
-o "${OUTPUT_PATH}/dog" \
.
cmd/dog/*.go
- task: install-build-deps
description: Installs required dependencies for building dog
run: go get -u github.com/mitchellh/gox
code: go get -u github.com/mitchellh/gox

- task: build-all
description: Build dog binary for all platforms
env:
- XC_ARCH=386 amd64
- XC_OS=linux darwin freebsd openbsd solaris
- REV=v0.3.0
- REV=v0.4.0
pre:
- install-build-deps
- clean
run: |
code: |
gox \
-os="${XC_OS}" \
-arch="${XC_ARCH}" \
-ldflags "-X main.Release=$REV -w" \
-output "dist/{{.OS}}_{{.Arch}}/dog" \
.
./cmd/dog/
- task: dist
description: Put all dist binaries in a compressed file
env: REV=v0.3.0
env: REV=v0.4.0
pre: build-all
run: tar zcvf dog-${REV}.tar.gz dist/
code: |
mv -v dist dog-${REV}
tar zcvf dog-${REV}.tar.gz dog-${REV}
- task: run-test-dogfiles
description: Run all Tasks in testdata Dogfiles
run: ./scripts/test-dogfiles.sh
code: ./scripts/test-dogfiles.sh
55 changes: 22 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
# Dog

[![Build Status](https://travis-ci.org/dogtools/dog.svg?branch=master)](https://travis-ci.org/dogtools/dog)
[![Join the chat](https://badges.gitter.im/dogtools/dog.svg)](https://gitter.im/dogtools/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, Ruby or Perl can also be used.

## Installing Dog

If you are on macOS you can install Dog using brew:

```
brew tap dogtools/dog
brew install dog
```

If you have your golang environment set up, you can use:

```
go get github.com/dogtools/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.

## Using Dog

Expand All @@ -30,7 +14,7 @@ Execute a task

dog taskname

Execute a task, printing elapsed time and status code
Execute a task, printing elapsed time and exit status

dog -i taskname

Expand All @@ -41,28 +25,33 @@ Dogfile is a specification that uses YAML to describe the tasks related to a pro
- Read Dog's own [Dogfile.yml][1]
- Read the [Dogfile Spec][2]

## Installing Dog

If you are using macOS you can install Dog using brew:

brew tap dogtools/dog
brew install dog

If you have your golang environment set up, you can use:

go get -u github.com/dogtools/dog

## Other tools

Tools that use Dogfiles are called *dogtools*. Dog is the first dogtool but there are other things that can implemented in the future: web and desktop UIs, chat bot interfaces, plugins for text editors and IDEs, tools to export Dogfiles to other formats, HTTP API interfaces, even implementations of the cli in other languages! To simplify the process of creating dogtools we are implementing parts of Dog as Go packages so they can be used in other projects (see [parser][3], [types][4] and [execute][5]). Let us know if you have any uncovered need on any of these packages.
Tools that use the Dogfile Specification are called *dogtools*. Dog is the first dogtool but there are other things that can be implemented in the future: web and desktop UIs, chat bot interfaces, plugins for text editors and IDEs, tools to export Dogfiles to other formats, HTTP API interfaces, even implementations of the cli in other languages!

## Contributing
The root directory of this repository contains the dog package that can be used to create dogtools in Go.

If you want to help, take a look at:
import "github.com/dogtools/dog"

- Open [bugs][6]
- Lacking features for [v0.4.0][7]
- Our [Code of Conduct][8]
Check the `examples/` directory to see how it works.

In case you are not interested in improving Dog but on building your own tool on top of the Dogfile Spec, please help us discussing it:
## Contributing

- Dogfile Spec [open discussion][9]
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
[2]: https://github.com/dogtools/dog/blob/master/DOGFILE_SPEC.md
[3]: https://github.com/dogtools/dog/tree/master/parser
[4]: https://github.com/dogtools/dog/tree/master/types
[5]: https://github.com/dogtools/dog/tree/master/execute
[6]: https://github.com/dogtools/dog/issues?q=is%3Aissue+is%3Aopen+label%3Abug
[7]: https://github.com/dogtools/dog/milestone/4
[8]: https://github.com/dogtools/dog/blob/master/CODE_OF_CONDUCT.md
[9]: https://github.com/dogtools/dog/issues?q=is%3Aissue+is%3Aopen+label%3A%22dogfile+spec%22
[3]: https://github.com/dogtools/dog/issues?q=is%3Aissue+is%3Aopen+label%3Abug
[4]: https://github.com/dogtools/dog/issues
[5]: https://github.com/dogtools/dog/blob/master/CODE_OF_CONDUCT.md
Loading

0 comments on commit 8b696fb

Please sign in to comment.