Skip to content

Commit

Permalink
CircleCI workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jun 26, 2019
1 parent 2dc8423 commit 3ba1c8a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 44 deletions.
7 changes: 7 additions & 0 deletions .circleci/check-coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -euo pipefail
go get github.com/mattn/goveralls

go test -coverprofile=/tmp/coverage.out -coverpkg=./... $(go list github.com/99designs/gqlgen/... | grep -v server)
goveralls -coverprofile=/tmp/coverage.out -service=circle-ci -repotoken=$REPOTOKEN -ignore='example/*/*,example/*/*/*,integration/*,integration/*/*,codegen/testserver/*'
10 changes: 10 additions & 0 deletions .circleci/check-fmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -euo pipefail

go fmt ./...
if [[ $(git --no-pager diff) ]] ; then
echo "you need to run "go fmt" and commit the changes"
git --no-pager diff
exit 1
fi
11 changes: 11 additions & 0 deletions .circleci/check-generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -euo pipefail

go generate ./...

if [[ $(git --no-pager diff) ]] ; then
echo "you need to run "go generate ./..." and commit the changes"
git --no-pager diff
exit 1
fi
7 changes: 7 additions & 0 deletions .circleci/check-linting
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -euo pipefail

curl -sL --fail https://github.com/golangci/golangci-lint/releases/download/v1.13/golangci-lint-1.13-linux-amd64.tar.gz | tar zxv --strip-components=1 --dir=/go/bin

golangci-lint run
125 changes: 81 additions & 44 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,89 @@
version: 2
jobs:
build:
working_directory: /app
lint:
docker:
- image: docker:18
- image: circleci/golang:1.12
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: "docker build"
command: |
docker build -f .circleci/golang.Dockerfile -t gqlgen/golang .
docker build -f .circleci/node.Dockerfile -t gqlgen/node .
- run: go mod download
- run: .circleci/check-fmt
- run: .circleci/check-linting
- run: .circleci/check-generate

- run:
name: "coverage"
command: docker run -e REPOTOKEN --rm gqlgen/golang .circleci/coverage.sh

- run:
name: "golang tests"
command: docker run --rm gqlgen/golang .circleci/test.sh

- run:
name: "integration tests"
command: |
function cleanup {
echo "Cleaning up containers..."
docker kill $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
docker rm --force -v $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
}
trap cleanup EXIT
SERVER_CONTAINER=$(docker run -d \
-e PORT=1234 \
--name integration_server \
gqlgen/golang go run ./integration/server/server.go \
)
sleep 20
docker run \
-e SERVER_URL=http://integration_server:1234/query \
--link=integration_server \
gqlgen/node ../.circleci/integration.sh
echo "### server logs"
docker logs $SERVER_CONTAINER
test:
docker:
- image: circleci/golang:1.12
steps:
- checkout
- run: go mod download
- run: go test -race ./...

exit $(docker inspect $SERVER_CONTAINER --format='{{.State.ExitCode}}')
cover:
docker:
- image: circleci/golang:1.12
steps:
- checkout
- run: go mod download
- run: .circleci/check-coverage

workflows:
version: 2
build_and_test:
jobs:
- lint
- test
- cover
#
#
# build:
# working_directory: /app
# docker:
# - image: golang:1.12
# steps:
#
# steps:
# - checkout
# - setup_remote_docker:
# docker_layer_caching: true
# - run:
# name: "docker build"
# command: |
# docker build -f .circleci/golang.Dockerfile -t gqlgen/golang .
# docker build -f .circleci/node.Dockerfile -t gqlgen/node .
#
# - run:
# name: "coverage"
# command: docker run -e REPOTOKEN --rm gqlgen/golang .circleci/coverage.sh
#
# - run:
# name: "golang tests"
# command: docker run --rm gqlgen/golang .circleci/test.sh
#
# - run:
# name: "integration tests"
# command: |
# function cleanup {
# echo "Cleaning up containers..."
# docker kill $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
# docker rm --force -v $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
# }
# trap cleanup EXIT
#
# SERVER_CONTAINER=$(docker run -d \
# -e PORT=1234 \
# --name integration_server \
# gqlgen/golang go run ./integration/server/server.go \
# )
#
# sleep 20
#
# docker run \
# -e SERVER_URL=http://integration_server:1234/query \
# --link=integration_server \
# gqlgen/node ../.circleci/integration.sh
#
# echo "### server logs"
# docker logs $SERVER_CONTAINER
#
# exit $(docker inspect $SERVER_CONTAINER --format='{{.State.ExitCode}}')
#

0 comments on commit 3ba1c8a

Please sign in to comment.