-
Notifications
You must be signed in to change notification settings - Fork 38
/
.gitlab-ci.yml
283 lines (268 loc) · 9.93 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
include:
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-golang-lint.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-golang-unittests.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-commits.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-license.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-github-status-updates.yml'
image: golang:1.20
variables:
GITHUB_RELEASE_BINARY: mender-cli
S3_BUCKET_NAME: "mender"
S3_BUCKET_PATH: "mender-cli"
BUILD_DIR: build
LICENSE_HEADERS_IGNORE_FILES_REGEXP: ".*autocomplete.*"
# release and changelog generators
GITHUB_REPO_URL:
description: "The Github Repo URL for release-please, in the format of 'owner/repo'"
value: "mendersoftware/mender-cli"
GITHUB_USER_NAME:
description: "The Github username for release-please"
value: "mender-test-bot"
GITHUB_USER_EMAIL:
description: "The Github user email for release-please"
value: "[email protected]"
GIT_CLIFF:
description: "Run git cliff to override the release-please changelog"
value: "true"
options:
- "true"
- "false"
GITHUB_CHANGELOG_REPO_URL:
description: "The Github Repo URL where to push the changelog"
value: "mendersoftware/mender-docs-changelog"
CHANGELOG_REMOTE_FILE:
description: "The changelog file in the remote changelog repo"
value: "31.mender-cli/docs.md"
stages:
- build
- test
- test_acceptance_build
- test_acceptance
- publish
- changelog
compile:
stage: build
needs: []
before_script:
# Prepare GOPATH
- mkdir -p /go/src/github.com/mendersoftware
- cp -r ${CI_PROJECT_DIR} /go/src/github.com/mendersoftware/${CI_PROJECT_NAME}
- cd /go/src/github.com/mendersoftware/${CI_PROJECT_NAME}
- make get-build-deps
script:
- make build-multiplatform
- cp mender-cli.linux.amd64 $CI_PROJECT_DIR/
- cp mender-cli.darwin.amd64 $CI_PROJECT_DIR/
artifacts:
paths:
- mender-cli.linux.amd64
- mender-cli.darwin.amd64
test:smoketests:mac:
stage: test
dependencies:
- compile
before_script: []
script:
- ./mender-cli.darwin.amd64
tags:
- mender-mac-slave
test:smoketests:linux:
image: debian:buster
stage: test
dependencies:
- compile
before_script: []
script:
- ./mender-cli.linux.amd64
test_acceptance_build:tools:
stage: test_acceptance_build
dependencies:
- compile
script:
# make target env var
- export PROJECT_DIR="$CI_PROJECT_DIR/"
- cp mender-cli.linux.amd64 $CI_PROJECT_DIR/mender-cli
- make build-acceptance-tools
- make build-coverage
artifacts:
untracked: true
paths:
- mender-cli
- mender-artifact
- mender-cli-test
test_acceptance_build:image:
stage: test_acceptance_build
image: docker
services:
- docker:20.10.21-dind
needs: []
script:
- apk add --no-cache make
- export PROJECT_DIR="$CI_PROJECT_DIR/"
- make build-acceptance-image
- docker save testing > $CI_PROJECT_DIR/acceptance_testing_image.tar
artifacts:
expire_in: 2w
paths:
- acceptance_testing_image.tar
test_acceptance:run:
stage: test_acceptance
image: tiangolo/docker-with-compose
dependencies:
- test_acceptance_build:tools
- test_acceptance_build:image
services:
- docker:20.10.21-dind
script:
- apk add --no-cache git bash make
- docker load -i acceptance_testing_image.tar
# make target env var
- export SHARED_PATH="$(dirname ${CI_PROJECT_DIR})/shared"
- make run-acceptance
- tar -cvf $CI_PROJECT_DIR/acceptance-coverage.tar -C ${SHARED_PATH} cover
tags:
# needs a one-off runner without preexisting /builds/Northern.tech/Mender/shared/integration folder
- mender-qa-worker-generic-light
artifacts:
expire_in: 2w
paths:
- acceptance-coverage.tar
publish:acceptance:
stage: publish
image: golang:1.20-alpine3.17
dependencies:
- test_acceptance:run
before_script:
- apk add --no-cache git
- go install github.com/mattn/goveralls@latest
# Coveralls env variables:
# According to https://docs.coveralls.io/supported-ci-services
# we should set CI_NAME, CI_BUILD_NUMBER, etc. But according
# to goveralls source code (https://github.com/mattn/goveralls)
# many of these are not supported. Set CI_BRANCH, CI_PR_NUMBER,
# and pass few others as command line arguments.
# See also https://docs.coveralls.io/api-reference
- export CI_BRANCH=${CI_COMMIT_BRANCH}
- export CI_PR_NUMBER=${CI_COMMIT_BRANCH#pr_}
script:
- tar -xvf acceptance-coverage.tar
- goveralls
-repotoken ${COVERALLS_TOKEN}
-service gitlab-ci
-jobid $CI_PIPELINE_ID
-covermode set
-flagname acceptance
-parallel
-coverprofile $(find cover -type f | tr '\n' ',' | sed 's/,$//')
publish:s3:
stage: publish
image: debian:buster
dependencies:
- compile
before_script:
- apt update && apt install -yyq awscli
script:
- echo "Publishing ${CI_COMMIT_REF_NAME} version for linux to S3"
- aws s3 cp $GITHUB_RELEASE_BINARY.linux.amd64
s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/${CI_COMMIT_REF_NAME}/linux/mender-cli
- aws s3api put-object-acl --acl public-read --bucket $S3_BUCKET_NAME
--key $S3_BUCKET_PATH/${CI_COMMIT_REF_NAME}/linux/mender-cli
- echo "Publishing ${CI_COMMIT_REF_NAME} version for darwin to S3"
- aws s3 cp $GITHUB_RELEASE_BINARY.darwin.amd64
s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/${CI_COMMIT_REF_NAME}/darwin/mender-cli
- aws s3api put-object-acl --acl public-read --bucket $S3_BUCKET_NAME
--key $S3_BUCKET_PATH/${CI_COMMIT_REF_NAME}/darwin/mender-cli
only:
- /^(master|[0-9]+\.[0-9]+\.x)$/
changelog:
stage: changelog
image: "registry.gitlab.com/northern.tech/mender/mender-test-containers:release-please-v1-master"
variables:
GIT_DEPTH: 0 # Always get the full history
GIT_STRATEGY: clone
GIT_CLIFF__BUMP__INITIAL_TAG: "1.13.0" # TODO: after the new tag is created,
# remove this variable
tags:
- hetzner-amd-beefy
rules:
# Only run for protected branches (main and maintenance branches)
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/'
when: never
- if: $CI_COMMIT_REF_PROTECTED == "true" && $CI_COMMIT_BRANCH != ""
before_script:
# Setting up git
- git config --global user.email "${GITHUB_USER_EMAIL}"
- git config --global user.name "${GITHUB_USER_NAME}"
# GITHUB_TOKEN for Github cli authentication
- export GITHUB_TOKEN=${GITHUB_CLI_TOKEN}
script:
- release-please release-pr
--token=${GITHUB_BOT_TOKEN_REPO_FULL}
--repo-url=${GITHUB_REPO_URL}
--target-branch=${CI_COMMIT_REF_NAME} || echo "INFO - release already exists" # workaround because we shifted to prerelease versioning strategy and there's already a PR open
# git cliff: override the changelog
- test $GIT_CLIFF == "false" && echo "INFO - Skipping git-cliff" && exit 0
- git remote add github-${CI_JOB_ID} https://${GITHUB_USER_NAME}:${GITHUB_BOT_TOKEN_REPO_FULL}@github.com/${GITHUB_REPO_URL} || true # Ignore already existing remote
- gh repo set-default https://${GITHUB_USER_NAME}:${GITHUB_BOT_TOKEN_REPO_FULL}@github.com/${GITHUB_REPO_URL}
- RELEASE_PLEASE_PR=$(gh pr list --author "${GITHUB_USER_NAME}" --head "release-please--branches--${CI_COMMIT_REF_NAME}" --json number | jq -r '.[0].number // empty')
- test -z "$RELEASE_PLEASE_PR" && echo "No release-please PR found" && exit 0
- gh pr checkout --force $RELEASE_PLEASE_PR
- wget --output-document cliff.toml https://raw.githubusercontent.com/mendersoftware/mendertesting/master/utils/cliff.toml
- git cliff --bump --output CHANGELOG.md --github-repo ${GITHUB_REPO_URL} --use-branch-tags
- git add CHANGELOG.md
- git commit --amend -s --no-edit
- git push github-${CI_JOB_ID} --force
# Update the PR body
- git cliff --unreleased --bump -o tmp_pr_body.md --github-repo ${GITHUB_REPO_URL} --use-branch-tags
- gh pr edit $RELEASE_PLEASE_PR --body-file tmp_pr_body.md
- rm tmp_pr_body.md
after_script:
- git remote remove github-${CI_JOB_ID}
release:github:
stage: .post
image: "registry.gitlab.com/northern.tech/mender/mender-test-containers:release-please-v1-master"
rules:
# Only make available for protected branches (main and maintenance branches)
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/'
when: never
- if: $CI_COMMIT_REF_PROTECTED == "true" && $CI_COMMIT_BRANCH != ""
when: manual
allow_failure: true
needs:
- job: changelog
script:
- release-please github-release
--token=${GITHUB_BOT_TOKEN_REPO_FULL}
--repo-url=${GITHUB_REPO_URL}
--target-branch=${CI_COMMIT_REF_NAME}
release:mender-docs-changelog:
image: "registry.gitlab.com/northern.tech/mender/mender-test-containers:release-please-v1-master"
stage: .post
tags:
- hetzner-amd-beefy
rules:
# Only make available for stable branches
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/'
allow_failure: true
before_script:
# Setting up git
- git config --global user.email "${GITHUB_USER_EMAIL}"
- git config --global user.name "${GITHUB_USER_NAME}"
# GITHUB_TOKEN for Github cli authentication
- export GITHUB_TOKEN=${GITHUB_CLI_TOKEN}
script:
- git clone https://${GITHUB_USER_NAME}:${GITHUB_BOT_TOKEN_REPO_FULL}@github.com/${GITHUB_CHANGELOG_REPO_URL}
- cd ${GITHUB_CHANGELOG_REPO_URL#*/}
- git checkout -b changelog-${CI_JOB_ID}
- cat ../docs_header.md > ${CHANGELOG_REMOTE_FILE}
- cat ../CHANGELOG.md | grep -v -E '^---' >> ${CHANGELOG_REMOTE_FILE}
- git add ${CHANGELOG_REMOTE_FILE}
- |
git commit -s -m "chore: add mender-cli changelog"
- git push origin changelog-${CI_JOB_ID}
- gh pr create --title "Update CHANGELOG.md" --body "Automated change to the CHANGELOG.md file" --base master --head changelog-${CI_JOB_ID}