-
Notifications
You must be signed in to change notification settings - Fork 14
/
Taskfile.yml
299 lines (263 loc) · 9.85 KB
/
Taskfile.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# Install `task` from https://taskfile.dev
# Run `task --list` to start.
version: "3"
vars:
DATE: '{{ now | date "2006-01-02" }}'
REPO: github.com/Pix4D/cogito
COMMIT:
sh: git log -n 1 --format=%h
BRANCH:
sh: git branch --show-current
DOCKER_ORG: '{{default "pix4d" .DOCKER_ORG}}'
DOCKER_IMAGE: cogito
DOCKER_TAG:
sh: ci/git-branch-or-tag.sh
IS_RELEASE:
sh: ci/git-is-release.sh
DOCKER_BASE_NAME: "{{.DOCKER_ORG}}/{{.DOCKER_IMAGE}}"
DOCKER_FULL_NAME: "{{.DOCKER_BASE_NAME}}:{{.DOCKER_TAG}}"
BUILD_INFO: "Tag: {{.DOCKER_TAG}}, commit: {{.COMMIT}}, build date: {{.DATE}}"
LDFLAGS: -w -X '{{.REPO}}/cogito.buildinfo={{.BUILD_INFO}}'
#
SMOKE_INPUT: >
{
"source": {"owner": "foo", "repo": "bar", "access_token": "123", "log_level": "debug"},
"version": {"ref": "pizza"}
}
#
GOLANGCI_VERSION: v1.54.2
GOTESTSUM_VERSION: v1.10.1
tasks:
install:deps:
desc: Install tool dependencies.
cmds:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@{{.GOLANGCI_VERSION}}
- go install gotest.tools/gotestsum@{{.GOTESTSUM_VERSION}}
lint:
desc: Lint the code.
cmds:
- golangci-lint run ./...
test:env:
desc: "Run what is passed on the command-line with a shell environment containing the secrets needed for the integration tests. Example: task test:env -- go test -count=1 -run 'TestFooIntegration' ./pkg/update"
cmds:
- '{{ .CLI_ARGS }}'
env: &test-env
COGITO_TEST_COMMIT_SHA: '{{default "751affd155db7a00d936ee6e9f483deee69c5922" .COGITO_TEST_COMMIT_SHA}}'
COGITO_TEST_OAUTH_TOKEN:
sh: 'echo {{default "$(gopass show cogito/test_oauth_token)" .COGITO_TEST_OAUTH_TOKEN}}'
COGITO_TEST_REPO_NAME: '{{default "cogito-test-read-write" .COGITO_TEST_REPO_NAME}}'
COGITO_TEST_REPO_OWNER: '{{default "pix4d" .COGITO_TEST_REPO_OWNER}}'
COGITO_TEST_GCHAT_HOOK:
sh: 'echo {{default "$(gopass show cogito/test_gchat_webhook)" .COGITO_TEST_GCHAT_HOOK}}'
test:unit:
desc: Run the unit tests.
cmds:
# One day I will understand how to use -coverpkg=./... :-(
- gotestsum -- -short -coverprofile=coverage.out ./...
test:all:
desc: Run all the tests (unit + integration). Use this target to get total coverage.
cmds:
- gotestsum -- -coverprofile=coverage.out ./...
env: *test-env
test:smoke:
desc: Simple smoke test of the local executables.
cmds:
- task: build
- task: build:templatedir
- task: test:buildinfo
- task: test:buildinfo
- task: test:smoke:check
- task: test:smoke:get
#- task: test:smoke:put
test:smoke:check:
cmds:
- echo '{{.SMOKE_INPUT}}' | ./bin/check
test:smoke:get:
cmds:
- echo '{{.SMOKE_INPUT}}' | ./bin/in dummy-dir
test:smoke:put:
cmds:
- rm -rf /tmp/cogito-test
- mkdir -p /tmp/cogito-test
- >
./bin/templatedir cogito/testdata/one-repo/a-repo /tmp/cogito-test --dot
--template repo_url=https://github.com/foo/bar head=dummyHead
branch_name=dummyBranch commit_sha=dummySha
- echo '{{.PUT_INPUT}}' | ./bin/out /tmp/cogito-test
vars:
PUT_INPUT: >
{
"source": {"owner": "foo", "repo": "bar", "access_token": "123", "log_level": "debug"},
"params": {"state": "success"}
}
test:buildinfo:
desc: Verify that the executable contains build information
# cogito: This is the Cogito GitHub status resource. unknown
# cogito: This is the Cogito GitHub status resource. Tag: buildinfo, commit: e9b36d0814, build date: 2022-07-26
cmds:
# "unknown" is the default value, printed when built without linker flags.
- 'echo {{.OUTPUT}} | grep -v unknown'
- 'echo {{.OUTPUT}} | grep Tag:'
- 'echo {{.OUTPUT}} | grep commit:'
vars:
INPUT: '{"source": {"owner": "foo", "repo": "bar", "access_token": "123"}}'
OUTPUT:
# We only want to capture stderr, because the Cogito resource protocol uses
# stderr for logging.
sh: echo '{{.INPUT}}' | ./bin/check 2>&1 1>/dev/null
fly-login:
desc: Performs a fly login in the target to be used in the acceptance tests.
cmds:
- fly -t cogito login -c $(gopass show cogito/concourse_url) --open-browser
test:acceptance:set-pipeline:
desc: Set the acceptance test pipeline
cmds:
- >
fly -t cogito set-pipeline --non-interactive -p {{.PIPELINE}}
-c pipelines/cogito-acceptance.yml
-y target-branch=stable
-y cogito-branch={{.BRANCH}}
-y github-owner=$(gopass show cogito/test_repo_owner)
-y repo-name=$(gopass show cogito/test_repo_name)
-y oauth-personal-access-token=$(gopass show cogito/test_oauth_token)
-y cogito-tag={{.BRANCH}}
-y gchat_webhook=$(gopass show cogito/test_gchat_webhook)
- fly -t cogito unpause-pipeline -p {{.PIPELINE}}
vars:
PIPELINE: cogito-acceptance---{{.BRANCH}}
trigger-job:
cmds:
- fly -t cogito trigger-job -j {{.PIPELINE}}/{{.JOB}} -w
vars:
PIPELINE: cogito-acceptance---{{.BRANCH}}
JOB: '{{.JOB}}'
test:acceptance:
desc: Run the Cogito acceptance tests. Needs a running Concourse.
cmds:
- task: test:acceptance:set-pipeline
- task: test:acceptance:chat-only-summary
- task: test:acceptance:chat-message-default
- task: test:acceptance:chat-message-no-summary
- task: test:acceptance:chat-message-file-default
- task: test:acceptance:chat-message-only-sinks-override
- task: test:acceptance:chat-message-only-simplest-possible
- task: test:acceptance:chat-message-only-file
- task: test:acceptance:default-log
test:acceptance:chat-only-summary:
desc: Run a pipeline job to test default chat
cmds:
- task: trigger-job
vars: {JOB: chat-only-summary}
test:acceptance:chat-message-default:
desc: Run a pipeline job to test chat_message
cmds:
- task: trigger-job
vars: {JOB: chat-message-default}
test:acceptance:chat-message-no-summary:
desc: Run a pipeline job to test chat_message and chat_append_summary
cmds:
- task: trigger-job
vars: {JOB: chat-message-no-summary}
test:acceptance:chat-message-file-default:
desc: Run a pipeline job to test chat_message_file
cmds:
- task: trigger-job
vars: {JOB: chat-message-file-default}
test:acceptance:chat-message-only-simplest-possible:
desc: Run a pipeline job to test chat only message
cmds:
- task: trigger-job
vars: {JOB: chat-message-only-simplest-possible}
test:acceptance:chat-message-only-sinks-override:
desc: Run a pipeline job to test chat only message
cmds:
- task: trigger-job
vars: {JOB: chat-message-only-sinks-override}
test:acceptance:chat-message-only-file:
desc: Run a pipeline job to test chat only chat_message_file
cmds:
- task: trigger-job
vars: {JOB: chat-message-only-file}
test:acceptance:default-log:
desc: Run a pipeline job to test default logging
cmds:
- task: trigger-job
vars: {JOB: default-log}
browser:
desc: "Show code coverage in browser (usage: task test:<subtarget> browser)"
cmds:
- go tool cover -html=coverage.out
build:
desc: Build on the local machine.
dir: bin
cmds:
- go build -ldflags "{{.LDFLAGS}}" ../cmd/cogito
- ln -sf cogito check
- ln -sf cogito in
- ln -sf cogito out
build:templatedir:
desc: Build templatedir (development helper, normally not needed).
dir: bin
cmds:
- go build -ldflags "{{.LDFLAGS}}" ../cmd/templatedir
clean:
desc: Delete build artifacts
cmds:
- rm -f coverage.out
- rm -r -f bin
docker:login:
cmds:
- echo $DOCKER_TOKEN | docker login -u $DOCKER_USERNAME --password-stdin
env:
DOCKER_USERNAME:
sh: 'echo {{default "$(gopass show cogito/docker_username)" .DOCKER_USERNAME}}'
DOCKER_TOKEN:
sh: 'echo {{default "$(gopass show cogito/docker_token)" .DOCKER_TOKEN}}'
docker:build:
desc: Build the Docker image.
cmds:
- docker build --build-arg BUILD_INFO --tag {{.DOCKER_FULL_NAME}} .
- docker images {{.DOCKER_FULL_NAME}}
env:
BUILD_INFO: "{{.BUILD_INFO}}"
docker:smoke:
desc: Simple smoke test of the Docker image.
cmds:
- echo '{{.SMOKE_INPUT}}' | docker run --rm --interactive {{.DOCKER_FULL_NAME}} /opt/resource/check
- echo
- echo '{{.SMOKE_INPUT}}' | docker run --rm --interactive {{.DOCKER_FULL_NAME}} /opt/resource/in dummy-dir
- echo
docker:push:
desc: Push the Docker image.
cmds:
- docker push {{.DOCKER_FULL_NAME}}
- docker images {{.DOCKER_FULL_NAME}}
preconditions:
- sh: test -z "$IS_RELEASE" || test -n "$CI"
msg: Release tag detected ({{.DOCKER_TAG}}); releases are made only on CI.
docker:maybe-push-release:
desc: If a release tag has been detected, Docker push with the 'latest' tag.
cmds:
- docker tag {{.DOCKER_FULL_NAME}} {{.DOCKER_BASE_NAME}}:latest
- docker push {{.DOCKER_BASE_NAME}}:latest
preconditions:
- sh: test -n "$CI"
msg: This target must run only on CI, not locally.
status:
- test -z "{{.IS_RELEASE}}"
ci:setup:
desc: Useful only when running under CI.
cmds:
- task: install:deps
# Running "go mod download" is optional, since "go build" would do it anyway.
# We run it explicitly to make the output of "go build" more focused.
- cmd: go mod download -x
# When using GitHub Actions, add this snippet at the end of the workflow:
# - run: docker logout
# # Always remove credentials, also if any previous step failed.
# if: always()
ci:teardown:
desc: ALWAYS run this when in CI (reduces security exposures)
cmds:
# Remove credentials from the file system, added by "docker login" :-(
- cmd: docker logout