• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / integration-test-runner / 1094225606

04 Dec 2023 10:07AM UTC coverage: 72.208% (-3.5%) from 75.712%
1094225606

Pull #289

gitlab-ci

lluiscampos
chore: Group dependabot updates for golang

Signed-off-by: Lluis Campos <lluis.campos@northern.tech>
Pull Request #289: chore: Group dependabot updates for golang

1099 of 1522 relevant lines covered (72.21%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.5
/menderqa_pipeline.go
1
package main
2

3
import (
4
        "bytes"
5
        "context"
6
        "reflect"
7
        "sort"
8
        "strconv"
9
        "strings"
10
        "text/template"
11

12
        "github.com/google/go-github/v28/github"
13
        "github.com/sirupsen/logrus"
14
        "github.com/xanzy/go-gitlab"
15

16
        clientgitlab "github.com/mendersoftware/integration-test-runner/client/gitlab"
17
)
18

19
const LatestStableYoctoBranch = "kirkstone"
20

21
func say(
22
        ctx context.Context,
23
        tmplString string,
24
        data interface{},
25
        log *logrus.Entry,
26
        conf *config,
27
        pr *github.PullRequestEvent,
28
) error {
1✔
29
        tmpl, err := template.New("Main").Parse(tmplString)
1✔
30
        if err != nil {
1✔
31
                log.Errorf(
×
32
                        "Failed to parse the build matrix template. Should never happen! Error: %s\n",
×
33
                        err.Error(),
×
34
                )
×
35
        }
×
36
        var buf bytes.Buffer
1✔
37
        if err = tmpl.Execute(&buf, data); err != nil {
1✔
38
                log.Errorf("Failed to execute the build matrix template. Error: %s\n", err.Error())
×
39
        }
×
40

41
        // Comment with a pipeline-link on the PR
42
        commentBody := buf.String()
1✔
43
        comment := github.IssueComment{
1✔
44
                Body: &commentBody,
1✔
45
        }
1✔
46

1✔
47
        err = githubClient.CreateComment(ctx,
1✔
48
                conf.githubOrganization, pr.GetRepo().GetName(), pr.GetNumber(), &comment)
1✔
49
        if err != nil {
1✔
50
                log.Infof("Failed to comment on the pr: %v, Error: %s", pr, err.Error())
×
51
        }
×
52

53
        return err
1✔
54
}
55

56
func parsePullRequest(
57
        log *logrus.Entry,
58
        conf *config,
59
        action string,
60
        pr *github.PullRequestEvent,
61
) []buildOptions {
4✔
62
        log.Info("Pull request event with action: ", action)
4✔
63
        var builds []buildOptions
4✔
64

4✔
65
        // github pull request events to trigger a CI job for
4✔
66
        if action == "opened" || action == "edited" || action == "reopened" ||
4✔
67
                action == "synchronize" || action == "ready_for_review" {
7✔
68

3✔
69
                return getBuilds(log, conf, pr)
3✔
70
        }
3✔
71

72
        return builds
2✔
73
}
74

75
func getBuilds(log *logrus.Entry, conf *config, pr *github.PullRequestEvent) []buildOptions {
3✔
76

3✔
77
        var builds []buildOptions
3✔
78

3✔
79
        repo := pr.GetRepo().GetName()
3✔
80

3✔
81
        commitSHA := pr.PullRequest.Head.GetSHA()
3✔
82
        //GetLabel returns "mendersoftware:master", we just want the branch
3✔
83
        baseBranch := strings.Split(pr.PullRequest.Base.GetLabel(), ":")[1]
3✔
84

3✔
85
        makeQEMU := false
3✔
86

3✔
87
        // we need to have the latest integration/master branch in order to use the release_tool.py
3✔
88
        if err := updateIntegrationRepo(conf); err != nil {
3✔
89
                log.Warnf(err.Error())
×
90
        }
×
91

92
        watchRepositoriesTriggerPipeline, err := getListOfWatchedRepositories(conf)
3✔
93
        if err != nil {
5✔
94
                log.Warnf(err.Error())
2✔
95
        }
2✔
96

97
        for _, watchRepo := range watchRepositoriesTriggerPipeline {
4✔
98
                // make sure the repo that the pull request is performed against is
1✔
99
                // one that we are watching.
1✔
100

1✔
101
                if watchRepo == repo {
2✔
102

1✔
103
                        // check if we need to build/test yocto
1✔
104
                        for _, qemuRepo := range qemuBuildRepositories {
2✔
105
                                if repo == qemuRepo {
2✔
106
                                        makeQEMU = true
1✔
107
                                }
1✔
108
                        }
109

110
                        switch repo {
1✔
111
                        case "meta-mender", "integration":
×
112
                                build := buildOptions{
×
113
                                        pr:         strconv.Itoa(pr.GetNumber()),
×
114
                                        repo:       repo,
×
115
                                        baseBranch: baseBranch,
×
116
                                        commitSHA:  commitSHA,
×
117
                                        makeQEMU:   makeQEMU,
×
118
                                }
×
119
                                builds = append(builds, build)
×
120

121
                        default:
1✔
122
                                var err error
1✔
123
                                var integrationsToTest []string
1✔
124

1✔
125
                                if integrationsToTest, err = getIntegrationVersionsUsingMicroservice(
1✔
126
                                        log,
1✔
127
                                        repo,
1✔
128
                                        baseBranch,
1✔
129
                                        conf,
1✔
130
                                ); err != nil {
1✔
131
                                        log.Errorf(
×
132
                                                "failed to get related microservices for repo: %s version: %s, failed "+
×
133
                                                        "with: %s\n",
×
134
                                                repo,
×
135
                                                baseBranch,
×
136
                                                err.Error(),
×
137
                                        )
×
138
                                        return nil
×
139
                                }
×
140
                                log.Infof(
1✔
141
                                        "the following integration branches: %s are using %s/%s",
1✔
142
                                        integrationsToTest,
1✔
143
                                        repo,
1✔
144
                                        baseBranch,
1✔
145
                                )
1✔
146

1✔
147
                                // one pull request can trigger multiple builds
1✔
148
                                for _, integrationBranch := range integrationsToTest {
2✔
149
                                        buildOpts := buildOptions{
1✔
150
                                                pr:         strconv.Itoa(pr.GetNumber()),
1✔
151
                                                repo:       repo,
1✔
152
                                                baseBranch: integrationBranch,
1✔
153
                                                commitSHA:  commitSHA,
1✔
154
                                                makeQEMU:   makeQEMU,
1✔
155
                                        }
1✔
156
                                        builds = append(builds, buildOpts)
1✔
157
                                }
1✔
158
                        }
159

160
                }
161
        }
162
        return builds
3✔
163
}
164

165
func filterOutEmptyVariables(
166
        optionsIn []*gitlab.PipelineVariableOptions,
167
) []*gitlab.PipelineVariableOptions {
1✔
168
        var optionsOut []*gitlab.PipelineVariableOptions
1✔
169
        for _, option := range optionsIn {
2✔
170
                if *option.Value != "" {
2✔
171
                        optionsOut = append(optionsOut, option)
1✔
172
                }
1✔
173
        }
174
        return optionsOut
1✔
175
}
176

177
func triggerBuild(
178
        log *logrus.Entry,
179
        conf *config,
180
        build *buildOptions,
181
        pr *github.PullRequestEvent,
182
        buildOptions *BuildOptions,
183
) error {
1✔
184
        gitlabClient, err := clientgitlab.NewGitLabClient(
1✔
185
                conf.gitlabToken,
1✔
186
                conf.gitlabBaseURL,
1✔
187
                conf.dryRunMode,
1✔
188
        )
1✔
189
        if err != nil {
1✔
190
                return err
×
191
        }
×
192

193
        buildParameters, err := getBuildParameters(log, conf, build, buildOptions)
1✔
194
        if err != nil {
1✔
195
                return err
×
196
        }
×
197

198
        // first stop old pipelines with the same buildParameters
199
        stopStalePipelines(log, gitlabClient, buildParameters)
1✔
200

1✔
201
        // trigger the new pipeline
1✔
202
        integrationPipelinePath := "Northern.tech/Mender/mender-qa"
1✔
203
        ref := "master"
1✔
204
        opt := &gitlab.CreatePipelineOptions{
1✔
205
                Ref:       &ref,
1✔
206
                Variables: &buildParameters,
1✔
207
        }
1✔
208

1✔
209
        variablesString := ""
1✔
210
        for _, variable := range *opt.Variables {
2✔
211
                variablesString += *variable.Key + ":" + *variable.Value + ", "
1✔
212
        }
1✔
213
        log.Infof(
1✔
214
                "Creating pipeline in project %s:%s with variables: %s",
1✔
215
                integrationPipelinePath,
1✔
216
                *opt.Ref,
1✔
217
                variablesString,
1✔
218
        )
1✔
219

1✔
220
        pipeline, err := gitlabClient.CreatePipeline(integrationPipelinePath, opt)
1✔
221
        if err != nil {
1✔
222
                log.Errorf("Could not create pipeline: %s", err.Error())
×
223
                return err
×
224
        }
×
225
        log.Infof("Created pipeline: %s", pipeline.WebURL)
1✔
226

1✔
227
        // Add the build variable matrix to the pipeline comment under a
1✔
228
        // drop-down tab
1✔
229
        // nolint:lll
1✔
230
        tmplString := `
1✔
231
Hello :smile_cat: I created a pipeline for you here: [Pipeline-{{.Pipeline.ID}}]({{.Pipeline.WebURL}})
1✔
232

1✔
233
<details>
1✔
234
    <summary>Build Configuration Matrix</summary><p>
1✔
235

1✔
236
| Key   | Value |
1✔
237
| ----- | ----- |
1✔
238
{{range $i, $var := .BuildVars}}{{if $var.Value}}| {{$var.Key}} | {{$var.Value}} |{{printf "\n"}}{{end}}{{end}}
1✔
239

1✔
240
 </p></details>
1✔
241
`
1✔
242
        tmpl, err := template.New("Main").Parse(tmplString)
1✔
243
        if err != nil {
1✔
244
                log.Errorf(
×
245
                        "Failed to parse the build matrix template. Should never happen! Error: %s\n",
×
246
                        err.Error(),
×
247
                )
×
248
                return err
×
249
        }
×
250
        var buf bytes.Buffer
1✔
251
        if err = tmpl.Execute(&buf, struct {
1✔
252
                BuildVars []*gitlab.PipelineVariableOptions
1✔
253
                Pipeline  *gitlab.Pipeline
1✔
254
        }{
1✔
255
                BuildVars: filterOutEmptyVariables(*opt.Variables),
1✔
256
                Pipeline:  pipeline,
1✔
257
        }); err != nil {
1✔
258
                log.Errorf("Failed to execute the build matrix template. Error: %s\n", err.Error())
×
259
                return err
×
260
        }
×
261

262
        // Comment with a pipeline-link on the PR
263
        commentBody := buf.String()
1✔
264
        comment := github.IssueComment{
1✔
265
                Body: &commentBody,
1✔
266
        }
1✔
267

1✔
268
        err = githubClient.CreateComment(context.Background(),
1✔
269
                conf.githubOrganization, pr.GetRepo().GetName(), pr.GetNumber(), &comment)
1✔
270
        if err != nil {
1✔
271
                log.Infof("Failed to comment on the pr: %v, Error: %s", pr, err.Error())
×
272
        }
×
273

274
        return err
1✔
275
}
276

277
func stopStalePipelines(
278
        log *logrus.Entry,
279
        client clientgitlab.Client,
280
        vars []*gitlab.PipelineVariableOptions,
281
) {
1✔
282
        integrationPipelinePath := "Northern.tech/Mender/mender-qa"
1✔
283

1✔
284
        sort.SliceStable(vars, func(i, j int) bool {
2✔
285
                return *vars[i].Key < *vars[j].Key
1✔
286
        })
1✔
287

288
        username := githubBotName
1✔
289
        status := gitlab.Pending
1✔
290
        opt := &gitlab.ListProjectPipelinesOptions{
1✔
291
                Username: &username,
1✔
292
                Status:   &status,
1✔
293
        }
1✔
294

1✔
295
        pipelinesPending, err := client.ListProjectPipelines(integrationPipelinePath, opt)
1✔
296
        if err != nil {
1✔
297
                log.Errorf("stopStalePipelines: Could not list pending pipelines: %s", err.Error())
×
298
        }
×
299

300
        status = gitlab.Running
1✔
301
        opt = &gitlab.ListProjectPipelinesOptions{
1✔
302
                Username: &username,
1✔
303
                Status:   &status,
1✔
304
        }
1✔
305

1✔
306
        pipelinesRunning, err := client.ListProjectPipelines(integrationPipelinePath, opt)
1✔
307
        if err != nil {
1✔
308
                log.Errorf("stopStalePipelines: Could not list running pipelines: %s", err.Error())
×
309
        }
×
310

311
        for _, pipeline := range append(pipelinesPending, pipelinesRunning...) {
2✔
312

1✔
313
                variables, err := client.GetPipelineVariables(integrationPipelinePath, pipeline.ID)
1✔
314
                if err != nil {
1✔
315
                        log.Errorf("stopStalePipelines: Could not get variables for pipeline: %s", err.Error())
×
316
                        continue
×
317
                }
318

319
                sort.SliceStable(variables, func(i, j int) bool {
1✔
320
                        return variables[i].Key < variables[j].Key
×
321
                })
×
322

323
                if reflect.DeepEqual(vars, variables) {
1✔
324
                        log.Infof("Cancelling stale pipeline %d, url: %s", pipeline.ID, pipeline.WebURL)
×
325

×
326
                        err := client.CancelPipelineBuild(integrationPipelinePath, pipeline.ID)
×
327
                        if err != nil {
×
328
                                log.Errorf("stopStalePipelines: Could not cancel pipeline: %s", err.Error())
×
329
                        }
×
330

331
                }
332

333
        }
334
}
335

336
func getBuildParameters(
337
        log *logrus.Entry,
338
        conf *config,
339
        build *buildOptions,
340
        buildOptions *BuildOptions,
341
) ([]*gitlab.PipelineVariableOptions, error) {
1✔
342
        var err error
1✔
343
        readHead := "pull/" + build.pr + "/head"
1✔
344
        var buildParameters []*gitlab.PipelineVariableOptions
1✔
345

1✔
346
        var versionedRepositories []string
1✔
347
        if build.repo == "meta-mender" {
1✔
348
                // For meta-mender, pick master versions of all Mender release repos.
×
349
                versionedRepositories, err = getListOfVersionedRepositories("origin/master", conf)
×
350
        } else {
1✔
351
                versionedRepositories, err = getListOfVersionedRepositories(
1✔
352
                        "origin/"+build.baseBranch,
1✔
353
                        conf,
1✔
354
                )
1✔
355
        }
1✔
356
        if err != nil {
1✔
357
                log.Errorf("Could not get list of repositories: %s", err.Error())
×
358
                return nil, err
×
359
        }
×
360

361
        for _, versionedRepo := range versionedRepositories {
2✔
362
                // iterate over all the repositories (except the one we are testing) and
1✔
363
                // set the correct microservice versions
1✔
364

1✔
365
                // use the default "master" for both mender-qa, and meta-mender (set in CI)
1✔
366
                if versionedRepo != build.repo &&
1✔
367
                        versionedRepo != "integration" &&
1✔
368
                        build.repo != "meta-mender" {
2✔
369

1✔
370
                        repoKey := repoToBuildParameter(versionedRepo)
1✔
371

1✔
372
                        if _, exists := buildOptions.PullRequests[versionedRepo]; exists {
2✔
373
                                prVersion := buildOptions.PullRequests[versionedRepo]
1✔
374
                                buildParameters = append(
1✔
375
                                        buildParameters,
1✔
376
                                        &gitlab.PipelineVariableOptions{
1✔
377
                                                Key:   &repoKey,
1✔
378
                                                Value: &prVersion,
1✔
379
                                        },
1✔
380
                                )
1✔
381
                                continue
1✔
382
                        }
383
                        version, err := getServiceRevisionFromIntegration(
1✔
384
                                versionedRepo,
1✔
385
                                "origin/"+build.baseBranch,
1✔
386
                                conf,
1✔
387
                        )
1✔
388
                        if err != nil {
1✔
389
                                log.Errorf("failed to determine %s version: %s", versionedRepo, err.Error())
×
390
                                return nil, err
×
391
                        }
×
392
                        log.Infof("%s version %s is being used in %s", versionedRepo, version, build.baseBranch)
1✔
393
                        buildParameters = append(
1✔
394
                                buildParameters,
1✔
395
                                &gitlab.PipelineVariableOptions{
1✔
396
                                        Key:   &repoKey,
1✔
397
                                        Value: &version,
1✔
398
                                },
1✔
399
                        )
1✔
400
                }
401
        }
402

403
        // set the correct integration branches if we aren't performing a pull request against
404
        // integration
405
        if build.repo != "integration" && build.repo != "meta-mender" {
2✔
406
                integrationRevision := build.baseBranch
1✔
407
                if _, exists := buildOptions.PullRequests["integration"]; exists {
2✔
408
                        integrationRevision = buildOptions.PullRequests["integration"]
1✔
409
                }
1✔
410
                integrationRepoKey := repoToBuildParameter("integration")
1✔
411
                buildParameters = append(buildParameters,
1✔
412
                        &gitlab.PipelineVariableOptions{
1✔
413
                                Key:   &integrationRepoKey,
1✔
414
                                Value: &integrationRevision})
1✔
415

1✔
416
                if _, exists := buildOptions.PullRequests["meta-mender"]; exists {
2✔
417
                        metaMenderRevision := buildOptions.PullRequests["meta-mender"]
1✔
418
                        metaMenderRepoKey := repoToBuildParameter("meta-mender")
1✔
419
                        buildParameters = append(buildParameters,
1✔
420
                                &gitlab.PipelineVariableOptions{
1✔
421
                                        Key:   &metaMenderRepoKey,
1✔
422
                                        Value: &metaMenderRevision})
1✔
423
                }
1✔
424
        }
425

426
        // Set poky (& friends) and meta-mender revisions:
427
        // - If building a master PR, leave everything at defaults, which generally means
428
        //   meta-mender/master and poky/LatestStableYoctoBranch.
429
        // - If building meta-mender @ non-master, set poky branches to its baseBranch.
430
        // - If building any other repo @ non-master, set both meta-mender and poky to
431
        //   LatestStableYoctoBranch.
432
        if build.baseBranch != "master" {
2✔
433
                var pokyBranch string
1✔
434
                if build.repo == "meta-mender" {
1✔
435
                        pokyBranch = build.baseBranch
×
436
                } else {
1✔
437
                        pokyBranch = LatestStableYoctoBranch
1✔
438
                        metaMenderBranch := pokyBranch
1✔
439
                        if build.baseBranch == "feature-c++-client" {
2✔
440
                                metaMenderBranch = build.baseBranch
1✔
441
                        }
1✔
442
                        metaMenderBranchKey := repoToBuildParameter("meta-mender")
1✔
443
                        buildParameters = append(
1✔
444
                                buildParameters,
1✔
445
                                &gitlab.PipelineVariableOptions{
1✔
446
                                        Key:   &metaMenderBranchKey,
1✔
447
                                        Value: &metaMenderBranch,
1✔
448
                                },
1✔
449
                        )
1✔
450
                }
451
                pokyBranchKey := repoToBuildParameter("poky")
1✔
452
                buildParameters = append(
1✔
453
                        buildParameters,
1✔
454
                        &gitlab.PipelineVariableOptions{Key: &pokyBranchKey, Value: &pokyBranch},
1✔
455
                )
1✔
456
                metaOEPokyBranchKey := repoToBuildParameter("meta-openembedded")
1✔
457
                buildParameters = append(
1✔
458
                        buildParameters,
1✔
459
                        &gitlab.PipelineVariableOptions{
1✔
460
                                Key:   &metaOEPokyBranchKey,
1✔
461
                                Value: &pokyBranch,
1✔
462
                        },
1✔
463
                )
1✔
464
                metaRPIPokyBranchKey := repoToBuildParameter("meta-raspberrypi")
1✔
465
                buildParameters = append(
1✔
466
                        buildParameters,
1✔
467
                        &gitlab.PipelineVariableOptions{
1✔
468
                                Key:   &metaRPIPokyBranchKey,
1✔
469
                                Value: &pokyBranch,
1✔
470
                        },
1✔
471
                )
1✔
472
        }
473

474
        // set the rest of the CI build parameters
475
        runIntegrationTests := "true"
1✔
476
        runBackendIntegrationTests := "true"
1✔
477
        if buildOptions.Fast {
1✔
478
                runIntegrationTests = "false"
×
479
        }
×
480

481
        if build.baseBranch == "feature-c++-client" {
2✔
482
                // Most of integration tests can be run for the C++ client \o/
1✔
483
                // To be cleaned-up after MEN-6671
1✔
484
                runIntegrationTests = "true"
1✔
485
                runBackendIntegrationTests = "false"
1✔
486
        }
1✔
487

488
        runIntegrationTestsKey := "RUN_INTEGRATION_TESTS"
1✔
489
        buildParameters = append(
1✔
490
                buildParameters,
1✔
491
                &gitlab.PipelineVariableOptions{Key: &runIntegrationTestsKey, Value: &runIntegrationTests},
1✔
492
        )
1✔
493
        runBackendIntegrationTestsKey := "RUN_BACKEND_INTEGRATION_TESTS"
1✔
494
        buildParameters = append(
1✔
495
                buildParameters,
1✔
496
                &gitlab.PipelineVariableOptions{
1✔
497
                        Key: &runBackendIntegrationTestsKey, Value: &runBackendIntegrationTests,
1✔
498
                },
1✔
499
        )
1✔
500
        buildRepoKey := repoToBuildParameter(build.repo)
1✔
501
        buildParameters = append(buildParameters,
1✔
502
                &gitlab.PipelineVariableOptions{
1✔
503
                        Key:   &buildRepoKey,
1✔
504
                        Value: &readHead,
1✔
505
                })
1✔
506

1✔
507
        return getClientBuildParameters(buildParameters, build)
1✔
508
}
509

510
func getClientBuildParameters(
511
        buildParameters []*gitlab.PipelineVariableOptions,
512
        build *buildOptions,
513
) ([]*gitlab.PipelineVariableOptions, error) {
1✔
514
        var qemuParam string
1✔
515
        if build.makeQEMU {
2✔
516
                qemuParam = "true"
1✔
517
        } else {
2✔
518
                qemuParam = ""
1✔
519
        }
1✔
520

521
        if build.baseBranch == "feature-c++-client" {
2✔
522
                // Avoid testing platforms for this branch. It is too early in
1✔
523
                // the project. For now only BUILD_CLIENT will run, ensuring
1✔
524
                // that we can at least build it. MEN-6116 exists to clean this
1✔
525
                // up later.
1✔
526
                qemuParam = "false"
1✔
527
                buildCppClient := "true"
1✔
528
                buildCppClientKey := "BUILD_CPP_CLIENT"
1✔
529
                buildParameters = append(
1✔
530
                        buildParameters,
1✔
531
                        &gitlab.PipelineVariableOptions{Key: &buildCppClientKey, Value: &buildCppClient},
1✔
532
                )
1✔
533
        }
1✔
534

535
        buildX86UefiGrubKey := "BUILD_QEMUX86_64_UEFI_GRUB"
1✔
536
        buildParameters = append(
1✔
537
                buildParameters,
1✔
538
                &gitlab.PipelineVariableOptions{Key: &buildX86UefiGrubKey, Value: &qemuParam},
1✔
539
        )
1✔
540
        testX86UefiGrubKey := "TEST_QEMUX86_64_UEFI_GRUB"
1✔
541
        buildParameters = append(
1✔
542
                buildParameters,
1✔
543
                &gitlab.PipelineVariableOptions{Key: &testX86UefiGrubKey, Value: &qemuParam},
1✔
544
        )
1✔
545

1✔
546
        buildX86BiosGrubKey := "BUILD_QEMUX86_64_BIOS_GRUB"
1✔
547
        buildParameters = append(
1✔
548
                buildParameters,
1✔
549
                &gitlab.PipelineVariableOptions{Key: &buildX86BiosGrubKey, Value: &qemuParam},
1✔
550
        )
1✔
551
        testX86BiosGrubKey := "TEST_QEMUX86_64_BIOS_GRUB"
1✔
552
        buildParameters = append(
1✔
553
                buildParameters,
1✔
554
                &gitlab.PipelineVariableOptions{Key: &testX86BiosGrubKey, Value: &qemuParam},
1✔
555
        )
1✔
556

1✔
557
        buildX86BiosGrubGptKey := "BUILD_QEMUX86_64_BIOS_GRUB_GPT"
1✔
558
        buildParameters = append(
1✔
559
                buildParameters,
1✔
560
                &gitlab.PipelineVariableOptions{Key: &buildX86BiosGrubGptKey, Value: &qemuParam},
1✔
561
        )
1✔
562
        testX86BiosGrubGptKey := "TEST_QEMUX86_64_BIOS_GRUB_GPT"
1✔
563
        buildParameters = append(
1✔
564
                buildParameters,
1✔
565
                &gitlab.PipelineVariableOptions{Key: &testX86BiosGrubGptKey, Value: &qemuParam},
1✔
566
        )
1✔
567

1✔
568
        buildVexpress := "BUILD_VEXPRESS_QEMU"
1✔
569
        buildParameters = append(
1✔
570
                buildParameters,
1✔
571
                &gitlab.PipelineVariableOptions{Key: &buildVexpress, Value: &qemuParam},
1✔
572
        )
1✔
573
        testVexpress := "TEST_VEXPRESS_QEMU"
1✔
574
        buildParameters = append(
1✔
575
                buildParameters,
1✔
576
                &gitlab.PipelineVariableOptions{Key: &testVexpress, Value: &qemuParam},
1✔
577
        )
1✔
578

1✔
579
        buildVexpressFlash := "BUILD_VEXPRESS_QEMU_FLASH"
1✔
580
        buildParameters = append(
1✔
581
                buildParameters,
1✔
582
                &gitlab.PipelineVariableOptions{Key: &buildVexpressFlash, Value: &qemuParam},
1✔
583
        )
1✔
584
        testVexpressFlash := "TEST_VEXPRESS_QEMU_FLASH"
1✔
585
        buildParameters = append(
1✔
586
                buildParameters,
1✔
587
                &gitlab.PipelineVariableOptions{Key: &testVexpressFlash, Value: &qemuParam},
1✔
588
        )
1✔
589

1✔
590
        buildVexpressUbootUefiGrub := "BUILD_VEXPRESS_QEMU_UBOOT_UEFI_GRUB"
1✔
591
        buildParameters = append(
1✔
592
                buildParameters,
1✔
593
                &gitlab.PipelineVariableOptions{Key: &buildVexpressUbootUefiGrub, Value: &qemuParam},
1✔
594
        )
1✔
595
        testVexpressUbootUefiGrub := "TEST_VEXPRESS_QEMU_UBOOT_UEFI_GRUB"
1✔
596
        buildParameters = append(
1✔
597
                buildParameters,
1✔
598
                &gitlab.PipelineVariableOptions{Key: &testVexpressUbootUefiGrub, Value: &qemuParam},
1✔
599
        )
1✔
600

1✔
601
        buildBBBKey := "BUILD_BEAGLEBONEBLACK"
1✔
602
        buildParameters = append(
1✔
603
                buildParameters,
1✔
604
                &gitlab.PipelineVariableOptions{Key: &buildBBBKey, Value: &qemuParam},
1✔
605
        )
1✔
606

1✔
607
        // Set BUILD_CLIENT = false, if target repo not in the qemuBuildRepositories list
1✔
608
        buildClientKey := "BUILD_CLIENT"
1✔
609
        buildClient := "false"
1✔
610
        for _, prebuiltClientRepo := range qemuBuildRepositories {
2✔
611
                if build.repo == prebuiltClientRepo {
2✔
612
                        buildClient = "true"
1✔
613
                }
1✔
614
        }
615
        if build.baseBranch == "feature-c++-client" {
2✔
616
                // While developing the C++ client, we cannot use pre-built QEMU images.
1✔
617
                buildClient = "true"
1✔
618
        }
1✔
619
        buildParameters = append(
1✔
620
                buildParameters,
1✔
621
                &gitlab.PipelineVariableOptions{Key: &buildClientKey, Value: &buildClient},
1✔
622
        )
1✔
623

1✔
624
        return buildParameters, nil
1✔
625
}
626

627
// stopBuildsOfStalePRs stops any running pipelines on a PR which has been merged.
628
func stopBuildsOfStalePRs(log *logrus.Entry, pr *github.PullRequestEvent, conf *config) error {
2✔
629

2✔
630
        // If the action is "closed" the pull request was merged or just closed,
2✔
631
        // stop builds in both cases.
2✔
632
        if pr.GetAction() != "closed" {
4✔
633
                log.Debugf("stopBuildsOfStalePRs: PR not closed, therefore not stopping it's pipeline")
2✔
634
                return nil
2✔
635
        }
2✔
636

637
        log.Debug("stopBuildsOfStalePRs: Find any running pipelines and kill mercilessly!")
1✔
638

1✔
639
        for _, build := range getBuilds(log, conf, pr) {
2✔
640

1✔
641
                gitlabClient, err := clientgitlab.NewGitLabClient(
1✔
642
                        conf.gitlabToken,
1✔
643
                        conf.gitlabBaseURL,
1✔
644
                        conf.dryRunMode,
1✔
645
                )
1✔
646
                if err != nil {
1✔
647
                        return err
×
648
                }
×
649

650
                buildParams, err := getBuildParameters(log, conf, &build, NewBuildOptions())
1✔
651
                if err != nil {
1✔
652
                        log.Debug("stopBuildsOfStalePRs: Failed to get the build-parameters for the build")
×
653
                        return err
×
654
                }
×
655

656
                stopStalePipelines(log, gitlabClient, buildParams)
1✔
657
        }
658

659
        return nil
1✔
660

661
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc