-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
108 lines (100 loc) · 4.28 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
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
- test
- build
- public
- release
variables:
BINARY_NAME: troll
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/troll/${PACKAGE_VERSION}"
Run tests:
image: golang:latest
stage: test
script:
- go fmt $(go list ./...)
- go vet $(go list ./...)
- go test -race $(go list ./...)
- go test . -coverprofile=coverage.txt -covermode count
- go get github.com/boumenot/gocover-cobertura
- go run github.com/boumenot/gocover-cobertura < coverage.txt > coverage.xml
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
Build:
stage: build
image: golang:latest
script:
- mkdir $CI_PROJECT_DIR/build/
- GOOS=linux GOARCH=amd64 go build -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/build/${BINARY_NAME}-linux-amd64
- GOOS=linux GOARCH=arm64 go build -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/build/${BINARY_NAME}-linux-arm64
- GOOS=darwin GOARCH=amd64 go build -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/build/${BINARY_NAME}-darwin-amd64
- GOOS=darwin GOARCH=arm64 go build -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/build/${BINARY_NAME}-darwin-arm64
artifacts:
paths:
- build
Public:
stage: public
script:
- export VERSION=$(grep VERSION version.go | cut -d\" -f2)
- ls $CI_PROJECT_DIR/build
- |
for arch in linux-amd64 linux-arm64 darwin-amd64 darwin-arm64; do
echo "Uploading file $CI_PROJECT_DIR/build/${BINARY_NAME}-${arch}"
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file $CI_PROJECT_DIR/build/${BINARY_NAME}-${arch} "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${BINARY_NAME}/${VERSION}-${arch}/${BINARY_NAME}"
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file $CI_PROJECT_DIR/build/${BINARY_NAME}-${arch} "${PACKAGE_REGISTRY_URL}/${BINARY_NAME}-linux-amd64"
done
Release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: "$CI_COMMIT_TAG"
script:
- |
release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"${DARWIN_AMD64_BINARY}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${DARWIN_AMD64_BINARY}\"}" \
--assets-link "{\"name\":\"${LINUX_AMD64_BINARY}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${LINUX_AMD64_BINARY}\"}"
Release latest:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
script:
- export VERSION=$(grep VERSION variables.go | cut -d\" -f2)
- |
release-cli create --name "Release LATEST from master branch" --tag-name ${VERSION} \
--assets-link "{\"name\":\"${BINARY_NAME}-darwin-arm64\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${BINARY_NAME}/${VERSION}-darwin-arm64/${BINARY_NAME}\"}" \
--assets-link "{\"name\":\"${BINARY_NAME}-linux-amd64\",\"url\":\"${PACKAGE_REGISTRY_URL}/${BINARY_NAME}-linux-amd64\"}"
Release OLD:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: "$CI_COMMIT_TAG"
script:
- echo "running release_job"
release:
name: Release $CI_COMMIT_TAG
description: Created using the release-cli $EXTRA_DESCRIPTION
tag_name: "$CI_COMMIT_TAG"
ref: "$CI_COMMIT_TAG"
milestones:
- m1
- m2
- m3
assets:
links:
- name: asset1
url: https://example.com/assets/1
- name: asset2
url: https://example.com/assets/2
filepath: "/pretty/url/1"
link_type: other
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml