-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvci.go
71 lines (58 loc) · 1.13 KB
/
envci.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
package envci
import (
env "github.com/tj/go/env"
)
// Detect current CI
func Detect() *EnvCI {
variables := &EnvCI{IsCI: false}
if ci := env.GetDefault("CI", ""); ci != "" {
variables.IsCI = true
}
for service, e := range Services {
if env.GetDefault(e.Base, "") != "" {
variables.IsCI = true
variables.Service = service
variables.Commit = e.Commit
variables.Build = e.Build
variables.Branch = e.Branch
variables.Job = e.Job
variables.PR = e.PR
variables.IsPR = variables.PR != ""
variables.Slug = e.Slug
variables.Root = e.Root
break
}
}
// TODO Get lastet commit
// if variables.Commit == "" {
// }
// TODO Get working branch
// if variables.Branch == "" {
// }
return variables
}
// IsCI tests if CI is in use
func IsCI() bool {
if env.GetDefault("CI", "") != "" {
return true
}
for _, e := range Services {
if env.GetDefault(e.Base, "") != "" {
return true
}
}
return false
}
// EnvCI variables
type EnvCI struct {
IsCI bool
Service string
Commit string
Build string
Branch string
Job string
PR string
IsPR bool
Slug string
Root string
}