-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
121 lines (110 loc) · 4.04 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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/
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
- git config --global --replace-all url."git@$GITLAB_SERVER:".insteadOf "https://gitlab.com/"
- git config --global --replace-all url."git@$GITLAB_SERVER:".insteadOf "https://git.xx.network/" --add
- export PATH=$HOME/go/bin:$PATH
stages:
- setup
- test
- build
- tag
- trigger_integration
setup:
stage: setup
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:
- mkdir -p testdata
# Test coverage
- 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
- grep -v -e trackRounds 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
# 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:
- testdata/
build:
stage: build
image: $DOCKER_IMAGE
except:
- tags
script:
- mkdir -p release
- GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '-w -s' ./...
- GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '-w -s' -o release/registration.linux64 main.go
- GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -ldflags '-w -s' -o release/registration.win64 main.go
# - GOOS=windows GOARCH=386 CGO_ENABLED=1 go build -ldflags '-w -s' -o release/registration.win32 main.go
- /upload-artifacts.sh release/
- /hash-file.sh release/registration.linux64
artifacts:
paths:
- release/
build-macos:
stage: build
image: $DOCKER_IMAGE
tags:
- ios
except:
- tags
script:
# We removed the upload-artifacts.sh here because nothing was ever written to it (see above build job) and it doesn't exist on the macOS runner
- mkdir -p release
- GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '-w -s' -o release/registration.darwin64 main.go
- if [ "$CI_COMMIT_REF_NAME" != "master" ] && [ "$CI_COMMIT_REF_NAME" != "release" ] && [ "$ARTIFACT_BRANCH_BYPASS" != "yes" ]; then echo 'Branch is not master or release, aborting script'; exit 0; fi
- mc alias set elixxir-s3 $ARTIFACT_S3_ENDPOINT $ARTIFACT_S3_KEY $ARTIFACT_S3_SECRET
- mc cp release/registration.darwin64 elixxir-s3/$ARTIFACT_S3_BUCKET/registration/registration.darwin64
artifacts:
paths:
- release/
tag:
stage: tag
only:
- master
image: $DOCKER_IMAGE
script:
- git remote add origin_tags git@git.xx.network:elixxir/registration.git || true
- git remote set-url origin_tags git@git.xx.network:elixxir/registration.git || true
- git tag $(./release/registration.linux64 version | grep "xx network Permissioning Server v"| cut -d ' ' -f5) -f
- git push origin_tags -f --tags
trigger_integration:
stage: trigger_integration
trigger:
project: elixxir/integration
branch: $CI_COMMIT_REF_NAME
only:
- release
- master