-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
142 lines (134 loc) · 4.12 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
image: golang:1.16
variables:
GOCACHE: "/go/.build_cache"
include:
- template: SAST.gitlab-ci.yml
- template: Dependency-Scanning.gitlab-ci.yml
- template: License-Scanning.gitlab-ci.yml
stages:
- build
- test
- deploy
# this job creates all relevant files which are needed in the 'build' AND
# 'release' job/ stage.
go_prepare:
stage: .pre
script:
- export PATH=$PATH:$GOPATH/bin
# get new Version from `git-semver`
- go install -v github.com/mdomke/git-semver@master
- git-semver -prefix v > `pwd`/.version
# get build/ target environment
- export VERSION=$(cat `pwd`/.version)
- $(pwd)/.ci/scripts/setEnvironment.sh
- export BUILD_ENVIRONMENT=$(cat `pwd`/ENVIRONMENT)
- make build-dev
artifacts:
expire_in: 1 hour
paths:
- .version
- ENVIRONMENT
build:
stage: build
script:
# install goreleaser
- curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
# get build/ target environment and build date
- export VERSION=$(cat `pwd`/.version)
- export BUILD_ENVIRONMENT=$(cat `pwd`/ENVIRONMENT)
- export BUILD_DATE=$(date --utc +%Y-%m-%dT%H:%M:%S%Z)
- >-
echo "++ Build Date: \"${BUILD_DATE}\""
# execute goreleaser but without pushing, signing or validating – so we can
# use the artifacts ie. in Sentry
- ./bin/goreleaser release --skip-validate --skip-publish --skip-sign --config="`pwd`/.ci/.goreleaser.develop.yml"
# delete all archives from dist/
- rm -rf `pwd`/dist/*.tar.gz
cache:
paths:
- ${GOCACHE}
- /go/pkg/mod
except:
# there is a "release" job which runs only when we are creating a new release
- tags
artifacts:
expire_in: 1 hour
paths:
- dist/
- .version
- ENVIRONMENT
release:
stage: build
variables:
# Disable shallow cloning so that goreleaser can diff between tags to
# generate a changelog.
#
# TODO: Use custom CHANGELOG.md (stripped from previous releases)
GIT_DEPTH: 0
script:
# install goreleaser
- curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
# get build/ target environment and build date
- export VERSION=$(cat `pwd`/.version)
- export BUILD_ENVIRONMENT=$(cat `pwd`/ENVIRONMENT)
- export BUILD_DATE=$(date --utc +%Y-%m-%dT%H:%M:%S%Z)
- >-
echo "++ Build Date: \"${BUILD_DATE}\""
# execute goreleaser but without pushing, signing or validating – so we can
# use the artifacts ie. in Sentry
- ./bin/goreleaser release --skip-validate --config="`pwd`/.ci/.goreleaser.release.yml"
# delete all archives from dist/
- rm -rf `pwd`/dist/*.tar.gz
cache:
paths:
- ${GOCACHE}
- /go/pkg/mod
only:
- tags
artifacts:
expire_in: 1 hour
paths:
- dist/
- .version
- ENVIRONMENT
sentry_deploy:
stage: deploy
image: getsentry/sentry-cli
only:
# run only on release build OR on develop branch (testing "deployments")
- tags
- develop
script:
- export VERSION="${PRJ}@$(cat `pwd`/.version)"
- export BUILD_ENVIRONMENT=$(cat `pwd`/ENVIRONMENT)
# create new release in sentry
- sentry-cli releases new -p ${SENTRY_PRJ} ${VERSION}
# add commits
- sentry-cli releases set-commits --commit "${SENTRY_GIT_REPO_NAME}" ${VERSION}
# upload artifacts
- export BINARIES=$(ls -d dist/*/* | grep -v prime)
- ls -d dist/*/* | grep -v prime
- sentry-cli upload-dif -p ${SENTRY_PRJ} --wait ${BINARIES}
# finalize sentry release
- sentry-cli releases finalize ${VERSION}
# mark release as deployed if environment is production or "staging"
- >-
if [ "$BUILD_ENVIRONMENT" == "production" ] || [ "$BUILD_ENVIRONMENT" == "staging" ]; then
sentry-cli releases deploys ${VERSION} new -e ${BUILD_ENVIRONMENT}
fi
# upload new Version to GitLab Pages site
pages:
stage: deploy
script:
# install go-selfupdate
- go get -u github.com/sanbornm/go-selfupdate/...
# generate content for 'public'
# TODO: filter all other 'goreleaser' files out
- ./.ci/getReleases.sh $(cat `pwd`/.version)
# move 'index.html' to public/
# TODO: create nice index.html
artifacts:
paths:
- public
only:
- tags