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

mendersoftware / integration-test-runner / 1583018314

10 Dec 2024 11:26PM UTC coverage: 68.703%. Remained the same
1583018314

Pull #336

gitlab-ci

danielskinstad
ci: pin docker to v27.3

Fixes runc errors in the hetzner runner
Use dependency proxy

Ticket: QA-823

Signed-off-by: Daniel Skinstad Drabitzius <daniel.drabitzius@northern.tech>
Pull Request #336: ci: pin docker to v27.3

1732 of 2521 relevant lines covered (68.7%)

2.49 hits per line

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

82.7
/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
        allRepositories, err := getListOfAllRepositories(conf)
3✔
93
        if err != nil {
5✔
94
                log.Warnf(err.Error())
2✔
95
        }
2✔
96

97
        for _, watchRepo := range allRepositories {
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 isLegacyBuild(build *buildOptions, buildParameters []*gitlab.PipelineVariableOptions) bool {
1✔
178
        // We define a legacy build as either:
1✔
179
        // * A PR in integration repo with baseBranch 3.7.x
1✔
180
        // * A PR in any repo for which INTEGRATION_REV variable is set to 3.7.x
1✔
181
        if build.repo == "integration" {
1✔
182
                return build.baseBranch == "3.7.x"
×
183
        }
×
184
        for _, param := range buildParameters {
2✔
185
                if *param.Key == "INTEGRATION_REV" {
2✔
186
                        return *param.Value == "3.7.x"
1✔
187
                }
1✔
188
        }
189
        // This should never happen, INTEGRATION_REV must be found! But just in case...
190
        return false
×
191
}
192

193
func getMenderQARef(build *buildOptions, buildParameters []*gitlab.PipelineVariableOptions) string {
1✔
194
        if isLegacyBuild(build, buildParameters) {
1✔
195
                return "legacy-mender-3.7-lts"
×
196
        }
×
197
        return "master"
1✔
198
}
199

200
func triggerBuild(
201
        log *logrus.Entry,
202
        conf *config,
203
        build *buildOptions,
204
        pr *github.PullRequestEvent,
205
        buildOptions *BuildOptions,
206
) error {
1✔
207
        gitlabClient, err := clientgitlab.NewGitLabClient(
1✔
208
                conf.gitlabToken,
1✔
209
                conf.gitlabBaseURL,
1✔
210
                conf.dryRunMode,
1✔
211
        )
1✔
212
        if err != nil {
1✔
213
                return err
×
214
        }
×
215

216
        buildParameters, err := getBuildParameters(log, conf, build, buildOptions)
1✔
217
        if err != nil {
1✔
218
                return err
×
219
        }
×
220

221
        // first stop old pipelines with the same buildParameters
222
        stopStalePipelines(log, gitlabClient, buildParameters)
1✔
223

1✔
224
        // trigger the new pipeline
1✔
225
        integrationPipelinePath := "Northern.tech/Mender/mender-qa"
1✔
226
        ref := getMenderQARef(build, buildParameters)
1✔
227
        opt := &gitlab.CreatePipelineOptions{
1✔
228
                Ref:       &ref,
1✔
229
                Variables: &buildParameters,
1✔
230
        }
1✔
231

1✔
232
        variablesString := ""
1✔
233
        for _, variable := range *opt.Variables {
2✔
234
                variablesString += *variable.Key + ":" + *variable.Value + ", "
1✔
235
        }
1✔
236
        log.Infof(
1✔
237
                "Creating pipeline in project %s:%s with variables: %s",
1✔
238
                integrationPipelinePath,
1✔
239
                *opt.Ref,
1✔
240
                variablesString,
1✔
241
        )
1✔
242

1✔
243
        pipeline, err := gitlabClient.CreatePipeline(integrationPipelinePath, opt)
1✔
244
        if err != nil {
1✔
245
                log.Errorf("Could not create pipeline: %s", err.Error())
×
246
                return err
×
247
        }
×
248
        log.Infof("Created pipeline: %s", pipeline.WebURL)
1✔
249

1✔
250
        // Add the build variable matrix to the pipeline comment under a
1✔
251
        // drop-down tab
1✔
252
        // nolint:lll
1✔
253
        tmplString := `
1✔
254
Hello :smiley_cat: I created a pipeline for you here: [Pipeline-{{.Pipeline.ID}}]({{.Pipeline.WebURL}})
1✔
255

1✔
256
<details>
1✔
257
    <summary>Build Configuration Matrix</summary><p>
1✔
258

1✔
259
| Key   | Value |
1✔
260
| ----- | ----- |
1✔
261
{{range $i, $var := .BuildVars}}{{if $var.Value}}| {{$var.Key}} | {{$var.Value}} |{{printf "\n"}}{{end}}{{end}}
1✔
262

1✔
263
 </p></details>
1✔
264
`
1✔
265
        tmpl, err := template.New("Main").Parse(tmplString)
1✔
266
        if err != nil {
1✔
267
                log.Errorf(
×
268
                        "Failed to parse the build matrix template. Should never happen! Error: %s\n",
×
269
                        err.Error(),
×
270
                )
×
271
                return err
×
272
        }
×
273
        var buf bytes.Buffer
1✔
274
        if err = tmpl.Execute(&buf, struct {
1✔
275
                BuildVars []*gitlab.PipelineVariableOptions
1✔
276
                Pipeline  *gitlab.Pipeline
1✔
277
        }{
1✔
278
                BuildVars: filterOutEmptyVariables(*opt.Variables),
1✔
279
                Pipeline:  pipeline,
1✔
280
        }); err != nil {
1✔
281
                log.Errorf("Failed to execute the build matrix template. Error: %s\n", err.Error())
×
282
                return err
×
283
        }
×
284

285
        // Comment with a pipeline-link on the PR
286
        commentBody := buf.String()
1✔
287
        comment := github.IssueComment{
1✔
288
                Body: &commentBody,
1✔
289
        }
1✔
290

1✔
291
        err = githubClient.CreateComment(context.Background(),
1✔
292
                conf.githubOrganization, pr.GetRepo().GetName(), pr.GetNumber(), &comment)
1✔
293
        if err != nil {
1✔
294
                log.Infof("Failed to comment on the pr: %v, Error: %s", pr, err.Error())
×
295
        }
×
296

297
        return err
1✔
298
}
299

300
func stopStalePipelines(
301
        log *logrus.Entry,
302
        client clientgitlab.Client,
303
        vars []*gitlab.PipelineVariableOptions,
304
) {
1✔
305
        integrationPipelinePath := "Northern.tech/Mender/mender-qa"
1✔
306

1✔
307
        sort.SliceStable(vars, func(i, j int) bool {
2✔
308
                return *vars[i].Key < *vars[j].Key
1✔
309
        })
1✔
310

311
        username := githubBotName
1✔
312
        status := gitlab.Pending
1✔
313
        opt := &gitlab.ListProjectPipelinesOptions{
1✔
314
                Username: &username,
1✔
315
                Status:   &status,
1✔
316
        }
1✔
317

1✔
318
        pipelinesPending, err := client.ListProjectPipelines(integrationPipelinePath, opt)
1✔
319
        if err != nil {
1✔
320
                log.Errorf("stopStalePipelines: Could not list pending pipelines: %s", err.Error())
×
321
        }
×
322

323
        status = gitlab.Running
1✔
324
        opt = &gitlab.ListProjectPipelinesOptions{
1✔
325
                Username: &username,
1✔
326
                Status:   &status,
1✔
327
        }
1✔
328

1✔
329
        pipelinesRunning, err := client.ListProjectPipelines(integrationPipelinePath, opt)
1✔
330
        if err != nil {
1✔
331
                log.Errorf("stopStalePipelines: Could not list running pipelines: %s", err.Error())
×
332
        }
×
333

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

1✔
336
                variables, err := client.GetPipelineVariables(integrationPipelinePath, pipeline.ID)
1✔
337
                if err != nil {
1✔
338
                        log.Errorf("stopStalePipelines: Could not get variables for pipeline: %s", err.Error())
×
339
                        continue
×
340
                }
341

342
                sort.SliceStable(variables, func(i, j int) bool {
1✔
343
                        return variables[i].Key < variables[j].Key
×
344
                })
×
345

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

×
349
                        err := client.CancelPipelineBuild(integrationPipelinePath, pipeline.ID)
×
350
                        if err != nil {
×
351
                                log.Errorf("stopStalePipelines: Could not cancel pipeline: %s", err.Error())
×
352
                        }
×
353

354
                }
355

356
        }
357
}
358

359
func getBuildParameters(
360
        log *logrus.Entry,
361
        conf *config,
362
        build *buildOptions,
363
        buildOptions *BuildOptions,
364
) ([]*gitlab.PipelineVariableOptions, error) {
1✔
365
        var err error
1✔
366
        readHead := "pull/" + build.pr + "/head"
1✔
367
        var buildParameters []*gitlab.PipelineVariableOptions
1✔
368

1✔
369
        var versionedRepositories []string
1✔
370
        if build.repo == "meta-mender" {
1✔
371
                // For meta-mender, pick master versions of all Mender release repos.
×
372
                versionedRepositories, err = getListOfVersionedRepositories("origin/master", conf)
×
373
        } else {
1✔
374
                versionedRepositories, err = getListOfVersionedRepositories(
1✔
375
                        "origin/"+build.baseBranch,
1✔
376
                        conf,
1✔
377
                )
1✔
378
        }
1✔
379
        if err != nil {
1✔
380
                log.Errorf("Could not get list of repositories: %s", err.Error())
×
381
                return nil, err
×
382
        }
×
383

384
        for _, versionedRepo := range versionedRepositories {
2✔
385
                // iterate over all the repositories (except the one we are testing) and
1✔
386
                // set the correct microservice versions
1✔
387

1✔
388
                // use the default "master" for both mender-qa, and meta-mender (set in CI)
1✔
389
                if versionedRepo != build.repo &&
1✔
390
                        versionedRepo != "integration" &&
1✔
391
                        build.repo != "meta-mender" {
2✔
392

1✔
393
                        repoKey := repoToBuildParameter(versionedRepo)
1✔
394

1✔
395
                        if _, exists := buildOptions.PullRequests[versionedRepo]; exists {
2✔
396
                                prVersion := buildOptions.PullRequests[versionedRepo]
1✔
397
                                buildParameters = append(
1✔
398
                                        buildParameters,
1✔
399
                                        &gitlab.PipelineVariableOptions{
1✔
400
                                                Key:   &repoKey,
1✔
401
                                                Value: &prVersion,
1✔
402
                                        },
1✔
403
                                )
1✔
404
                                continue
1✔
405
                        }
406
                        version, err := getServiceRevisionFromIntegration(
1✔
407
                                versionedRepo,
1✔
408
                                "origin/"+build.baseBranch,
1✔
409
                                conf,
1✔
410
                        )
1✔
411
                        if err != nil {
1✔
412
                                log.Errorf("failed to determine %s version: %s", versionedRepo, err.Error())
×
413
                                return nil, err
×
414
                        }
×
415
                        log.Infof("%s version %s is being used in %s", versionedRepo, version, build.baseBranch)
1✔
416
                        buildParameters = append(
1✔
417
                                buildParameters,
1✔
418
                                &gitlab.PipelineVariableOptions{
1✔
419
                                        Key:   &repoKey,
1✔
420
                                        Value: &version,
1✔
421
                                },
1✔
422
                        )
1✔
423
                }
424
        }
425

426
        // set the correct integration branches if we aren't performing a pull request against
427
        // integration
428
        if build.repo != "integration" && build.repo != "meta-mender" {
2✔
429
                integrationRevision := build.baseBranch
1✔
430
                if _, exists := buildOptions.PullRequests["integration"]; exists {
2✔
431
                        integrationRevision = buildOptions.PullRequests["integration"]
1✔
432
                }
1✔
433
                integrationRepoKey := repoToBuildParameter("integration")
1✔
434
                buildParameters = append(buildParameters,
1✔
435
                        &gitlab.PipelineVariableOptions{
1✔
436
                                Key:   &integrationRepoKey,
1✔
437
                                Value: &integrationRevision})
1✔
438

1✔
439
                if _, exists := buildOptions.PullRequests["meta-mender"]; exists {
2✔
440
                        metaMenderRevision := buildOptions.PullRequests["meta-mender"]
1✔
441
                        metaMenderRepoKey := repoToBuildParameter("meta-mender")
1✔
442
                        buildParameters = append(buildParameters,
1✔
443
                                &gitlab.PipelineVariableOptions{
1✔
444
                                        Key:   &metaMenderRepoKey,
1✔
445
                                        Value: &metaMenderRevision})
1✔
446
                }
1✔
447
        }
448

449
        // Set poky (& friends) and meta-mender revisions:
450
        // - If building a master PR, leave everything at defaults, which generally means
451
        //   meta-mender/master and poky/LatestStableYoctoBranch.
452
        // - If building meta-mender @ non-master, set poky branches to its baseBranch.
453
        // - If building any other repo @ non-master, set both meta-mender and poky to
454
        //   LatestStableYoctoBranch.
455
        if build.baseBranch != "master" {
2✔
456
                var pokyBranch string
1✔
457
                if build.repo == "meta-mender" {
1✔
458
                        pokyBranch = build.baseBranch
×
459
                } else {
1✔
460
                        pokyBranch = LatestStableYoctoBranch
1✔
461
                        metaMenderBranch := pokyBranch
1✔
462
                        metaMenderBranchKey := repoToBuildParameter("meta-mender")
1✔
463
                        buildParameters = append(
1✔
464
                                buildParameters,
1✔
465
                                &gitlab.PipelineVariableOptions{
1✔
466
                                        Key:   &metaMenderBranchKey,
1✔
467
                                        Value: &metaMenderBranch,
1✔
468
                                },
1✔
469
                        )
1✔
470
                }
1✔
471
                pokyBranchKey := repoToBuildParameter("poky")
1✔
472
                buildParameters = append(
1✔
473
                        buildParameters,
1✔
474
                        &gitlab.PipelineVariableOptions{Key: &pokyBranchKey, Value: &pokyBranch},
1✔
475
                )
1✔
476
                metaOEPokyBranchKey := repoToBuildParameter("meta-openembedded")
1✔
477
                buildParameters = append(
1✔
478
                        buildParameters,
1✔
479
                        &gitlab.PipelineVariableOptions{
1✔
480
                                Key:   &metaOEPokyBranchKey,
1✔
481
                                Value: &pokyBranch,
1✔
482
                        },
1✔
483
                )
1✔
484
                metaRPIPokyBranchKey := repoToBuildParameter("meta-raspberrypi")
1✔
485
                buildParameters = append(
1✔
486
                        buildParameters,
1✔
487
                        &gitlab.PipelineVariableOptions{
1✔
488
                                Key:   &metaRPIPokyBranchKey,
1✔
489
                                Value: &pokyBranch,
1✔
490
                        },
1✔
491
                )
1✔
492
        }
493

494
        // set the rest of the CI build parameters
495
        runIntegrationTests := "true"
1✔
496
        runIntegrationTestsKey := "RUN_INTEGRATION_TESTS"
1✔
497
        buildParameters = append(
1✔
498
                buildParameters,
1✔
499
                &gitlab.PipelineVariableOptions{Key: &runIntegrationTestsKey, Value: &runIntegrationTests},
1✔
500
        )
1✔
501

1✔
502
        // Backend integration tests, from mender-qa pipeline, are only relevant for legacy builds
1✔
503
        if isLegacyBuild(build, buildParameters) {
1✔
504
                runBackendIntegrationTests := "true"
×
505
                if buildOptions.Fast {
×
506
                        runIntegrationTests = "false"
×
507
                }
×
508

509
                runBackendIntegrationTestsKey := "RUN_BACKEND_INTEGRATION_TESTS"
×
510
                buildParameters = append(
×
511
                        buildParameters,
×
512
                        &gitlab.PipelineVariableOptions{
×
513
                                Key: &runBackendIntegrationTestsKey, Value: &runBackendIntegrationTests,
×
514
                        },
×
515
                )
×
516
        }
517

518
        buildRepoKey := repoToBuildParameter(build.repo)
1✔
519
        buildParameters = append(buildParameters,
1✔
520
                &gitlab.PipelineVariableOptions{
1✔
521
                        Key:   &buildRepoKey,
1✔
522
                        Value: &readHead,
1✔
523
                })
1✔
524

1✔
525
        return getClientBuildParameters(buildParameters, build)
1✔
526
}
527

528
func getClientBuildParameters(
529
        buildParameters []*gitlab.PipelineVariableOptions,
530
        build *buildOptions,
531
) ([]*gitlab.PipelineVariableOptions, error) {
1✔
532
        var qemuParam string
1✔
533
        if build.makeQEMU {
2✔
534
                qemuParam = "true"
1✔
535
        } else {
2✔
536
                qemuParam = ""
1✔
537
        }
1✔
538

539
        buildX86UefiGrubKey := "BUILD_QEMUX86_64_UEFI_GRUB"
1✔
540
        buildParameters = append(
1✔
541
                buildParameters,
1✔
542
                &gitlab.PipelineVariableOptions{Key: &buildX86UefiGrubKey, Value: &qemuParam},
1✔
543
        )
1✔
544
        testX86UefiGrubKey := "TEST_QEMUX86_64_UEFI_GRUB"
1✔
545
        buildParameters = append(
1✔
546
                buildParameters,
1✔
547
                &gitlab.PipelineVariableOptions{Key: &testX86UefiGrubKey, Value: &qemuParam},
1✔
548
        )
1✔
549

1✔
550
        buildX86BiosGrubKey := "BUILD_QEMUX86_64_BIOS_GRUB"
1✔
551
        buildParameters = append(
1✔
552
                buildParameters,
1✔
553
                &gitlab.PipelineVariableOptions{Key: &buildX86BiosGrubKey, Value: &qemuParam},
1✔
554
        )
1✔
555
        testX86BiosGrubKey := "TEST_QEMUX86_64_BIOS_GRUB"
1✔
556
        buildParameters = append(
1✔
557
                buildParameters,
1✔
558
                &gitlab.PipelineVariableOptions{Key: &testX86BiosGrubKey, Value: &qemuParam},
1✔
559
        )
1✔
560

1✔
561
        buildX86BiosGrubGptKey := "BUILD_QEMUX86_64_BIOS_GRUB_GPT"
1✔
562
        buildParameters = append(
1✔
563
                buildParameters,
1✔
564
                &gitlab.PipelineVariableOptions{Key: &buildX86BiosGrubGptKey, Value: &qemuParam},
1✔
565
        )
1✔
566
        testX86BiosGrubGptKey := "TEST_QEMUX86_64_BIOS_GRUB_GPT"
1✔
567
        buildParameters = append(
1✔
568
                buildParameters,
1✔
569
                &gitlab.PipelineVariableOptions{Key: &testX86BiosGrubGptKey, Value: &qemuParam},
1✔
570
        )
1✔
571

1✔
572
        buildVexpress := "BUILD_VEXPRESS_QEMU"
1✔
573
        buildParameters = append(
1✔
574
                buildParameters,
1✔
575
                &gitlab.PipelineVariableOptions{Key: &buildVexpress, Value: &qemuParam},
1✔
576
        )
1✔
577
        testVexpress := "TEST_VEXPRESS_QEMU"
1✔
578
        buildParameters = append(
1✔
579
                buildParameters,
1✔
580
                &gitlab.PipelineVariableOptions{Key: &testVexpress, Value: &qemuParam},
1✔
581
        )
1✔
582

1✔
583
        buildVexpressFlash := "BUILD_VEXPRESS_QEMU_FLASH"
1✔
584
        buildParameters = append(
1✔
585
                buildParameters,
1✔
586
                &gitlab.PipelineVariableOptions{Key: &buildVexpressFlash, Value: &qemuParam},
1✔
587
        )
1✔
588
        testVexpressFlash := "TEST_VEXPRESS_QEMU_FLASH"
1✔
589
        buildParameters = append(
1✔
590
                buildParameters,
1✔
591
                &gitlab.PipelineVariableOptions{Key: &testVexpressFlash, Value: &qemuParam},
1✔
592
        )
1✔
593

1✔
594
        buildVexpressUbootUefiGrub := "BUILD_VEXPRESS_QEMU_UBOOT_UEFI_GRUB"
1✔
595
        buildParameters = append(
1✔
596
                buildParameters,
1✔
597
                &gitlab.PipelineVariableOptions{Key: &buildVexpressUbootUefiGrub, Value: &qemuParam},
1✔
598
        )
1✔
599
        testVexpressUbootUefiGrub := "TEST_VEXPRESS_QEMU_UBOOT_UEFI_GRUB"
1✔
600
        buildParameters = append(
1✔
601
                buildParameters,
1✔
602
                &gitlab.PipelineVariableOptions{Key: &testVexpressUbootUefiGrub, Value: &qemuParam},
1✔
603
        )
1✔
604

1✔
605
        buildBBBKey := "BUILD_BEAGLEBONEBLACK"
1✔
606
        buildParameters = append(
1✔
607
                buildParameters,
1✔
608
                &gitlab.PipelineVariableOptions{Key: &buildBBBKey, Value: &qemuParam},
1✔
609
        )
1✔
610

1✔
611
        // Set BUILD_CLIENT = false, if target repo not in the qemuBuildRepositories list
1✔
612
        buildClientKey := "BUILD_CLIENT"
1✔
613
        buildClient := "false"
1✔
614
        for _, prebuiltClientRepo := range qemuBuildRepositories {
2✔
615
                if build.repo == prebuiltClientRepo {
2✔
616
                        buildClient = "true"
1✔
617
                }
1✔
618
        }
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