Skip to content

Commit

Permalink
Merge branch 'docker' of github.com:CircleCI-Public/circleci-cli into…
Browse files Browse the repository at this point in the history
… docker
  • Loading branch information
marcomorain committed Jun 26, 2018
2 parents e5c7428 + 78e3a86 commit 2926d0d
Show file tree
Hide file tree
Showing 51 changed files with 1,364 additions and 113 deletions.
56 changes: 39 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,35 @@ workflows:
- test
- coverage
- lint
- deploy:
- deploy_github_release:
requires:
- test
- coverage
- lint disable lint check for now
filters:
branches:
only: master
- deploy_docker:
requires:
- test
- coverage
# - lint disable lint check for now
# filters:
# branches:
# only: master

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
Expand All @@ -52,7 +60,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:
Expand All @@ -68,25 +76,14 @@ jobs:
key: v1-gometalinter-{{ checksum "/go/bin/gometalinter" }}
paths: [/go/bin/*]

# Build a docker image
docker:
docker:
- image: circleci/golang:1.10.3
steps:
- checkout
- setup_remote_docker
- run: make
- run:


deploy:
deploy_github_release:
working_directory: /go/src/github.com/circleci/circleci-cli
docker:
- image: circleci/golang:1.10
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:
Expand All @@ -109,3 +106,28 @@ jobs:
- save_cache:
key: v2-goreleaser-{{ checksum "~/goreleaser_amd64.deb" }}
paths: [~/goreleaser_amd64.deb]

deploy_docker:
docker:
- image: circleci/command-convenience:0.1.392-2e3ae33
environment:
NAME: circleci-cli
CONTAINER_ORG: circlecidx
DOCKERFILE_PATH: Dockerfile
DOCKER_REGISTRY: dockerhub
working_directory: /go/src/github.com/circleci/circleci-cli
steps:
- setup_docker_engine:
docker_layer_caching: true
- checkout
- run:
name: Build the binary
command: make
- run:
name: Build and push circleci-cli image
command: publish
- run:
name: Update the "latest" tag
command: publish
environment:
CONTAINER_VERSION: latest
33 changes: 32 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 8 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]/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.
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package client

import (
"context"
"fmt"

"github.com/circleci/circleci-cli/logger"
"github.com/CircleCI-Public/circleci-cli/logger"
"github.com/machinebox/graphql"
)

Expand All @@ -15,7 +16,7 @@ func NewClient(endpoint string, logger *logger.Logger) *graphql.Client {
client := graphql.NewClient(endpoint)

client.Log = func(s string) {
logger.Debug(s)
logger.Debug(fmt.Sprintf("[machinebox/graphql] %s", s))
}

return client
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})

Expand Down
11 changes: 2 additions & 9 deletions cmd/collapse.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,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"
)
Expand All @@ -20,13 +18,8 @@ func init() {
collapseCommand.Flags().StringVarP(&root, "root", "r", ".circleci", "path to your configuration (default is .circleci)")
}

func specialCase(path string) bool {
re := regexp.MustCompile(`orb\.(yml|yaml)$`)
return re.MatchString(path)
}

func collapse(cmd *cobra.Command, args []string) {
tree, err := filetree.NewTree(root, specialCase)
tree, err := filetree.NewTree(root)
if err != nil {
Logger.FatalOnError("An error occurred trying to build the tree", err)
}
Expand Down
93 changes: 59 additions & 34 deletions cmd/collapse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd_test

import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"

Expand All @@ -13,54 +12,80 @@ import (

var _ = Describe("collapse", func() {
var (
tempRoot string
command *exec.Cmd
command *exec.Cmd
results []byte
)

BeforeEach(func() {
var err error
tempRoot, err = ioutil.TempDir("", "circleci-cli-test-")
Expect(err).ToNot(HaveOccurred())
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/result.yml")
Expect(err).ShouldNot(HaveOccurred())
})

command = exec.Command(pathCLI, "collapse", "-r", tempRoot)
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))
})
})

AfterEach(func() {
Expect(os.RemoveAll(tempRoot)).To(Succeed())
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())
})

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("with two YAML files within separate directory structures", func() {
Describe("an orb containing local executors and commands in folder", 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 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 using directory structure as keys", func() {
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))
})
})

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
`))
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))
})
})
Expand Down
Loading

0 comments on commit 2926d0d

Please sign in to comment.