Skip to content
Snippets Groups Projects
Commit ee44f9a4 authored by Rick Carback's avatar Rick Carback
Browse files

Collapse build to single stage

parent fbb8653b
Branches
Tags
No related merge requests found
# From: https://about.gitlab.com/2017/09/21/how-to-create-ci-cd-pipeline-with-autodeploy-to-kubernetes-using-gitlab-and-helm/
cache:
untracked: true
key: "$CI_BUILD_REF_NAME"
paths:
- vendor/
variables:
REPO_DIR: gitlab.com/elixxir
REPO_NAME: notifications-bot
DOCKER_IMAGE: golang:1.13.4-buster
DOCKER_IMAGE: elixxirlabs/cuda-go:latest
MIN_CODE_COVERAGE: "0.0"
before_script:
......@@ -23,60 +17,39 @@ before_script:
- chmod 700 ~/.ssh
- ssh-keyscan -t rsa gitlab.com > ~/.ssh/known_hosts
- git config --global url."git@gitlab.com:".insteadOf "https://gitlab.com/"
- export GOFLAGS=-mod=vendor
- export PATH=$HOME/go/bin:$PATH
- export GOPRIVATE=gitlab.com/elixxir/*
stages:
- setup
- test
- build
- tag
- trigger_integration
setup:
stage: setup
build:
stage: build
image: $DOCKER_IMAGE
except:
- tags
script:
- git clean -ffdx
- go mod vendor -v
- go build ./...
- go mod tidy
artifacts:
paths:
- vendor/
test:
stage: test
image: $DOCKER_IMAGE
except:
- tags
script:
- GO111MODULE=off go get -u github.com/haya14busa/goverage
- apt-get update
- apt-get install bc -y
- mkdir -p testdata
# Test coverage
- goverage -coverprofile=testdata/coverage-real.out -v ./... 2>&1 | grep -v "no packages being tested depend on"
- go-acc --covermode atomic --output testdata/coverage.out ./... -- -v
# Exclude cmd from test coverage as it is command line related tooling
# - grep -v -e cmd testdata/coverage.out > testdata/coverage-real.out
- go tool cover -func=testdata/coverage-real.out
- go tool cover -html=testdata/coverage-real.out -o testdata/coverage.html
- go tool cover -func=testdata/coverage.out
- go tool cover -html=testdata/coverage.out -o testdata/coverage.html
# Test Coverage Check
- go tool cover -func=testdata/coverage-real.out | grep "total:" | awk '{print $3}' | sed 's/\%//g' > testdata/coverage-percentage.txt
- go tool cover -func=testdata/coverage.out | grep "total:" | awk '{print $3}' | sed 's/\%//g' > testdata/coverage-percentage.txt
- export CODE_CHECK=$(echo "$(cat testdata/coverage-percentage.txt) >= $MIN_CODE_COVERAGE" | bc -l)
- (if [ "$CODE_CHECK" == "1" ]; then echo "Minimum coverage of $MIN_CODE_COVERAGE succeeded"; else echo "Minimum coverage of $MIN_CODE_COVERAGE failed"; exit 1; fi);
artifacts:
paths:
- testdata/
build:
stage: build
image: $DOCKER_IMAGE
except:
- tags
script:
- mkdir -p release
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' ./...
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/notifications.linux64 main.go
......@@ -85,10 +58,12 @@ build:
- GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/notifications.darwin64 main.go
artifacts:
paths:
- vendor/
- testdata/
- release/
tag:
stage: tag
stage: trigger_integration
only:
- master
image: $DOCKER_IMAGE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment