-
Notifications
You must be signed in to change notification settings - Fork 618
/
shell_gha.go
53 lines (43 loc) · 975 Bytes
/
shell_gha.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
package cmd
import (
"fmt"
"strings"
)
type gha struct{}
// GitHubActions shell instance
var GitHubActions Shell = gha{}
func (sh gha) Hook() (string, error) {
return "", fmt.Errorf("Hook not implemented for GitHub Actions shell")
}
func (sh gha) Export(e ShellExport) string {
var b strings.Builder
for key, value := range e {
if value == nil {
sh.unset(&b, key)
} else {
sh.export(&b, key, *value)
}
}
return b.String()
}
const ghaDelim = "DIRENV_GITHUB_ACTIONS_EOV\n"
func (sh gha) Dump(env Env) string {
var b strings.Builder
for key, value := range env {
sh.export(&b, key, value)
}
return b.String()
}
func (sh gha) export(b *strings.Builder, key, value string) {
b.WriteString(key)
b.WriteString("<<")
b.WriteString(ghaDelim)
b.WriteString(value)
if value != "" && !strings.HasSuffix(value, "\n") {
b.WriteByte('\n')
}
b.WriteString(ghaDelim)
}
func (sh gha) unset(b *strings.Builder, key string) {
sh.export(b, key, "")
}