-
Notifications
You must be signed in to change notification settings - Fork 5
/
.gitlab-ci.yml
229 lines (206 loc) · 5.16 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
image: alpine:latest
stages:
- init
- test
- build
- release
# Allows caching of the bin and pkg outside of repo path
before_script:
- rm -rf /go/bin || true
- tar -xzf .bin-cache.tar.gz -C / || true
- rm -rf /go/pkg || true
- tar -xzf .pkg-cache.tar.gz -C / || true
after_script:
- tar -czf .bin-cache.tar.gz /go/bin || true
- tar -czf .pkg-cache.tar.gz /go/pkg || true
cache:
paths:
- .bin-cache.tar.gz
- .pkg-cache.tar.gz
policy: pull
init:
image: golang:1-stretch
stage: init
cache:
paths:
- .bin-cache.tar.gz
- .pkg-cache.tar.gz
policy: push
script:
- go install golang.org/x/lint/golint
# This build will trigger vgo to install all packages
- go build -o depcharge
- ./depcharge -h
- export VERSION=$(echo $CI_COMMIT_SHA| cut -c1-7)
- export VERSION=$(if [ -z $CI_COMMIT_TAG ]; then echo $VERSION ; else echo $CI_COMMIT_TAG.$VERSION; fi)
- echo -n $VERSION | tee VERSION.txt
- echo
artifacts:
expire_in: 10 minutes
paths:
- VERSION.txt
- src/
gofmt:
image: golang:1-stretch
stage: test
cache: {}
script:
- > # Test for gofmt smells
if [[ $(gofmt -s -d *.go) ]]; then
gofmt -s -d *.go
echo "gofmt changes detected"
exit -1
fi
golint:
image: golang:1-stretch
stage: test
dependencies:
- init
script:
# Test for golint smells
- golint -set_exit_status
test:
image: golang:1-stretch
stage: test
dependencies:
- init
coverage: '/coverage: \d+\.\d+\%/'
variables:
COVER_STRICT: "true"
script:
# Generate code coverage report
- . ./scripts/create-coverage.sh
artifacts:
expire_in: 1 week
paths:
- coverage.html
build-linux:
image: golang:1-alpine
stage: build
dependencies:
- init
variables:
CGO_ENABLED: 0
GOOS: "linux"
GOARCH: "amd64"
script:
- export VERSION=$(cat VERSION.txt)
- if [ -n "${CI_COMMIT_TAG-}" ]; then export EXTRA_FLAGS="-w -s"; fi
- go build -ldflags="$EXTRA_FLAGS -X main.version=$VERSION" -o depcharge-linux .
artifacts:
expire_in: 1 week
paths:
- depcharge-linux
build-mac:
image: golang:1-alpine
stage: build
dependencies:
- init
variables:
CGO_ENABLED: 0
GOOS: "darwin"
GOARCH: "amd64"
script:
- export VERSION=$(cat VERSION.txt)
- go build -a -ldflags="-w -s -X main.version=$VERSION" -o depcharge-mac .
artifacts:
expire_in: 1 week
paths:
- depcharge-mac
only:
- develop
- master
- tags
build-win:
image: golang:1-alpine
stage: build
dependencies:
- init
variables:
CGO_ENABLED: 0
GOOS: "windows"
GOARCH: "amd64"
script:
- export VERSION=$(cat VERSION.txt)
- go build -a -ldflags="-w -s -X main.version=$VERSION" .
artifacts:
expire_in: 1 week
paths:
- depcharge.exe
only:
- develop
- master
- tags
#build-docker:
# image: docker:latest
# stage: build
# services:
# - docker:dind
# script:
# - export IMAGE_NAME=$(if [ -z $CI_COMMIT_TAG ]; then echo "latest" ; else echo $CI_COMMIT_TAG; fi)
# - export VERSION=$(cat VERSION.txt)
#
# - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
# - docker build --build-arg VERSION=$VERSION -t $CI_REGISTRY_IMAGE:$IMAGE_NAME .
#
# # Ensure the container can run properly
# - docker run $CI_REGISTRY_IMAGE:$IMAGE_NAME
#
# - docker push $CI_REGISTRY_IMAGE:$IMAGE_NAME
# only:
# - develop
# - master
# - tags
release:
image: registry.gitlab.com/centerorbit/release-github
stage: release
cache: {}
dependencies:
- build-linux
- build-mac
- build-win
variables:
OWNER: "centerorbit"
REPO: "depcharge"
ACCESS_TOKEN: $GITHUB_ACCESS_TOKEN
script:
# Pushing latest commits, then tags in pipeline, because mirroring isn't fast enough.
- git checkout master
- git push https://centerorbit:$GITHUB_ACCESS_TOKEN@github.com/centerorbit/depcharge.git
- git push --tags https://centerorbit:$GITHUB_ACCESS_TOKEN@github.com/centerorbit/depcharge.git
# If it's a tag, then it's not a prerelease
- if [ -z $CI_COMMIT_TAG ]; then export PRE_RELEASE="true" ; else unset PRE_RELEASE ; fi
# Lets make the initial release on GitHub
- export TAG=$(if [ -z $CI_COMMIT_TAG ]; then echo $CI_COMMIT_SHA | cut -c1-7 ; else echo $CI_COMMIT_TAG; fi)
- export UPLOAD_URL=$(php /var/code/createRelease.php)
# Send Linux binary to GitHub
- export RELEASE_NAME="depcharge-linux-x64"
- mv depcharge-linux depcharge
- zip -m $RELEASE_NAME.zip depcharge
- php /var/code/uploadBinary.php
# Send Mac binary to GitHub
- export RELEASE_NAME="depcharge-mac-x64"
- mv depcharge-mac depcharge
- zip -m $RELEASE_NAME.zip depcharge
- php /var/code/uploadBinary.php
# Send Win binary to GitHub
- export RELEASE_NAME="depcharge-win-x64"
- zip -m $RELEASE_NAME.zip depcharge.exe
- php /var/code/uploadBinary.php
only:
- develop
- master
- tags
pages:
image: alpine:latest
stage: release
dependencies:
- test
script:
- mkdir public
- mv coverage.html public/index.html
artifacts:
paths:
- public
only:
- develop