-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
41 lines (35 loc) · 1.4 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
stages:
- test
- release
test:linux:
stage: test
image: golang:latest
variables:
GIT_URL: github.com
GOPATH: /go
PROJECT_DIR: $GOPATH/src/$GIT_URL/$CI_PROJECT_NAMESPACE
coverage: '/coverage: \d+\.\d+%/'
script:
- mkdir -p $PROJECT_DIR
- cp -r $CI_PROJECT_DIR $PROJECT_DIR/$CI_PROJECT_NAME
- cd $PROJECT_DIR/$CI_PROJECT_NAME
- go generate ./...
- go test -cover ./...
release:docker:
stage: release
image: docker:git
services:
- docker:dind
dependencies:
- test:linux
script:
- git describe --tags && LATEST_TAG=`git describe --tags --abbrev=0 | sed 's/[^0-9.]*//g'` || LATEST_TAG="1.0.0"
- OLD_IFS=$IFS; IFS=".-"; set -- $LATEST_TAG; IFS=$OLD_IFS; TAG_MAJOR=$1; TAG_MINOR=$2; TAG_MICRO=$3
- function join_by { local IFS="$1"; shift; echo "$*"; }
- LATEST_IMAGE="$CI_REGISTRY_IMAGE:latest"
- images="$CI_REGISTRY_IMAGE:$LATEST_TAG $CI_REGISTRY_IMAGE:$(join_by . $TAG_MAJOR $TAG_MINOR $TAG_MICRO) $CI_REGISTRY_IMAGE:$(join_by . $TAG_MAJOR $TAG_MINOR) $CI_REGISTRY_IMAGE:$TAG_MAJOR"
- unique_images=$(echo "$images" | tr ' ' '\n' | sort -u | tr '\n' ' ')
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build --pull -t $LATEST_IMAGE --build-arg PROJECT_NAME=$CI_PROJECT_NAME .
- docker push $LATEST_IMAGE
- for image in $unique_images; do docker tag "$LATEST_IMAGE" "$image"; docker push "$image"; done