-
Notifications
You must be signed in to change notification settings - Fork 0
/
cicd.go
109 lines (93 loc) · 3.11 KB
/
cicd.go
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
package azuretpl
import (
"encoding/base64"
"fmt"
"os"
"strings"
"sync/atomic"
)
var (
cicdMaskVarNumber atomic.Uint64
)
func (e *AzureTemplateExecutor) handleCicdMaskSecret(val string) {
workflowLogMsgList := []string{}
// only show first line of error (could be a multi line error message)
val = strings.SplitN(val, "\n", 2)[0]
switch {
case os.Getenv("SYSTEM_TEAMFOUNDATIONSERVERURI") != "":
// Azure DevOps
workflowLogMsgList = append(
workflowLogMsgList,
fmt.Sprintf(`##vso[task.setvariable variable=HELM_AZURETPL_SECRET_MASK_%d;isSecret=true]%v`, cicdMaskVarNumber.Add(1), val),
fmt.Sprintf(`##vso[task.setvariable variable=HELM_AZURETPL_SECRET_MASK_%d;isSecret=true]%v`, cicdMaskVarNumber.Add(1), base64.StdEncoding.EncodeToString([]byte(val))),
)
case os.Getenv("GITLAB_CI") != "":
// GitLab
// no secret masking available
case os.Getenv("JENKINS_URL") != "":
// Jenkins
// no secret masking available
case os.Getenv("GITHUB_ACTION") != "":
// GitHub
workflowLogMsgList = append(
workflowLogMsgList,
fmt.Sprintf(`::add-mask::%v`, val),
fmt.Sprintf(`::add-mask::%v`, base64.StdEncoding.EncodeToString([]byte(val))),
)
}
for _, workflowLogMsg := range workflowLogMsgList {
e.logger.Sync() //nolint:errcheck
fmt.Fprintln(os.Stderr, workflowLogMsg)
e.logger.Sync() //nolint:errcheck
}
}
func (e *AzureTemplateExecutor) handleCicdWarning(err error) error {
workflowLogMsg := ""
// only show first line of error (could be a multi line error message)
workflowLogError := strings.SplitN(err.Error(), "\n", 2)[0]
switch {
case os.Getenv("SYSTEM_TEAMFOUNDATIONSERVERURI") != "":
// Azure DevOps
workflowLogMsg = fmt.Sprintf(`##vso[task.logissue type=warning;sourcepath=%v]%v`, e.currentPath, workflowLogError)
case os.Getenv("GITLAB_CI") != "":
// GitLab
// no error logging available
case os.Getenv("JENKINS_URL") != "":
// Jenkins
// no error logging available
case os.Getenv("GITHUB_ACTION") != "":
// GitHub
workflowLogMsg = fmt.Sprintf(`::warning file=%v,title=helm-azure-tpl::%v`, e.currentPath, workflowLogError)
}
if workflowLogMsg != "" {
e.logger.Sync() //nolint:errcheck
fmt.Fprintln(os.Stderr, workflowLogMsg)
e.logger.Sync() //nolint:errcheck
}
return err
}
func (e *AzureTemplateExecutor) handleCicdError(err error) error {
workflowLogMsg := ""
// only show first line of error (could be a multi line error message)
workflowLogError := strings.SplitN(err.Error(), "\n", 2)[0]
switch {
case os.Getenv("SYSTEM_TEAMFOUNDATIONSERVERURI") != "":
// Azure DevOps
workflowLogMsg = fmt.Sprintf(`##vso[task.logissue type=error;sourcepath=%v]%v`, e.currentPath, workflowLogError)
case os.Getenv("GITLAB_CI") != "":
// GitLab
// no error logging available
case os.Getenv("JENKINS_URL") != "":
// Jenkins
// no error logging available
case os.Getenv("GITHUB_ACTION") != "":
// GitHub
workflowLogMsg = fmt.Sprintf(`::error file=%v,title=helm-azure-tpl::%v`, e.currentPath, workflowLogError)
}
if workflowLogMsg != "" {
e.logger.Sync() //nolint:errcheck
fmt.Fprintln(os.Stderr, workflowLogMsg)
e.logger.Sync() //nolint:errcheck
}
return err
}