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
No related branches found
No related tags found
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/ # 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: variables:
REPO_DIR: gitlab.com/elixxir REPO_DIR: gitlab.com/elixxir
REPO_NAME: notifications-bot REPO_NAME: notifications-bot
DOCKER_IMAGE: golang:1.13.4-buster DOCKER_IMAGE: elixxirlabs/cuda-go:latest
MIN_CODE_COVERAGE: "0.0" MIN_CODE_COVERAGE: "0.0"
before_script: before_script:
...@@ -23,60 +17,39 @@ before_script: ...@@ -23,60 +17,39 @@ before_script:
- chmod 700 ~/.ssh - chmod 700 ~/.ssh
- ssh-keyscan -t rsa gitlab.com > ~/.ssh/known_hosts - ssh-keyscan -t rsa gitlab.com > ~/.ssh/known_hosts
- git config --global url."git@gitlab.com:".insteadOf "https://gitlab.com/" - 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: stages:
- setup
- test
- build - build
- tag
- trigger_integration - trigger_integration
setup: build:
stage: setup stage: build
image: $DOCKER_IMAGE image: $DOCKER_IMAGE
except: except:
- tags - tags
script: script:
- git clean -ffdx
- go mod vendor -v - go mod vendor -v
- go build ./... - go build ./...
- go mod tidy - 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 update
- apt-get install bc -y - apt-get install bc -y
- mkdir -p testdata - mkdir -p testdata
# Test coverage # 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 # Exclude cmd from test coverage as it is command line related tooling
# - grep -v -e cmd testdata/coverage.out > testdata/coverage-real.out # - grep -v -e cmd testdata/coverage.out > testdata/coverage-real.out
- go tool cover -func=testdata/coverage-real.out - go tool cover -func=testdata/coverage.out
- go tool cover -html=testdata/coverage-real.out -o testdata/coverage.html - go tool cover -html=testdata/coverage.out -o testdata/coverage.html
# Test Coverage Check # 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) - 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); - (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 - 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' ./...
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/notifications.linux64 main.go - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/notifications.linux64 main.go
...@@ -85,10 +58,12 @@ build: ...@@ -85,10 +58,12 @@ build:
- GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/notifications.darwin64 main.go - GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/notifications.darwin64 main.go
artifacts: artifacts:
paths: paths:
- vendor/
- testdata/
- release/ - release/
tag: tag:
stage: tag stage: trigger_integration
only: only:
- master - master
image: $DOCKER_IMAGE image: $DOCKER_IMAGE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment