Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Added genny support for CircleCI as a CI provider. #1972

Merged
merged 3 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buffalo/cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func init() {
newCmd.Flags().Bool("skip-yarn", false, "use npm instead of yarn for frontend dependencies management")
newCmd.Flags().String("db-type", "postgres", fmt.Sprintf("specify the type of database you want to use [%s]", strings.Join(pop.AvailableDialects, ", ")))
newCmd.Flags().String("docker", "multi", "specify the type of Docker file to generate [none, multi, standard]")
newCmd.Flags().String("ci-provider", "none", "specify the type of ci file you would like buffalo to generate [none, travis, gitlab-ci]")
newCmd.Flags().String("ci-provider", "none", "specify the type of ci file you would like buffalo to generate [none, travis, gitlab-ci, circleci]")
newCmd.Flags().String("vcs", "git", "specify the Version control system you would like to use [none, git, bzr]")
newCmd.Flags().String("module", "", "specify the root module (package) name. [defaults to 'automatic']")
viper.BindPFlags(newCmd.Flags())
Expand Down
4 changes: 3 additions & 1 deletion genny/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/gobuffalo/packr/v2"
)

// New generator for adding travis or gitlab
// New generator for adding travis, gitlab, or circleci
func New(opts *Options) (*genny.Generator, error) {
g := genny.New()

Expand All @@ -32,6 +32,8 @@ func New(opts *Options) (*genny.Generator, error) {
} else {
fname = "-dot-gitlab-ci-no-pop.yml.tmpl"
}
case "circleci":
fname = "-dot-circleci/config.yml.tmpl"
default:
return g, fmt.Errorf("could not find a template for %s", opts.Provider)
}
Expand Down
27 changes: 27 additions & 0 deletions genny/ci/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,30 @@ func Test_New_Gitlab_No_pop(t *testing.T) {
r.Equal(".gitlab-ci.yml", f.Name())
r.NotContains(f.String(), "postgres:5432")
}

func Test_New_Circle(t *testing.T) {
r := require.New(t)

g, err := New(&Options{
Provider: "circleci",
DBType: "postgres",
})
r.NoError(err)

run := gentest.NewRunner()
run.With(g)

r.NoError(run.Run())

res := run.Results()

r.Len(res.Commands, 0)
r.Len(res.Files, 1)

f := res.Files[0]
r.Equal(".circleci/config.yml", f.Name())
circleYml := struct {
Version int
}{}
r.NoError(yaml.NewDecoder(f).Decode(&circleYml), "config.yml is a valid YAML file")
}
2 changes: 1 addition & 1 deletion genny/ci/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// Available CI implementations
var Available = []string{"travis", "gitlab"}
var Available = []string{"travis", "gitlab", "circleci"}

// Options for CI
type Options struct {
Expand Down
45 changes: 45 additions & 0 deletions genny/ci/templates/-dot-circleci/config.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.12
{{ if eq .opts.DBType "postgres" -}}
- image: circleci/postgres:9.6-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_DB: {{.opts.App.Name.File}}_test
{{- end }}

environment:
TEST_RESULTS: /tmp/test-results

steps:
- checkout
- run: mkdir -p $TEST_RESULTS

- restore_cache:
keys:
- v1-pkg-cache

- run: go get github.com/jstemmer/go-junit-report

- run: go get github.com/gobuffalo/buffalo/buffalo
- run: go mod download

- run:
name: Run unit tests
command: |
trap "go-junit-report <${TEST_RESULTS}/go-test.out > ${TEST_RESULTS}/go-test-report.xml" EXIT
paganotoni marked this conversation as resolved.
Show resolved Hide resolved
buffalo test | tee ${TEST_RESULTS}/go-test.out

- save_cache:
key: v1-pkg-cache
paths:
- "/go/pkg"

- store_artifacts:
path: /tmp/test-results
destination: raw-test-output

- store_test_results:
path: /tmp/test-results
2 changes: 1 addition & 1 deletion genny/ci/templates/-dot-gitlab-ci-no-pop.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ before_script:
- cd /go/src/{{.opts.App.PackagePkg}}
- mkdir -p public/assets
- go get -u github.com/gobuffalo/buffalo/buffalo
- go get -t -v ./...
- go mod download
- export PATH="$PATH:$GOPATH/bin"

stages:
Expand Down
2 changes: 1 addition & 1 deletion genny/ci/templates/-dot-gitlab-ci.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ before_script:
- cd /go/src/{{.opts.App.PackagePkg}}
- mkdir -p public/assets
- go get -u github.com/gobuffalo/buffalo/buffalo
- go get -t -v ./...
- go mod download
- export PATH="$PATH:$GOPATH/bin"

stages:
Expand Down
2 changes: 1 addition & 1 deletion genny/ci/templates/-dot-travis.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ go_import_path: {{.opts.App.PackagePkg}}

install:
- go get github.com/gobuffalo/buffalo/buffalo
- go get $(go list ./... | grep -v /vendor/)
- go mod download

script: buffalo test
323 changes: 154 additions & 169 deletions packrd/packed-packr.go

Large diffs are not rendered by default.