diff --git a/.cmdx.yaml b/.cmdx.yaml index bebb330..14d8802 100644 --- a/.cmdx.yaml +++ b/.cmdx.yaml @@ -47,3 +47,8 @@ tasks: description: buildflow run for test usage: buildflow run for test script: "go run ./cmd/buildflow run" +- name: test-example + short: te + description: test examples + usage: test examples + script: "bash scripts/test-example.sh" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f5c6310..c55ba09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: bash ci/test.sh buildflow - name: test examples run: | - bash ci/test-example.sh + bash scripts/test-example.sh - name: remove changes # Sometimes it is failed to release by goreleaser due to changes of go.sum diff --git a/.gitignore b/.gitignore index a094828..c96cf00 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin/* .git-rm-branch.yml .buildflow.yaml .envrc +examples/foo.txt diff --git a/README.md b/README.md index 2298313..d9f581c 100644 --- a/README.md +++ b/README.md @@ -538,6 +538,16 @@ phases: Please see [examples](https://github.com/suzuki-shunsuke/buildflow/tree/master/examples). +On the directory, there are some examples of configuration files. + +We can execute the build with them. + +For example, + +``` +$ buildflow run -c examples/hello_world.yaml +``` + ### Configuration variables - PR: [Response body of GitHub API: Get a pull request](https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#get-a-pull-request) diff --git a/ci/test-example.sh b/ci/test-example.sh deleted file mode 100644 index b0243cd..0000000 --- a/ci/test-example.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -cd "$(dirname "$0")/.." - -go build -o dist/buildflow ./cmd/buildflow -export PATH="$PWD/dist:$PATH" -cd examples -go test -race -covermode=atomic ./... -rm -R ../dist diff --git a/examples/import_phases.yaml b/examples/import_phases.yaml new file mode 100644 index 0000000..c5a73c9 --- /dev/null +++ b/examples/import_phases.yaml @@ -0,0 +1,8 @@ +--- +phases: +- name: main + tasks: + - name: hello + command: + command: echo hello +- import: phases.yaml diff --git a/examples/import_tasks.yaml b/examples/import_tasks.yaml new file mode 100644 index 0000000..65cb387 --- /dev/null +++ b/examples/import_tasks.yaml @@ -0,0 +1,8 @@ +--- +phases: +- name: main + tasks: + - name: hello + command: + command: echo hello + - import: tasks.yaml diff --git a/examples/main_test.go b/examples/main_test.go index 3818d07..96d8e52 100644 --- a/examples/main_test.go +++ b/examples/main_test.go @@ -6,7 +6,7 @@ import ( "gotest.tools/v3/icmd" ) -func TestBuildflow(t *testing.T) { +func TestBuildflow(t *testing.T) { //nolint:funlen data := []struct { title string file string @@ -32,10 +32,22 @@ func TestBuildflow(t *testing.T) { title: "read_file", file: "read_file.yaml", }, + { + title: "write_file", + file: "write_file.yaml", + }, { title: "command's standard input", file: "stdin.yaml", }, + { + title: "import phases from a file", + file: "import_phases.yaml", + }, + { + title: "import tasks from a file", + file: "import_tasks.yaml", + }, { title: "buildflow run fails as expected", file: "fail.yaml", diff --git a/examples/phases.yaml b/examples/phases.yaml new file mode 100644 index 0000000..c7e118a --- /dev/null +++ b/examples/phases.yaml @@ -0,0 +1,12 @@ +--- +# This file is imported from import_phases.yaml +- name: main 2 + tasks: + - name: hello + command: + command: echo "main 2" +- name: main + tasks: + - name: main 3 + command: + command: echo "main 3" diff --git a/examples/tasks.yaml b/examples/tasks.yaml new file mode 100644 index 0000000..025a7e0 --- /dev/null +++ b/examples/tasks.yaml @@ -0,0 +1,8 @@ +--- +# This file is imported from import_tasks.yaml +- name: foo + command: + command: echo foo +- name: bar + command: + command: echo bar diff --git a/examples/write_file.yaml b/examples/write_file.yaml new file mode 100644 index 0000000..dbbb71e --- /dev/null +++ b/examples/write_file.yaml @@ -0,0 +1,10 @@ +--- +phases: +- name: main + tasks: + - name: foo + write_file: + path: foo.txt + template: | + # This file is generated by write_file.yaml + hello {{.Task.Name}} diff --git a/scripts/test-example.sh b/scripts/test-example.sh new file mode 100644 index 0000000..f71ae8f --- /dev/null +++ b/scripts/test-example.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eu + +cd "$(dirname "$0")/.." + +tempdir=$(mktemp -d) +go build -o "$tempdir/buildflow" ./cmd/buildflow +export PATH="$tempdir:$PATH" +cd examples +# command -v buildflow +go test -race -covermode=atomic ./... +rm -R "$tempdir"