From 8493988150fba8683e339465b518d201cf560511 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 13:16:06 +0900 Subject: [PATCH 1/8] Update references to project after switching organizations to public --- .circleci/config.yml | 8 ++++---- Makefile | 2 +- client/client.go | 2 +- cmd/cmd_suite_test.go | 2 +- cmd/collapse.go | 2 +- cmd/query.go | 2 +- cmd/root.go | 4 ++-- filetree/filetree_test.go | 2 +- main.go | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ea2f58ede..37a984d5d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,14 +20,14 @@ jobs: test: docker: - image: circleci/golang:1.10 - working_directory: /go/src/github.com/circleci/circleci-cli + working_directory: /go/src/github.com/CircleCI-Public/circleci-cli steps: - checkout - run: make test coverage: docker: - image: circleci/golang:1.10 - working_directory: /go/src/github.com/circleci/circleci-cli + working_directory: /go/src/github.com/CircleCI-Public/circleci-cli steps: - checkout - run: make cover @@ -52,7 +52,7 @@ jobs: lint: docker: - image: circleci/golang:1.10 - working_directory: /go/src/github.com/circleci/circleci-cli + working_directory: /go/src/github.com/CircleCI/circleci-cli steps: - checkout - restore_cache: @@ -74,7 +74,7 @@ jobs: environment: GORELEASER_URL: https://github.com/goreleaser/goreleaser/releases/download/v0.77.1/goreleaser_amd64.deb - working_directory: /go/src/github.com/circleci/circleci-cli + working_directory: /go/src/github.com/CircleCI/circleci-cli steps: - checkout - restore_cache: diff --git a/Makefile b/Makefile index c6a9019c9..ef62acb69 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GOFILES = $(shell find . -name '*.go' -not -path './vendor/*') OS = $(shell uname) -CLIPATH=github.com/circleci/circleci-cli +CLIPATH=github.com/CircleCI-Public/circleci-cli EXECUTABLE=circleci-cli BUILD_DIR=build diff --git a/client/client.go b/client/client.go index b88d6c381..42cc31f5c 100644 --- a/client/client.go +++ b/client/client.go @@ -3,7 +3,7 @@ package client import ( "context" - "github.com/circleci/circleci-cli/logger" + "github.com/CircleCI-Public/circleci-cli/logger" "github.com/machinebox/graphql" ) diff --git a/cmd/cmd_suite_test.go b/cmd/cmd_suite_test.go index 593f57238..4c2a4f02d 100644 --- a/cmd/cmd_suite_test.go +++ b/cmd/cmd_suite_test.go @@ -12,7 +12,7 @@ var pathCLI string var _ = BeforeSuite(func() { var err error - pathCLI, err = gexec.Build("github.com/circleci/circleci-cli") + pathCLI, err = gexec.Build("github.com/CircleCI-Public/circleci-cli") Ω(err).ShouldNot(HaveOccurred()) }) diff --git a/cmd/collapse.go b/cmd/collapse.go index b3c4eef09..cb7c625b5 100644 --- a/cmd/collapse.go +++ b/cmd/collapse.go @@ -3,7 +3,7 @@ package cmd import ( "regexp" - "github.com/circleci/circleci-cli/filetree" + "github.com/CircleCI-Public/circleci-cli/filetree" "github.com/spf13/cobra" yaml "gopkg.in/yaml.v2" ) diff --git a/cmd/query.go b/cmd/query.go index 65cc5c8bb..0ecbb4b2c 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -4,7 +4,7 @@ import ( "io/ioutil" "os" - "github.com/circleci/circleci-cli/client" + "github.com/CircleCI-Public/circleci-cli/client" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" diff --git a/cmd/root.go b/cmd/root.go index 3b0e5f096..eaf11bb32 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,8 +4,8 @@ import ( "os" "path" - "github.com/circleci/circleci-cli/logger" - "github.com/circleci/circleci-cli/settings" + "github.com/CircleCI-Public/circleci-cli/logger" + "github.com/CircleCI-Public/circleci-cli/settings" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" diff --git a/filetree/filetree_test.go b/filetree/filetree_test.go index f7910b8ad..fc3d4deda 100644 --- a/filetree/filetree_test.go +++ b/filetree/filetree_test.go @@ -11,7 +11,7 @@ import ( . "github.com/onsi/gomega" yaml "gopkg.in/yaml.v2" - "github.com/circleci/circleci-cli/filetree" + "github.com/CircleCI-Public/circleci-cli/filetree" ) var _ = Describe("filetree", func() { diff --git a/main.go b/main.go index 10948c3af..8948a918d 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/circleci/circleci-cli/cmd" + "github.com/CircleCI-Public/circleci-cli/cmd" ) func main() { From 8d42f72b922ceab94d8e821eca90123d60b6a1b9 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 13:16:50 +0900 Subject: [PATCH 2/8] Add go tooling instructions to CONTRIBUTING Make README setup instructions independent of go tools, also updated binary name to match with beta. --- CONTRIBUTING.md | 33 ++++++++++++++++++++++++++++++++- README.md | 34 ++++++++-------------------------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97d58dcc5..581123228 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,6 +9,37 @@ Second, it's written in Go. If you are new to Go, we recommend the following res * [A Tour of Go](https://tour.golang.org/welcome/1) * [The Go documentation](https://golang.org/doc/) +## Requirements + +* Go 1.10+ +* Make +* ... + +## Getting setup + +You should already have [installed Go](https://golang.org/doc/install) and setup your [workspace](https://golang.org/doc/code.html#Workspaces). + +This includes setting a valid `$GOPATH`. + +### 1. Get the repo + +``` +$ go get -u github.com/CircleCI-Public/circleci-cli +$ cd $GOPATH/src/github.com/CircleCI-Public/circleci-cli +``` + +### 2. Build the binary + +``` +$ make +``` + +### 3. Run tests + +``` +$ make test +``` + ## Managing Dependencies We use `dep` for vendoring our depencencies: @@ -80,4 +111,4 @@ You can view the documentation for this project in your browser using `godoc`. After installing it via `make dev`. 1. Run `make doc`. -2. Access http://localhost:6060/pkg/github.com/circleci/circleci-cli/ +2. Access http://localhost:6060/pkg/github.com/CircleCI-Public/circleci-cli/ diff --git a/README.md b/README.md index 52368a2ee..fd8859967 100644 --- a/README.md +++ b/README.md @@ -2,42 +2,24 @@ This project is the seed for CircleCI's new command-line application. -## Requirements - -* Go 1.10+ -* Make -* ... - ## Getting Started -You should already have [installed Go](https://golang.org/doc/install) and setup your [workspace](https://golang.org/doc/code.html#Workspaces). - -This includes setting a valid `$GOPATH`. - -### 1. Get the repo -TODO: make this easier once repo is public +### 1. Get the latest binary -``` -# Setup circleci source in your $GOPATH -$ mkdir -p $GOPATH/src/github.com/circleci -$ cd $GOPATH/src/github.com/circleci - -# Clone the repo -$ git clone git@github.com/circleci/circleci-cli -$ cd circleci-cli -``` +Download the [latest release](https://github.com/CircleCI-Public/circleci-cli/releases/latest) from GitHub for your operating system. If you're on a Mac, this would be `circleci-cli_0.1.X_darwin_amd64.tar.gz`. -### 2. Build the binary +### 2. Put the binary in your $PATH ``` -$ make +$ tar -xvzf circleci-cli_0.1.X_darwin_amd64.tar.gz +$ mv circleci-beta /usr/local/bin ``` -### 3. Run Diagnostic check +### 3. Run a Diagnostic check ``` -$ ./build/target/darwin/amd64/circleci-cli diagnostic +$ circleci-beta diagnostic Please enter your CircleCI API token: OK. @@ -88,7 +70,7 @@ fragment FullType on __Type { You can now pipe that file to the `query` command to send it. ``` -$ cat query.gql | ./build/target/darwin/amd64/circleci-cli query +$ cat query.gql | circleci-beta query ``` This should pretty-print back a JSON response from the server: From 998a25864b6ba4dd710548b43ca4f0eea28665fd Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 16:26:19 +0900 Subject: [PATCH 3/8] Add testdata for integration testing collapse command with hugo orb --- cmd/collapse_test.go | 33 +++--- .../hugo-collapse/.circleci/config.yml | 4 + .../hugo-collapse/.circleci/orbs/.DS_Store | 0 .../.circleci/orbs/hugo/README.md | 3 + .../orbs/hugo/commands/build-hugo.yml | 24 ++++ .../orbs/hugo/commands/html-proofer.yml | 8 ++ .../.circleci/orbs/hugo/jobs/build.yml | 34 ++++++ .../hugo-collapse/.circleci/orbs/hugo/orb.yml | 10 ++ .../.circleci/orbs/hugo/usage/build.yml | 8 ++ cmd/testdata/hugo-collapse/out.yml | 108 ++++++++++++++++++ 10 files changed, 217 insertions(+), 15 deletions(-) create mode 100644 cmd/testdata/hugo-collapse/.circleci/config.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/.DS_Store create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/build-hugo.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/html-proofer.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/orb.yml create mode 100644 cmd/testdata/hugo-collapse/.circleci/orbs/hugo/usage/build.yml create mode 100644 cmd/testdata/hugo-collapse/out.yml diff --git a/cmd/collapse_test.go b/cmd/collapse_test.go index bff835cec..736d7087e 100644 --- a/cmd/collapse_test.go +++ b/cmd/collapse_test.go @@ -41,26 +41,29 @@ var _ = Describe("collapse", func() { ).To(Succeed()) } }) + }) +}) + +var _ = Describe("collapse with testdata", func() { + var ( + command *exec.Cmd + results []byte + ) - It("collapse all YAML contents using directory structure as keys", func() { + Describe("a .circleci folder with config.yml and local orbs folder containing the hugo orb", func() { + BeforeEach(func() { + var err error + command = exec.Command(pathCLI, "collapse", "-r", "testdata/hugo-collapse/.circleci") + results, err = ioutil.ReadFile("testdata/hugo-collapse/out.yml") + Expect(err).ShouldNot(HaveOccurred()) + }) + + It("collapse all YAML contents as expected", func() { session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) session.Wait() Expect(err).ShouldNot(HaveOccurred()) Eventually(session.Err.Contents()).Should(BeEmpty()) - - Eventually(session.Out.Contents()).Should(MatchYAML(` -orbs: - one: - commands: - file: - contents_one: 1 - contents_two: 2 - two: - commands: - file: - contents_one: 1 - contents_two: 2 -`)) + Eventually(session.Out.Contents()).Should(MatchYAML(results)) Eventually(session).Should(gexec.Exit(0)) }) }) diff --git a/cmd/testdata/hugo-collapse/.circleci/config.yml b/cmd/testdata/hugo-collapse/.circleci/config.yml new file mode 100644 index 000000000..18ac24cb8 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/config.yml @@ -0,0 +1,4 @@ +workflows: + foo: + jobs: + - hugo/build diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/.DS_Store b/cmd/testdata/hugo-collapse/.circleci/orbs/.DS_Store new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md new file mode 100644 index 000000000..a7fa997d9 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/README.md @@ -0,0 +1,3 @@ +# The hugo orb + +I'm just here to make sure we don't try to parse this markdown file as yaml. diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/build-hugo.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/build-hugo.yml new file mode 100644 index 000000000..49b875591 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/build-hugo.yml @@ -0,0 +1,24 @@ +description: "Runs the `hugo` CLI against a given source (default: current path) in a given env (default: production)" +parameters: + env: + description: "Passed in as the value of HUGO_ENV prior to running the hugo command" + type: string + default: "production" + source: + description: "a file path, relative to the root of your working directory, where your hugo root is. (passed as the value of the `-s` flag to hugo)" + type: string + default: "." + update-submodules: + description: "Boolean for whether to update git submodules." + type: boolean + default: false +steps: + - when: + condition: << parameters.update-submodules >> + steps: + - run: + name: "Get submodules to refresh themes" + command: git submodule update --init --recursive + - run: + name: "Build site with hugo" + command: HUGO_ENV=<< parameters.env >> hugo -v -s << parameters.source >> diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/html-proofer.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/html-proofer.yml new file mode 100644 index 000000000..9e6150fec --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/commands/html-proofer.yml @@ -0,0 +1,8 @@ +parameters: + path: + type: string + description: "Path to the directory containing the published site, relative to the execution environment root." +steps: + - run: + name: "Run HTML Proofer to check for good html and such" + command: htmlproofer << parameters.path>> --allow-hash-href --check-html --empty-alt-ignore --disable-external diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml new file mode 100644 index 000000000..bdcde488a --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/jobs/build.yml @@ -0,0 +1,34 @@ +parameters: + source: + description: "a file path, relative to the root of your working directory, where your hugo root is. (passed as the value of the `-s` flag to hugo)" + default: "." + type: string + publishdir: + description: "Hugo sets the name of your publish Dir inside the site config, not as a CLI argument. Most people leave this to the default value of `public`, so that's what we do here. In most case you don't need to change this value." + default: "public" + type: string + html-proofer: + description: "Boolean value for whether to run the HTML Proofer. Set to `false` to stop the default behavior of running the proofer." + type: boolean + default: true + persist_to_workspace: + description: "Boolean value for whether to persist to a workspace drawing from the `parameters.source` as root and `parameters.publishdir` as the path." + type: boolean + default: true +executor: default +steps: + - checkout + - build-hugo: + source: "<< parameters.source >>" + - when: + condition: << parameters.html-proofer >> + steps: + - html-proofer: + - path: "<< parameters.source >>/<< parameters.publishdir >>" + - when: + condition: << parameters.persist_to_workspace >> + steps: + - persist_to_workspace: + root: "<< parameters.source >>" + paths: + - "<< parameters.publishdir >>" diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/orb.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/orb.yml new file mode 100644 index 000000000..d12c0a238 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/orb.yml @@ -0,0 +1,10 @@ +description: "A simple encapsulation of common tasks in Hugo" + +executors: + default: + parameters: + tag: + description: "The tag to use on the image" + type: string + docker: + - image: cibuilds/hugo:<< parameters.image >> diff --git a/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/usage/build.yml b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/usage/build.yml new file mode 100644 index 000000000..a24a76e54 --- /dev/null +++ b/cmd/testdata/hugo-collapse/.circleci/orbs/hugo/usage/build.yml @@ -0,0 +1,8 @@ +version: 2 +orbs: + hugo: circleci/hugo@latest + +workflows: + build-hugo: + jobs: + - hugo/build diff --git a/cmd/testdata/hugo-collapse/out.yml b/cmd/testdata/hugo-collapse/out.yml new file mode 100644 index 000000000..8994ccaeb --- /dev/null +++ b/cmd/testdata/hugo-collapse/out.yml @@ -0,0 +1,108 @@ +orbs: + hugo: + commands: + build-hugo: + description: 'Runs the `hugo` CLI against a given source (default: current + path) in a given env (default: production)' + parameters: + env: + default: production + description: Passed in as the value of HUGO_ENV prior to running the hugo + command + type: string + source: + default: . + description: a file path, relative to the root of your working directory, + where your hugo root is. (passed as the value of the `-s` flag to hugo) + type: string + update-submodules: + default: false + description: Boolean for whether to update git submodules. + type: boolean + steps: + - when: + condition: << parameters.update-submodules >> + steps: + - run: + command: git submodule update --init --recursive + name: Get submodules to refresh themes + - run: + command: HUGO_ENV=<< parameters.env >> hugo -v -s << parameters.source + >> + name: Build site with hugo + html-proofer: + parameters: + path: + description: Path to the directory containing the published site, relative + to the execution environment root. + type: string + steps: + - run: + command: htmlproofer << parameters.path>> --allow-hash-href --check-html + --empty-alt-ignore --disable-external + name: Run HTML Proofer to check for good html and such + description: A simple encapsulation of common tasks in Hugo + executors: + default: + docker: + - image: cibuilds/hugo:<< parameters.image >> + parameters: + tag: + description: The tag to use on the image + type: string + jobs: + build: + executor: default + parameters: + html-proofer: + default: true + description: Boolean value for whether to run the HTML Proofer. Set to + `false` to stop the default behavior of running the proofer. + type: boolean + persist_to_workspace: + default: true + description: Boolean value for whether to persist to a workspace drawing + from the `parameters.source` as root and `parameters.publishdir` as + the path. + type: boolean + publishdir: + default: public + description: Hugo sets the name of your publish Dir inside the site config, + not as a CLI argument. Most people leave this to the default value of + `public`, so that's what we do here. In most case you don't need to + change this value. + type: string + source: + default: . + description: a file path, relative to the root of your working directory, + where your hugo root is. (passed as the value of the `-s` flag to hugo) + type: string + steps: + - checkout + - build-hugo: + source: << parameters.source >> + - when: + condition: << parameters.html-proofer >> + steps: + - html-proofer: null + - path: << parameters.source >>/<< parameters.publishdir >> + - when: + condition: << parameters.persist_to_workspace >> + steps: + - persist_to_workspace: + paths: + - << parameters.publishdir >> + root: << parameters.source >> + usage: + build: + orbs: + hugo: circleci/hugo@latest + version: 2 + workflows: + build-hugo: + jobs: + - hugo/build +workflows: + foo: + jobs: + - hugo/build From fa63a0269c18e583dd2fab500bf2c237c14653a9 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 16:46:15 +0900 Subject: [PATCH 4/8] Add collapse test for nesting orbs and local commands, etc --- cmd/collapse_test.go | 21 +++- .../hugo-collapse/{out.yml => result.yml} | 0 .../result.yml | 112 ++++++++++++++++++ .../test/build.yml | 71 +++++++++++ .../test/commands/say.yml | 8 ++ .../test/executors/parallel.yml | 1 + .../test/jobs/sayhello.yml | 10 ++ .../test/orbs/foo/commands/zomg.yml | 7 ++ .../test/orbs/foo/orb.yml | 10 ++ 9 files changed, 239 insertions(+), 1 deletion(-) rename cmd/testdata/hugo-collapse/{out.yml => result.yml} (100%) create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/result.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/build.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/commands/say.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/executors/parallel.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/jobs/sayhello.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/commands/zomg.yml create mode 100644 cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/orb.yml diff --git a/cmd/collapse_test.go b/cmd/collapse_test.go index 736d7087e..4c6a9d0ff 100644 --- a/cmd/collapse_test.go +++ b/cmd/collapse_test.go @@ -54,7 +54,26 @@ var _ = Describe("collapse with testdata", func() { BeforeEach(func() { var err error command = exec.Command(pathCLI, "collapse", "-r", "testdata/hugo-collapse/.circleci") - results, err = ioutil.ReadFile("testdata/hugo-collapse/out.yml") + results, err = ioutil.ReadFile("testdata/hugo-collapse/result.yml") + Expect(err).ShouldNot(HaveOccurred()) + }) + + It("collapse all YAML contents as expected", func() { + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) + session.Wait() + Expect(err).ShouldNot(HaveOccurred()) + Eventually(session.Err.Contents()).Should(BeEmpty()) + Eventually(session.Out.Contents()).Should(MatchYAML(results)) + Eventually(session).Should(gexec.Exit(0)) + }) + }) + + Describe("local orbs folder with mixed inline and local commands, jobs, etc", func() { + BeforeEach(func() { + var err error + var path string = "nested-orbs-and-local-commands-etc" + command = exec.Command(pathCLI, "collapse", "-r", filepath.Join("testdata", path, "test")) + results, err = ioutil.ReadFile(filepath.Join("testdata", path, "result.yml")) Expect(err).ShouldNot(HaveOccurred()) }) diff --git a/cmd/testdata/hugo-collapse/out.yml b/cmd/testdata/hugo-collapse/result.yml similarity index 100% rename from cmd/testdata/hugo-collapse/out.yml rename to cmd/testdata/hugo-collapse/result.yml diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/result.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/result.yml new file mode 100644 index 000000000..f34c24283 --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/result.yml @@ -0,0 +1,112 @@ +commands: + foo: + parameters: + mybool: + default: true + type: boolean + steps: + - run: echo in foo + - when: + condition: << parameters.mybool >> + steps: + - run: echo bool is true + - unless: + condition: << parameters.mybool >> + steps: + - run: echo bool is false + say: + description: A simple command that echoes whatever is passed + parameters: + saywhat: + description: What shall we say? + type: string + steps: + - run: echo << parameters.saywhat >> +executors: + parallel: + parallelism: 4 +jobs: + bar: + machine: + docker_layer_caching: << parameters.mybool >> + enabled: << parameters.mybool >> + parameters: + mybool: + default: false + type: boolean + myotherbool: + default: false + type: boolean + mysteps: + default: [] + type: steps + steps: + - checkout + - when: + condition: << parameters.mybool >> + steps: + - << parameters.mysteps >> + - when: + condition: << parameters.mybool >> + steps: + - foo: + mybool: << parameters.myotherbool >> + build-false: + machine: true + steps: + - foo: + mybool: false + build-true: + machine: true + steps: + - foo + sayhello: + description: A job that does very little other than demonstrate what a parameterized + job looks like + machine: true + parameters: + saywhat: + default: World + description: To whom shall we say hello? + type: string + steps: + - say: + saywhat: Hello << parameters.saywhat >> +orbs: + foo: + commands: + zomg: + description: a command inside a folder in an orb + parameters: + tm: + description: Tell me something. + type: string + steps: + - run: echo "You don't say... << parameters.saywhat >>" + description: A simple encapsulation of common tasks in Hugo + executors: + default: + docker: + - image: cibuilds/hugo:<< parameters.image >> + parameters: + tag: + description: The tag to use on the image + type: string +version: 2 +workflows: + version: 2 + workflow: + jobs: + - build-true + - build-false + - bar: + mybool: true + myotherbool: false + - bar: + mybool: false + myotherbool: true + - bar: + mybool: true + mysteps: + - run: echo i am a steps param, hear me shout + diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/build.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/build.yml new file mode 100644 index 000000000..b09c6f244 --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/build.yml @@ -0,0 +1,71 @@ +version: 2 + +commands: + foo: + parameters: + mybool: + type: boolean + default: true + steps: + - run: "echo in foo" + - when: + condition: << parameters.mybool >> + steps: + - run: echo bool is true + - unless: + condition: << parameters.mybool >> + steps: + - run: echo bool is false + +jobs: + build-true: + machine: true + steps: + - foo + build-false: + machine: true + steps: + - foo: + mybool: false + bar: + parameters: + mybool: + type: boolean + default: false + myotherbool: + type: boolean + default: false + mysteps: + type: steps + default: [] + machine: + docker_layer_caching: << parameters.mybool >> + enabled: << parameters.mybool >> + steps: + - checkout + - when: + condition: << parameters.mybool >> + steps: + - << parameters.mysteps >> + - when: + condition: << parameters.mybool >> + steps: + - foo: + mybool: << parameters.myotherbool >> + +workflows: + version: 2 + workflow: + jobs: + - build-true + - build-false + - bar: + mybool: true + myotherbool: false + - bar: + mybool: false + myotherbool: true + - bar: + mybool: true + mysteps: + - run: echo i am a steps param, hear me shout diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/commands/say.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/commands/say.yml new file mode 100644 index 000000000..36d54858c --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/commands/say.yml @@ -0,0 +1,8 @@ +description: "A simple command that echoes whatever is passed" +parameters: + saywhat: + description: "What shall we say?" + type: string +steps: + # note: the interpolation syntax is subject to change + - run: echo << parameters.saywhat >> diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/executors/parallel.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/executors/parallel.yml new file mode 100644 index 000000000..28c7f4b4d --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/executors/parallel.yml @@ -0,0 +1 @@ +parallelism: 4 diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/jobs/sayhello.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/jobs/sayhello.yml new file mode 100644 index 000000000..2be3c054c --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/jobs/sayhello.yml @@ -0,0 +1,10 @@ +description: A job that does very little other than demonstrate what a parameterized job looks like +parameters: + saywhat: + description: "To whom shall we say hello?" + type: string + default: "World" +machine: true +steps: + - say: + saywhat: Hello << parameters.saywhat >> diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/commands/zomg.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/commands/zomg.yml new file mode 100644 index 000000000..11289f015 --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/commands/zomg.yml @@ -0,0 +1,7 @@ +description: "a command inside a folder in an orb" +parameters: + tm: + description: "Tell me something." + type: string +steps: + - run: echo "You don't say... << parameters.saywhat >>" diff --git a/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/orb.yml b/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/orb.yml new file mode 100644 index 000000000..d12c0a238 --- /dev/null +++ b/cmd/testdata/nested-orbs-and-local-commands-etc/test/orbs/foo/orb.yml @@ -0,0 +1,10 @@ +description: "A simple encapsulation of common tasks in Hugo" + +executors: + default: + parameters: + tag: + description: "The tag to use on the image" + type: string + docker: + - image: cibuilds/hugo:<< parameters.image >> From f23054e6935f22dd3ca84f4809b53d4a13397ef2 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 16:49:42 +0900 Subject: [PATCH 5/8] Add test for orb with local executors and commands in folder --- cmd/collapse_test.go | 18 ++++++++++++++++++ cmd/testdata/myorb/result.yml | 19 +++++++++++++++++++ cmd/testdata/myorb/test/commands/zomg.yml | 7 +++++++ cmd/testdata/myorb/test/orb.yml | 10 ++++++++++ 4 files changed, 54 insertions(+) create mode 100644 cmd/testdata/myorb/result.yml create mode 100644 cmd/testdata/myorb/test/commands/zomg.yml create mode 100644 cmd/testdata/myorb/test/orb.yml diff --git a/cmd/collapse_test.go b/cmd/collapse_test.go index 4c6a9d0ff..623ed1d84 100644 --- a/cmd/collapse_test.go +++ b/cmd/collapse_test.go @@ -86,4 +86,22 @@ var _ = Describe("collapse with testdata", func() { Eventually(session).Should(gexec.Exit(0)) }) }) + + Describe("an orb containing local executors and commands in folder", func() { + BeforeEach(func() { + var err error + command = exec.Command(pathCLI, "collapse", "-r", "testdata/myorb/test") + results, err = ioutil.ReadFile("testdata/myorb/result.yml") + Expect(err).ShouldNot(HaveOccurred()) + }) + + It("collapse all YAML contents as expected", func() { + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) + session.Wait() + Expect(err).ShouldNot(HaveOccurred()) + Eventually(session.Err.Contents()).Should(BeEmpty()) + Eventually(session.Out.Contents()).Should(MatchYAML(results)) + Eventually(session).Should(gexec.Exit(0)) + }) + }) }) diff --git a/cmd/testdata/myorb/result.yml b/cmd/testdata/myorb/result.yml new file mode 100644 index 000000000..281d6c05a --- /dev/null +++ b/cmd/testdata/myorb/result.yml @@ -0,0 +1,19 @@ +commands: + zomg: + description: a command inside a folder in an orb + parameters: + tm: + description: Tell me something. + type: string + steps: + - run: echo "You don't say... << parameters.saywhat >>" +description: A simple encapsulation of common tasks in Hugo +executors: + default: + docker: + - image: cibuilds/hugo:<< parameters.image >> + parameters: + tag: + description: The tag to use on the image + type: string + diff --git a/cmd/testdata/myorb/test/commands/zomg.yml b/cmd/testdata/myorb/test/commands/zomg.yml new file mode 100644 index 000000000..11289f015 --- /dev/null +++ b/cmd/testdata/myorb/test/commands/zomg.yml @@ -0,0 +1,7 @@ +description: "a command inside a folder in an orb" +parameters: + tm: + description: "Tell me something." + type: string +steps: + - run: echo "You don't say... << parameters.saywhat >>" diff --git a/cmd/testdata/myorb/test/orb.yml b/cmd/testdata/myorb/test/orb.yml new file mode 100644 index 000000000..d12c0a238 --- /dev/null +++ b/cmd/testdata/myorb/test/orb.yml @@ -0,0 +1,10 @@ +description: "A simple encapsulation of common tasks in Hugo" + +executors: + default: + parameters: + tag: + description: "The tag to use on the image" + type: string + docker: + - image: cibuilds/hugo:<< parameters.image >> From 0a747268b4a268d57532a2cc08dd9d92709d5864 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 16:55:05 +0900 Subject: [PATCH 6/8] Test collapse with a large nested config including rails orb --- cmd/collapse_test.go | 19 ++ .../result.yml | 310 ++++++++++++++++++ .../test/build.yml | 71 ++++ .../test/commands/say.yml | 8 + .../test/executors/parallel.yml | 1 + .../test/jobs/sayhello.yml | 10 + .../test/orbs/foo/commands/zomg.yml | 7 + .../test/orbs/foo/orb.yml | 10 + .../test/orbs/rails/README.md | 17 + .../orbs/rails/commands/bundle_install.yml | 44 +++ .../test/orbs/rails/commands/load_db.yml | 10 + .../test/orbs/rails/commands/run_rspec.yml | 25 ++ .../test/orbs/rails/jobs/build_postgres.yml | 34 ++ .../test/orbs/rails/orb.yml | 0 .../test/orbs/rails/usage/build.yml | 9 + .../orbs/rails/usage/generated_config.yml | 73 +++++ 16 files changed, 648 insertions(+) create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/result.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/build.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/commands/say.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/executors/parallel.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/jobs/sayhello.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/foo/commands/zomg.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/foo/orb.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/README.md create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/bundle_install.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/load_db.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/run_rspec.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/jobs/build_postgres.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/orb.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/usage/build.yml create mode 100644 cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/usage/generated_config.yml diff --git a/cmd/collapse_test.go b/cmd/collapse_test.go index 623ed1d84..c73c7cbfd 100644 --- a/cmd/collapse_test.go +++ b/cmd/collapse_test.go @@ -104,4 +104,23 @@ var _ = Describe("collapse with testdata", func() { Eventually(session).Should(gexec.Exit(0)) }) }) + + Describe("with a large nested config including rails orb", func() { + BeforeEach(func() { + var err error + var path string = "test-with-large-nested-rails-orb" + command = exec.Command(pathCLI, "collapse", "-r", filepath.Join("testdata", path, "test")) + results, err = ioutil.ReadFile(filepath.Join("testdata", path, "result.yml")) + Expect(err).ShouldNot(HaveOccurred()) + }) + + It("collapse all YAML contents as expected", func() { + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) + session.Wait() + Expect(err).ShouldNot(HaveOccurred()) + Eventually(session.Err.Contents()).Should(BeEmpty()) + Eventually(session.Out.Contents()).Should(MatchYAML(results)) + Eventually(session).Should(gexec.Exit(0)) + }) + }) }) diff --git a/cmd/testdata/test-with-large-nested-rails-orb/result.yml b/cmd/testdata/test-with-large-nested-rails-orb/result.yml new file mode 100644 index 000000000..44876a6a2 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/result.yml @@ -0,0 +1,310 @@ +commands: + foo: + parameters: + mybool: + default: true + type: boolean + steps: + - run: echo in foo + - when: + condition: << parameters.mybool >> + steps: + - run: echo bool is true + - unless: + condition: << parameters.mybool >> + steps: + - run: echo bool is false + say: + description: A simple command that echoes whatever is passed + parameters: + saywhat: + description: What shall we say? + type: string + steps: + - run: echo << parameters.saywhat >> +executors: + parallel: + parallelism: 4 +jobs: + bar: + machine: + docker_layer_caching: << parameters.mybool >> + enabled: << parameters.mybool >> + parameters: + mybool: + default: false + type: boolean + myotherbool: + default: false + type: boolean + mysteps: + default: [] + type: steps + steps: + - checkout + - when: + condition: << parameters.mybool >> + steps: + - << parameters.mysteps >> + - when: + condition: << parameters.mybool >> + steps: + - foo: + mybool: << parameters.myotherbool >> + build-false: + machine: true + steps: + - foo: + mybool: false + build-true: + machine: true + steps: + - foo + sayhello: + description: A job that does very little other than demonstrate what a parameterized + job looks like + machine: true + parameters: + saywhat: + default: World + description: To whom shall we say hello? + type: string + steps: + - say: + saywhat: Hello << parameters.saywhat >> +orbs: + foo: + commands: + zomg: + description: a command inside a folder in an orb + parameters: + tm: + description: Tell me something. + type: string + steps: + - run: echo "You don't say... << parameters.saywhat >>" + description: A simple encapsulation of common tasks in Hugo + executors: + default: + docker: + - image: cibuilds/hugo:<< parameters.image >> + parameters: + tag: + description: The tag to use on the image + type: string + rails: + commands: + bundle_install: + parameters: + bundle_jobs: + default: "3" + type: string + bundle_path: + default: vendor/bundle + type: string + bundle_retry: + default: "3" + type: string + steps: + - run: + command: | + bundle config jobs << parameters.bundle_jobs >> + bundle config path << parameters.bundle_path >> + bundle config retry << parameters.bundle_retry >> + name: Configure bundler + - run: + command: | + gem --version + bundle --version + name: Log versions for debugging + - restore_cache: + keys: + - rails-demo-bundle-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" + }} + - rails-demo-bundle-{{ arch }}-{{ .Branch }}- + - rails-demo-bundle-{{ arch }}-{{ Environment.DEFAULT_BRANCH }}- + name: Restore bundler cache + - run: + command: bundle check || bundle install + name: Bundle Install + - run: + command: bundle clean --force + name: Clear unused bundle gems before saving cache + - save_cache: + key: rails-demo-bundle-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" + }} + paths: + - << parameters.bundle_path >> + load_db: + steps: + - run: + command: dockerize -wait tcp://localhost:5432 -timeout 1m + name: Wait for DB to initialize + - run: + command: bin/rails db:schema:load --trace + name: Database setup + run_rspec: + parameters: + rspec_glob: + default: spec/**/*_spec.rb + type: string + steps: + - run: + command: | + # Determine test subset to run on each container and print diagnostics + TEST_FILES=$(circleci tests glob << parameters.rspec_glob >> | \ + circleci tests split) + echo "running " $(echo $TEST_FILES | wc -w) " tests files on this container:" + echo "$TEST_FILES" + + bundle exec rspec --profile 10 \ + --format RspecJunitFormatter \ + --out CIRCLE_TEST_REPORTS/rspec.xml \ + --format documentation \ + $TEST_FILES + name: Run rspec in parallel + - store_test_results: + path: $CIRCLE_TEST_REPORTS + - store_artifacts: + path: $CIRCLE_ARTIFACTS + jobs: + build_postgres: + docker: + - image: circleci/ruby:<< parameters.ruby >>-node + - environment: + - POSTGRES_USER: << parameters.database_user >> + - POSTGRES_DB: << parameters.database_name >> + - POSTGRES_PASSWORD: << parameters.database_password >> + image: circleci/postgres:<< parameters.postgres >>-alpine-ram + environment: + - CIRCLE_TEST_REPORTS: test_results + - CIRCLE_ARTIFACTS: test_results + - DATABASE_URL: postgres://<< parameters.database_user >>:<< parameters.database_password + >>@127.0.0.1:5432/<< parameters.database_name >> + - RAILS_ENV: test + parameters: + database_name: + default: rails_blog + type: string + database_password: + default: "" + type: string + database_user: + default: circleci-demo-ruby + type: string + postgres: + type: string + rspec_glob: + default: spec/**/*_spec.rb + type: string + ruby: + type: string + steps: + - checkout + - bundle_install + - load_db + - run_rspec + usage: + build: + version: 2 + workflows: + build-test-deploy: + jobs: + - rails/build_postgres: + postgres: 9.6.8 + ruby: 2.5.1 + version: 2 + generated_config: + jobs: + build_postgres: + docker: + - image: circleci/ruby:2.5.1-node + - environment: + - POSTGRES_USER: circleci-demo-ruby + - POSTGRES_DB: rails_blog + - POSTGRES_PASSWORD: "" + image: circleci/postgres:9.6.8-alpine-ram + environment: + - CIRCLE_TEST_REPORTS: test_results + - CIRCLE_ARTIFACTS: test_results + - DATABASE_URL: postgres://circleci-demo-ruby:@127.0.0.1:5432/rails_blog + - RAILS_ENV: test + steps: + - checkout + - run: + command: | + bundle config jobs 3 + bundle config path vendor/bundle + bundle config retry 3 + name: Configure bundler + - run: + command: | + gem --version + bundle --version + name: Log versions for debugging + - restore_cache: + keys: + - rails-demo-bundle-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" + }} + - rails-demo-bundle-{{ arch }}-{{ .Branch }}- + - rails-demo-bundle-{{ arch }}-{{ Environment.DEFAULT_BRANCH }}- + name: Restore bundler cache + - run: + command: bundle check || bundle install + name: Bundle Install + - run: + command: bundle clean --force + name: Clear unused bundle gems before saving cache + - save_cache: + key: rails-demo-bundle-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" + }} + paths: + - vendor/bundle + - run: + command: dockerize -wait tcp://localhost:5432 -timeout 1m + name: Wait for DB to initialize + - run: + command: bin/rails db:schema:load --trace + name: Database setup + - run: + command: | + # Determine test subset to run on each container and print diagnostics + TEST_FILES=$(circleci tests glob spec/**/*_spec.rb | \ + circleci tests split) + echo "running " $(echo $TEST_FILES | wc -w) " tests files on this container:" + echo "$TEST_FILES" + + bundle exec rspec --profile 10 \ + --format RspecJunitFormatter \ + --out CIRCLE_TEST_REPORTS/rspec.xml \ + --format documentation \ + $TEST_FILES + name: Run rspec in parallel + - store_test_results: + path: $CIRCLE_TEST_REPORTS + - store_artifacts: + path: $CIRCLE_ARTIFACTS + version: 2 + workflows: + build-test-deploy: + jobs: + - build_postgres: {} + version: 2 +version: 2 +workflows: + version: 2 + workflow: + jobs: + - build-true + - build-false + - bar: + mybool: true + myotherbool: false + - bar: + mybool: false + myotherbool: true + - bar: + mybool: true + mysteps: + - run: echo i am a steps param, hear me shout + diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/build.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/build.yml new file mode 100644 index 000000000..b09c6f244 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/build.yml @@ -0,0 +1,71 @@ +version: 2 + +commands: + foo: + parameters: + mybool: + type: boolean + default: true + steps: + - run: "echo in foo" + - when: + condition: << parameters.mybool >> + steps: + - run: echo bool is true + - unless: + condition: << parameters.mybool >> + steps: + - run: echo bool is false + +jobs: + build-true: + machine: true + steps: + - foo + build-false: + machine: true + steps: + - foo: + mybool: false + bar: + parameters: + mybool: + type: boolean + default: false + myotherbool: + type: boolean + default: false + mysteps: + type: steps + default: [] + machine: + docker_layer_caching: << parameters.mybool >> + enabled: << parameters.mybool >> + steps: + - checkout + - when: + condition: << parameters.mybool >> + steps: + - << parameters.mysteps >> + - when: + condition: << parameters.mybool >> + steps: + - foo: + mybool: << parameters.myotherbool >> + +workflows: + version: 2 + workflow: + jobs: + - build-true + - build-false + - bar: + mybool: true + myotherbool: false + - bar: + mybool: false + myotherbool: true + - bar: + mybool: true + mysteps: + - run: echo i am a steps param, hear me shout diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/commands/say.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/commands/say.yml new file mode 100644 index 000000000..36d54858c --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/commands/say.yml @@ -0,0 +1,8 @@ +description: "A simple command that echoes whatever is passed" +parameters: + saywhat: + description: "What shall we say?" + type: string +steps: + # note: the interpolation syntax is subject to change + - run: echo << parameters.saywhat >> diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/executors/parallel.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/executors/parallel.yml new file mode 100644 index 000000000..28c7f4b4d --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/executors/parallel.yml @@ -0,0 +1 @@ +parallelism: 4 diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/jobs/sayhello.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/jobs/sayhello.yml new file mode 100644 index 000000000..2be3c054c --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/jobs/sayhello.yml @@ -0,0 +1,10 @@ +description: A job that does very little other than demonstrate what a parameterized job looks like +parameters: + saywhat: + description: "To whom shall we say hello?" + type: string + default: "World" +machine: true +steps: + - say: + saywhat: Hello << parameters.saywhat >> diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/foo/commands/zomg.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/foo/commands/zomg.yml new file mode 100644 index 000000000..11289f015 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/foo/commands/zomg.yml @@ -0,0 +1,7 @@ +description: "a command inside a folder in an orb" +parameters: + tm: + description: "Tell me something." + type: string +steps: + - run: echo "You don't say... << parameters.saywhat >>" diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/foo/orb.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/foo/orb.yml new file mode 100644 index 000000000..d12c0a238 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/foo/orb.yml @@ -0,0 +1,10 @@ +description: "A simple encapsulation of common tasks in Hugo" + +executors: + default: + parameters: + tag: + description: "The tag to use on the image" + type: string + docker: + - image: cibuilds/hugo:<< parameters.image >> diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/README.md b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/README.md new file mode 100644 index 000000000..6b5bf1236 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/README.md @@ -0,0 +1,17 @@ +# rails-orb + +Reusable configuration for Rails projects on CircleCI. Commands and jobs within this orb should abstract away common build configuration and stay up to date with best practices. + +## Getting started + +This repo can be downloaded or sub-tree'd into your `.circleci/orbs` folder in your project. See the [config compiler](https://github.com/circleci/config-compilation) during the internal pre-release period to understand usage in a `build.yml` file that will generate a `config.yml` file. + +See [the rails-postgres build.yml](usage/build.yml) for an example of current syntax. + +## Usage + +Take a look at [rails-orb-demo](https://github.com/circleci/rails-orb-demo) for example how to use this orb in a CircleCI project. + +## Versioning + +Orbs should adhere to a versioning scheme. We recommend using SemVer with [Github Releases](https://help.github.com/articles/creating-releases/). Orb consumers will then be able to download a zip of multiple files, when we add multi-file orb processing to the config compiler. diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/bundle_install.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/bundle_install.yml new file mode 100644 index 000000000..ac57579f0 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/bundle_install.yml @@ -0,0 +1,44 @@ +parameters: + bundle_jobs: + type: string + default: "3" + bundle_retry: + type: string + default: "3" + bundle_path: + type: string + default: vendor/bundle +steps: + - run: + name: Configure bundler + command: | + bundle config jobs << parameters.bundle_jobs >> + bundle config path << parameters.bundle_path >> + bundle config retry << parameters.bundle_retry >> + + - run: + name: Log versions for debugging + command: | + gem --version + bundle --version + + - restore_cache: + name: Restore bundler cache + keys: + - rails-demo-bundle-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }} + - rails-demo-bundle-{{ arch }}-{{ .Branch }}- + - rails-demo-bundle-{{ arch }}-{{ Environment.DEFAULT_BRANCH }}- + + - run: + name: Bundle Install + command: bundle check || bundle install + + - run: + name: Clear unused bundle gems before saving cache + command: bundle clean --force + + - save_cache: + key: rails-demo-bundle-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }} + paths: + - "<< parameters.bundle_path >>" + diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/load_db.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/load_db.yml new file mode 100644 index 000000000..a3d6b4f69 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/load_db.yml @@ -0,0 +1,10 @@ +steps: + # Dockerize is this pre-installed on all CircleCI images + - run: + name: Wait for DB to initialize + command: dockerize -wait tcp://localhost:5432 -timeout 1m + + - run: + name: Database setup + command: bin/rails db:schema:load --trace + diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/run_rspec.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/run_rspec.yml new file mode 100644 index 000000000..69677e5de --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/commands/run_rspec.yml @@ -0,0 +1,25 @@ +parameters: + rspec_glob: + type: string + default: "spec/**/*_spec.rb" +steps: + - run: + name: Run rspec in parallel + command: | + # Determine test subset to run on each container and print diagnostics + TEST_FILES=$(circleci tests glob << parameters.rspec_glob >> | \ + circleci tests split) + echo "running " $(echo $TEST_FILES | wc -w) " tests files on this container:" + echo "$TEST_FILES" + + bundle exec rspec --profile 10 \ + --format RspecJunitFormatter \ + --out CIRCLE_TEST_REPORTS/rspec.xml \ + --format documentation \ + $TEST_FILES + + - store_test_results: + path: $CIRCLE_TEST_REPORTS + + - store_artifacts: + path: $CIRCLE_ARTIFACTS diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/jobs/build_postgres.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/jobs/build_postgres.yml new file mode 100644 index 000000000..ec8593f42 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/jobs/build_postgres.yml @@ -0,0 +1,34 @@ +parameters: + ruby: + type: string + postgres: + type: string + rspec_glob: + type: string + default: "spec/**/*_spec.rb" + database_user: + type: string + default: "circleci-demo-ruby" + database_name: + type: string + default: "rails_blog" + database_password: + type: string + default: "" +environment: + - CIRCLE_TEST_REPORTS: test_results + - CIRCLE_ARTIFACTS: test_results + - DATABASE_URL: postgres://<< parameters.database_user >>:<< parameters.database_password >>@127.0.0.1:5432/<< parameters.database_name >> + - RAILS_ENV: test +docker: + - image: circleci/ruby:<< parameters.ruby >>-node + - image: circleci/postgres:<< parameters.postgres >>-alpine-ram + environment: + - POSTGRES_USER: "<< parameters.database_user >>" + - POSTGRES_DB: "<< parameters.database_name >>" + - POSTGRES_PASSWORD: "<< parameters.database_password >>" +steps: + - checkout + - bundle_install + - load_db + - run_rspec diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/orb.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/orb.yml new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/usage/build.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/usage/build.yml new file mode 100644 index 000000000..9e9ed3e34 --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/usage/build.yml @@ -0,0 +1,9 @@ +version: 2 + +workflows: + version: 2 + build-test-deploy: + jobs: + - rails/build_postgres: + ruby: "2.5.1" + postgres: "9.6.8" diff --git a/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/usage/generated_config.yml b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/usage/generated_config.yml new file mode 100644 index 000000000..cf7ba7afb --- /dev/null +++ b/cmd/testdata/test-with-large-nested-rails-orb/test/orbs/rails/usage/generated_config.yml @@ -0,0 +1,73 @@ +version: 2 +workflows: + version: 2 + build-test-deploy: + jobs: + - build_postgres: {} +jobs: + build_postgres: + environment: + - CIRCLE_TEST_REPORTS: test_results + - CIRCLE_ARTIFACTS: test_results + - DATABASE_URL: postgres://circleci-demo-ruby:@127.0.0.1:5432/rails_blog + - RAILS_ENV: test + docker: + - image: circleci/ruby:2.5.1-node + - image: circleci/postgres:9.6.8-alpine-ram + environment: + - POSTGRES_USER: circleci-demo-ruby + - POSTGRES_DB: rails_blog + - POSTGRES_PASSWORD: '' + steps: + - checkout + - run: + name: Configure bundler + command: | + bundle config jobs 3 + bundle config path vendor/bundle + bundle config retry 3 + - run: + name: Log versions for debugging + command: | + gem --version + bundle --version + - restore_cache: + name: Restore bundler cache + keys: + - rails-demo-bundle-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }} + - rails-demo-bundle-{{ arch }}-{{ .Branch }}- + - rails-demo-bundle-{{ arch }}-{{ Environment.DEFAULT_BRANCH }}- + - run: + name: Bundle Install + command: bundle check || bundle install + - run: + name: Clear unused bundle gems before saving cache + command: bundle clean --force + - save_cache: + key: rails-demo-bundle-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }} + paths: + - vendor/bundle + - run: + name: Wait for DB to initialize + command: dockerize -wait tcp://localhost:5432 -timeout 1m + - run: + name: Database setup + command: bin/rails db:schema:load --trace + - run: + name: Run rspec in parallel + command: | + # Determine test subset to run on each container and print diagnostics + TEST_FILES=$(circleci tests glob spec/**/*_spec.rb | \ + circleci tests split) + echo "running " $(echo $TEST_FILES | wc -w) " tests files on this container:" + echo "$TEST_FILES" + + bundle exec rspec --profile 10 \ + --format RspecJunitFormatter \ + --out CIRCLE_TEST_REPORTS/rspec.xml \ + --format documentation \ + $TEST_FILES + - store_test_results: + path: $CIRCLE_TEST_REPORTS + - store_artifacts: + path: $CIRCLE_ARTIFACTS From 007ff3acc4187d56605f0beae82d4607fa2497e0 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 17:00:13 +0900 Subject: [PATCH 7/8] Remove unused test from collapse and fold in testdata examples --- cmd/collapse_test.go | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/cmd/collapse_test.go b/cmd/collapse_test.go index c73c7cbfd..28ef77f4f 100644 --- a/cmd/collapse_test.go +++ b/cmd/collapse_test.go @@ -2,7 +2,6 @@ package cmd_test import ( "io/ioutil" - "os" "os/exec" "path/filepath" @@ -12,39 +11,6 @@ import ( ) var _ = Describe("collapse", func() { - var ( - tempRoot string - command *exec.Cmd - ) - - BeforeEach(func() { - var err error - tempRoot, err = ioutil.TempDir("", "circleci-cli-test-") - Expect(err).ToNot(HaveOccurred()) - - command = exec.Command(pathCLI, "collapse", "-r", tempRoot) - }) - - AfterEach(func() { - Expect(os.RemoveAll(tempRoot)).To(Succeed()) - }) - - Describe("with two YAML files within separate directory structures", func() { - BeforeEach(func() { - for _, dirName := range []string{"one", "two"} { - path := filepath.Join(tempRoot, "orbs", dirName, "commands") - Expect(os.MkdirAll(path, 0700)).To(Succeed()) - Expect(ioutil.WriteFile( - filepath.Join(path, "file.yml"), - []byte("contents_one: 1\ncontents_two: 2\n"), - 0600), - ).To(Succeed()) - } - }) - }) -}) - -var _ = Describe("collapse with testdata", func() { var ( command *exec.Cmd results []byte From dfe75317c7911650893ab3daaa4af640e4d6f1b3 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 22 Jun 2018 17:05:05 +0900 Subject: [PATCH 8/8] Missed references for working_directory fixes lint/deploy jobs --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 37a984d5d..5e2d75f43 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -52,7 +52,7 @@ jobs: lint: docker: - image: circleci/golang:1.10 - working_directory: /go/src/github.com/CircleCI/circleci-cli + working_directory: /go/src/github.com/CircleCI-Public/circleci-cli steps: - checkout - restore_cache: @@ -74,7 +74,7 @@ jobs: environment: GORELEASER_URL: https://github.com/goreleaser/goreleaser/releases/download/v0.77.1/goreleaser_amd64.deb - working_directory: /go/src/github.com/CircleCI/circleci-cli + working_directory: /go/src/github.com/CircleCI-Public/circleci-cli steps: - checkout - restore_cache: