• 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

69.15
/gitlab_sync.go
1
package main
2

3
import (
4
        "fmt"
5
        "regexp"
6
        "strings"
7

8
        "github.com/sirupsen/logrus"
9

10
        "github.com/mendersoftware/integration-test-runner/git"
11
)
12

13
type branchDepth int
14

15
const fullDepth = -1
16

17
func shouldStartPipeline(branchName string) bool {
8✔
18
        startByName := []string{
8✔
19
                "master",
8✔
20
                "staging",
8✔
21
                "production",
8✔
22
                "hosted",
8✔
23
                "main",
8✔
24
        }
8✔
25
        for _, n := range startByName {
31✔
26
                if branchName == n {
28✔
27
                        return true
5✔
28
                }
5✔
29
        }
30

31
        startByRegEx := []*regexp.Regexp{
3✔
32
                regexp.MustCompile(`^[0-9]+\.[0-9]+\.x`),
3✔
33
                regexp.MustCompile(`^pr_[0-9]+$`),
3✔
34
        }
3✔
35
        for _, n := range startByRegEx {
8✔
36
                if n.MatchString(branchName) {
7✔
37
                        return true
2✔
38
                }
2✔
39
        }
40

41
        return false
1✔
42
}
43

44
func syncRemoteRef(log *logrus.Entry, org, repo, ref string, conf *config) error {
2✔
45

2✔
46
        remoteURLGitLab, err := getRemoteURLGitLab(org, repo)
2✔
47
        if err != nil {
2✔
48
                return fmt.Errorf("getRemoteURLGitLab returned error: %s", err.Error())
×
49
        }
×
50

51
        state, err := git.Commands(
2✔
52
                git.Command("init", "."),
2✔
53
                git.Command("remote", "add", "github",
2✔
54
                        getRemoteURLGitHub(conf.githubProtocol, conf.githubOrganization, repo)),
2✔
55
                git.Command("remote", "add", "gitlab", remoteURLGitLab),
2✔
56
        )
2✔
57
        defer state.Cleanup()
2✔
58
        if err != nil {
2✔
59
                return err
×
60
        }
×
61

62
        depths := []branchDepth{5, 10, 50, 100, fullDepth} // 0 = infinite depth
2✔
63
        for _, depth := range depths {
4✔
64

2✔
65
                log.Infof("Fetching branch at depth: %d", depth)
2✔
66
                err := fetchCmd(ref, repo, state, depth)
2✔
67
                if err == nil {
4✔
68
                        break
2✔
69
                }
70
                log.Infof("Failed to sync the remotes at depth: %d", depth)
×
71
        }
72

73
        log.Infof("Pushed ref to GitLab: %s:%s", repo, ref)
2✔
74
        return nil
2✔
75
}
76

77
func setDepth(depth branchDepth) string {
2✔
78
        switch depth {
2✔
79
        case fullDepth:
×
80
                return ""
×
81
        default:
2✔
82
                return fmt.Sprintf("--depth=%d", depth)
2✔
83

84
        }
85
}
86

87
func fetchCmd(ref, repo string, state *git.State, depth branchDepth) error {
2✔
88

2✔
89
        if strings.Contains(ref, "tags") {
2✔
90
                tagName := strings.TrimPrefix(ref, "refs/tags/")
×
91

×
92
                err := git.Command("fetch", setDepth(depth), "--tags", "github").With(state).Run()
×
93

×
94
                if err != nil {
×
95
                        return err
×
96
                }
×
97
                err = git.Command("push", "-f", "gitlab", tagName).With(state).Run()
×
98
                if err != nil {
×
99
                        return err
×
100
                }
×
101
        } else if strings.Contains(ref, "heads") {
4✔
102
                branchName := strings.TrimPrefix(ref, "refs/heads/")
2✔
103

2✔
104
                err := git.Command("fetch", setDepth(depth), "github").With(state).Run()
2✔
105
                if err != nil {
2✔
106
                        return err
×
107
                }
×
108
                err = git.Command("checkout", "-b", branchName, "github/"+branchName).With(state).Run()
2✔
109
                if err != nil {
2✔
110
                        return err
×
111
                }
×
112
                // For the push, add option ci.skip for mender-qa
113
                cmdArgs := []string{"push", "-f"}
2✔
114
                if repo == "mender-qa" {
3✔
115
                        cmdArgs = append(cmdArgs, "-o", "ci.skip")
1✔
116
                }
1✔
117
                if !shouldStartPipeline(branchName) {
2✔
118
                        cmdArgs = append(cmdArgs, "-o", "ci.skip")
×
119
                }
×
120
                cmdArgs = append(cmdArgs, "gitlab", branchName)
2✔
121
                err = git.Command(cmdArgs...).With(state).Run()
2✔
122
                if err != nil {
2✔
123
                        return err
×
124
                }
×
125
        } else {
×
126
                return fmt.Errorf("Unrecognized ref %s", ref)
×
127
        }
×
128

129
        return nil
2✔
130
}
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