Skip to content

Commit d191d18

Browse files
committed
Updated circleci
1 parent 35586e7 commit d191d18

File tree

3 files changed

+69
-31
lines changed

3 files changed

+69
-31
lines changed

.circleci/config.yml

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,67 @@
1-
# Golang CircleCI 2.0 configuration file
2-
#
3-
# Check https://circleci.com/docs/2.0/language-go/ for more details
4-
version: 2
1+
version: 2.1
52
jobs:
3+
test:
4+
docker:
5+
- image: circleci/golang:1.14
6+
working_directory: ~/golang-example-app
7+
steps:
8+
- checkout
9+
- run:
10+
name: Fetch dependencies
11+
command: go mod download
12+
- run:
13+
name: Test
14+
command: |
15+
APP_WD=~/golang-example-app/resources
16+
go test ./...
617
build:
718
docker:
8-
# specify the version
9-
- image: circleci/golang:1.9
10-
11-
# Specify service dependencies here if necessary
12-
# CircleCI maintains a library of pre-built images
13-
# documented at https://circleci.com/docs/2.0/circleci-images/
14-
# - image: circleci/postgres:9.4
15-
16-
#### TEMPLATE_NOTE: go expects specific checkout path representing url
17-
#### expecting it in the form of
18-
#### /go/src/github.com/circleci/go-tool
19-
#### /go/src/bitbucket.org/circleci/go-tool
20-
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
19+
- image: circleci/golang:1.14
20+
working_directory: ~/golang-example-app
2121
steps:
2222
- checkout
23-
24-
# specify any bash command here prefixed with `run: `
25-
- run: go get -v -t -d ./...
26-
- run: go test -v ./...
23+
- run:
24+
name: Fetch dependencies
25+
command: go mod download
26+
- run:
27+
name: Building
28+
command: |
29+
VERSION=${CIRCLE_TAG}
30+
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o bin/app-${VERSION}-linux-amd64 main.go
31+
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o bin/app-${VERSION}-darwin-amd64 main.go
32+
- persist_to_workspace:
33+
root: .
34+
paths:
35+
- bin
36+
publish-github-release:
37+
docker:
38+
- image: cibuilds/github:0.13
39+
steps:
40+
- attach_workspace:
41+
at: ~/golang-example-app
42+
- run:
43+
name: "Publish Release on GitHub"
44+
command: |
45+
VERSION=${CIRCLE_TAG}
46+
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ~/golang-example-app/bin
47+
workflows:
48+
version: 2
49+
main:
50+
jobs:
51+
- test
52+
release:
53+
jobs:
54+
- build:
55+
filters:
56+
branches:
57+
ignore: /.*/
58+
tags:
59+
only: /^v\d+\.\d+\.\d+.*/
60+
- publish-github-release:
61+
requires:
62+
- build
63+
filters:
64+
branches:
65+
ignore: /.*/
66+
tags:
67+
only: /^v\d+\.\d+\.\d+.*/

Makefile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ init: ## init packages
3030
start: ## start daemon on development mode
3131
./artifacts/bin daemon -c ./artifacts/configs/development.yaml -d
3232

33-
vendor: ## generate vendor
34-
rm -rf $(GO_DIR)/vendor ;\
35-
GO111MODULE=on \
36-
go mod vendor
33+
dependencies: ## generate dependencies
34+
go mod download
3735

3836
gqlgen-generate: ## generate graphql server
3937
go run github.com/99designs/gqlgen
@@ -44,16 +42,15 @@ prototool-generate: ## generate proto file
4442
build: init ## build binary file
4543
$(call build_resources) ;\
4644
GO111MODULE=on GOOS=${GOOS} CGO_ENABLED=${CGO_ENABLED} GOARCH=${GOARCH} \
47-
go build -mod vendor -ldflags "-X $(GO_PKG)/cmd/version.appVersion=$(TAG)-$$(date -u +%Y%m%d%H%M)" -o "$(GO_DIR)/artifacts/bin" main.go
45+
go build -ldflags "-X $(GO_PKG)/cmd/version.appVersion=$(TAG)-$$(date -u +%Y%m%d%H%M)" -o "$(GO_DIR)/artifacts/bin" main.go
4846

4947
docker-image: ## build docker image
5048
REMOVE_CONTAINERS=${REMOVE_CONTAINERS} DOCKER_IMAGE=${DOCKER_IMAGE} ./scripts/remove_docker_containers.sh
5149
docker rmi ${DOCKER_IMAGE}:${TAG} -f || true ;\
5250
docker build --cache-from ${DOCKER_IMAGE}:${CACHE_TAG} -f "${GO_DIR}/docker/app/Dockerfile" -t ${DOCKER_IMAGE}:${TAG} ${GO_DIR}
5351

5452
test: ## test application with race
55-
GO111MODULE=on \
56-
go test -mod vendor -race -v ./...
53+
go test -v ./...
5754

5855
coverage: ## test coverage
5956
go test -coverprofile=coverage.out ./...
@@ -65,7 +62,7 @@ createdb: ## create database
6562
dropdb: ## drop database
6663
dropdb $(DATABASE_URL)
6764

68-
.PHONY: install init vendor gqlgen-generate prototool-generate
65+
.PHONY: install init dependencies gqlgen-generate prototool-generate
6966

7067
help:
7168
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ Sql migrations
8888
sql-migrate up
8989
```
9090

91-
Install Golang packages to vendor
91+
Install Golang dependencies
9292

9393
```$xslt
94-
make vendor
94+
make dependencies
9595
```
9696

9797
Generate artifacts(binary files and configs)

0 commit comments

Comments
 (0)