-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
73 lines (65 loc) · 2.05 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
cache:
untracked: true
key: "$CI_BUILD_REF_NAME"
paths:
- vendor/
before_script:
- go version || echo "Go executable not found."
- echo $CI_BUILD_REF
- echo $CI_PROJECT_DIR
- echo $PWD
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -t rsa $GITLAB_SERVER > ~/.ssh/known_hosts
- rm -rf ~/.gitconfig
- git config --global url."git@$GITLAB_SERVER:".insteadOf "https://gitlab.com/"
- git config --global url."git@$GITLAB_SERVER:".insteadOf "https://git.xx.network/" --add
- export PATH=$HOME/go/bin:$PATH
stages:
- test
- build
- trigger_integration
test:
stage: test
image: $DOCKER_IMAGE
script:
- git clean -ffdx
- go mod vendor -v
- go mod tidy
- go build ./...
- mkdir -p testdata
# Test coverage
- go-acc --covermode atomic --output testdata/coverage.out ./... -- -v
# Exclude some specific packages and files
- cat testdata/coverage.out | grep -v pb[.]go > testdata/coverage-real.out
- go tool cover -func=testdata/coverage-real.out
- go tool cover -html=testdata/coverage-real.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
- 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:
- vendor/
- testdata/
build:
stage: build
image: $DOCKER_IMAGE
script:
- go mod vendor -v
- go build ./...
- mkdir -p release
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' ./...
- cd release
artifacts:
paths:
- release/
trigger-integration:
stage: trigger_integration
trigger:
project: elixxir/integration
branch: $CI_COMMIT_REF_NAME
only:
- master