-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
202 lines (187 loc) · 7.68 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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
- version_check
test:
stage: test
image: $DOCKER_IMAGE
except:
- tags
script:
- git clean -ffdx
- go mod vendor -v
- 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 cmd | grep -v mockserver | grep -v pb[.]go | grep -v main.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/
wasm-test:
stage: test
image: $DOCKER_IMAGE
except:
- tags
script:
- export PATH=/root/go/bin:$PATH
- go mod vendor
# Remove some environment vars to deal with: https://github.com/agnivade/wasmbrowsertest/issues/40
- unset SSH_PRIVATE_KEY
- unset $(env | grep '=' | awk -F= '{print $1}' | grep -v PATH | grep -v GO | grep -v HOME)
- GOOS=js GOARCH=wasm go test ./... -v
build:
stage: build
image: $DOCKER_IMAGE
except:
- tags
script:
- go mod vendor -v
- make version
- 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/client.linux64 main.go
# - GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/client.win64 main.go
# - GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/client.win32 main.go
- GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/client.darwin64 main.go
- /upload-artifacts.sh release/
artifacts:
paths:
- release/
tag:
stage: trigger_integration
only:
- master
image: $DOCKER_IMAGE
script:
# Get the version number from the built binary
- export TAG=$(release/client.linux64 version | grep "Elixxir Client v"| cut -d ' ' -f3)
# Poll the GitLab API to see if the tag exists
- 'TAG_JSON=$(curl --header "PRIVATE-TOKEN: $GITLAB_ACCESS_TOKEN" "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/tags/$TAG")'
# Debug information
- echo $TAG_JSON
# If the API says the tag doesn't exist, create it for the current commit
#
# Note: if we want to fail because this is not a unique version number, we can simply do "else; echo non-unique version && return -1; fi" instead of "fi".
# That would be a much cleaner way (IMO) to do the unique version number check Ben wanted than the previous horrible Git hack.
- 'if echo $TAG_JSON | grep -q "404 Tag Not Found"; then curl --request POST --header "PRIVATE-TOKEN: $GITLAB_ACCESS_TOKEN" "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/tags?tag_name=$TAG&ref=$CI_COMMIT_SHA"; fi'
bindings-ios:
stage: build
dependencies: []
except:
- tags
tags:
- ios
script:
- export PATH=/opt/homebrew/bin:$PATH:$HOME/go/bin
- mc --version
- go mod tidy
- rm -rf vendor/
- export PODVERSION=$(go run main.go version | head -1 | awk '{print $3}' | sed 's/v//g')
- go build ./...
- go get golang.org/x/mobile/bind
- go install golang.org/x/mobile/cmd/gomobile@latest
- gomobile init
- gomobile bind -v -target ios,iossimulator,macos gitlab.com/elixxir/client/v4/bindings
- python3 bindings-checker.py Bindings.xcframework/ios-arm64/Bindings.framework/Headers/Bindings.objc.h
- ls
# Package and upload the bindings to S3 for Xcode's package manager
- cp LICENSE Bindings.xcframework/
- zip -r -y iOS.zip Bindings.xcframework
- sync # Force disc flush
- cp iOS.zip iOS-$CI_COMMIT_SHA.zip
- sync # Force disc flush
- mc alias set elixxir-s3 $ARTIFACT_S3_ENDPOINT $ARTIFACT_S3_KEY $ARTIFACT_S3_SECRET
- swift package compute-checksum iOS-$CI_COMMIT_SHA.zip > iOS-$CI_COMMIT_SHA.zip.checksum && cat iOS-$CI_COMMIT_SHA.zip.checksum
- mc cp iOS-$CI_COMMIT_SHA.zip elixxir-s3/$ARTIFACT_S3_BUCKET/bindings-ios/iOS-$CI_COMMIT_SHA.zip
- mc cp iOS-$CI_COMMIT_SHA.zip.checksum elixxir-s3/$ARTIFACT_S3_BUCKET/bindings-ios/iOS-$CI_COMMIT_SHA.zip.checksum
# Verify the uploaded file
- curl http://elixxir-bins.s3-us-west-1.amazonaws.com/bindings-ios/iOS-$CI_COMMIT_SHA.zip | shasum -a 256 - | awk '{print $1;}' > aws-sum-dl.txt
- curl http://elixxir-bins.s3-us-west-1.amazonaws.com/bindings-ios/iOS-$CI_COMMIT_SHA.zip.checksum > aws-sum-computed.txt
- diff aws-sum-dl.txt aws-sum-computed.txt
# Release package folder (used for Cocoapods) - NEEDS CLEANUP
- mkdir -p ios-release
- cp iOS.zip ios-release/XXDK-$PODVERSION.zip
- cp iOS-$CI_COMMIT_SHA.zip.checksum ios-release/XXDK-$PODVERSION.zip.checksum
- mc cp iOS-$CI_COMMIT_SHA.zip elixxir-s3/$ARTIFACT_S3_BUCKET/release-ios/XXDK-$PODVERSION.zip
- mc cp iOS-$CI_COMMIT_SHA.zip.checksum elixxir-s3/$ARTIFACT_S3_BUCKET/release-ios/XXDK-$PODVERSION.zip.checksum
artifacts:
paths:
- iOS.zip
- ios-release
expire_in: never
bindings-android:
stage: build
image: $ANDROID_DOCKER_IMAGE
dependencies: []
except:
- tags
script:
- export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin:/android-sdk/platform-tools/
- export ANDROID_HOME=/android-sdk
# Build the bindings
- go mod tidy
- rm -rf vendor/
- go build ./...
- go get golang.org/x/mobile/bind
- go install golang.org/x/mobile/cmd/gomobile@latest
- gomobile init
- gomobile bind -v -target android -androidapi 21 gitlab.com/elixxir/client/v4/bindings
artifacts:
paths:
- bindings.aar
- bindings-sources.jar
# This pipeline job will attempt to have pkg.go.dev update docs for client/xxdk.
#
# pkg.go.dev relies on the proxy.golang.org service (go module cache/proxy) to discover versions of
# Go modules to make docs of. The proxy keeps a list of all known versions of Go modules. The go
# mod proxy does cache pulls for about 30 minutes, so if quickly successive commits are done in
# master/release, this will fail to pull the latest client, and the docs will not update.
trigger-doc-update:
stage: trigger_integration
image: $DOCKER_IMAGE
script:
# We use GOPRIVATE blank because not want to directly pull client, we want to use the public cache.
- GOPRIVATE="" go install gitlab.com/elixxir/client@$CI_COMMIT_REF_NAME
only:
- release
- master
trigger-integration:
stage: trigger_integration
trigger:
project: elixxir/integration
branch: $CI_COMMIT_REF_NAME
only:
- master
- release
trigger-udb:
stage: trigger_integration
trigger:
project: elixxir/user-discovery-bot
branch: $CI_COMMIT_REF_NAME
only:
- master
- release