-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuildevent.go
160 lines (147 loc) · 4.58 KB
/
buildevent.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package action
import (
"context"
"github.com/pkg/errors"
"github.com/samber/lo"
"projectforge.dev/projectforge/app/file/diff"
"projectforge.dev/projectforge/app/lib/telemetry"
"projectforge.dev/projectforge/app/module"
"projectforge.dev/projectforge/app/project/build"
"projectforge.dev/projectforge/app/util"
)
func onBuild(ctx context.Context, pm *PrjAndMods) *Result {
phaseStr := pm.Cfg.GetStringOpt("phase")
if phaseStr == "" {
if x, _ := pm.Cfg.GetStringArray("cmds", true); len(x) == 1 {
phaseStr = x[0]
} else {
phaseStr = "build"
}
}
_, span, logger := telemetry.StartSpan(ctx, "build:"+phaseStr, pm.Logger)
span.Attribute("project", pm.Prj.Key)
defer span.Complete()
pm.Logger = logger
ret := newResult(TypeBuild, pm.Prj, pm.Cfg, logger)
ret.AddLog("building project [%s] in [%s] with phase [%s]", pm.Prj.Key, pm.Prj.Path, phaseStr)
phase := AllBuilds.Get(phaseStr)
if phase == nil {
return ret.WithError(errors.Errorf("invalid phase [%s]", phaseStr))
}
timer := util.TimerStart()
ret = phase.Run(ctx, pm, ret)
ret.Duration = timer.End()
return ret
}
func onDeps(ctx context.Context, pm *PrjAndMods, ret *Result) *Result {
if up := ret.Args.GetStringOpt("upgrade"); up != "" {
o := ret.Args.GetStringOpt("old")
n := ret.Args.GetStringOpt("new")
err := build.OnDepsUpgrade(ctx, pm.Prj, up, o, n, pm.PSvc, pm.Logger)
if err != nil {
return ret.WithError(err)
}
}
upd := ret.Args.GetStringOpt("upd")
showAll := pm.Cfg.GetBoolOpt("showAll")
pfs, err := pm.PSvc.GetFilesystem(pm.Prj)
if err != nil {
return ret.WithError(err)
}
deps, err := build.LoadDeps(ctx, pm.Prj.Key, pm.Prj.Path, upd != util.BoolFalse, pfs, showAll, pm.Logger)
ret.Data = deps
if err != nil {
return ret.WithError(err)
}
return ret
}
func onImports(_ context.Context, pm *PrjAndMods, r *Result) *Result {
fixStr := r.Args.GetStringOpt("fix")
fix := fixStr == util.BoolTrue
fileStr := r.Args.GetStringOpt("file")
t := util.TimerStart()
pfs, err := pm.PSvc.GetFilesystem(pm.Prj)
if err != nil {
return r.WithError(err)
}
logs, diffs, err := build.Imports(pm.Prj.Package, fix, fileStr, pfs, pm.Logger)
r.Modules = append(r.Modules, &module.Result{Keys: []string{"imports"}, Status: "OK", Diffs: diffs, Duration: t.End()})
r.Logs = append(r.Logs, logs...)
if err != nil {
return r.WithError(err)
}
return r
}
func onIgnored(_ context.Context, pm *PrjAndMods, r *Result) *Result {
pfs, err := pm.PSvc.GetFilesystem(pm.Prj)
if err != nil {
return r.WithError(err)
}
ign, err := build.Ignored(pm.Prj, pfs, pm.Logger)
r.Data = ign
if err != nil {
return r.WithError(err)
}
res := &module.Result{Keys: []string{"ignored"}, Status: "OK"}
lo.ForEach(ign, func(x string, _ int) {
if x != "app/file/header.go" && x != "doc/faq.md" {
res.Diffs = append(res.Diffs, &diff.Diff{Path: x, Status: diff.StatusDifferent})
}
})
r.Modules = append(r.Modules, res)
return r
}
func onPackages(_ context.Context, pm *PrjAndMods, r *Result) *Result {
pfs, err := pm.PSvc.GetFilesystem(pm.Prj)
if err != nil {
return r.WithError(err)
}
pkgs, err := build.Packages(pm.Prj, pfs, pm.Cfg.GetBoolOpt("all"), pm.Logger)
r.Data = pkgs
if err != nil {
return r.WithError(err)
}
return r
}
func onCleanup(_ context.Context, pm *PrjAndMods, r *Result) *Result {
t := util.TimerStart()
pfs, err := pm.PSvc.GetFilesystem(pm.Prj)
if err != nil {
return r.WithError(err)
}
logs, diffs, err := build.Cleanup(pfs, pm.Logger)
r.Modules = append(r.Modules, &module.Result{Keys: []string{"cleanup"}, Status: "OK", Diffs: diffs, Duration: t.End()})
r.Logs = append(r.Logs, logs...)
if err != nil {
return r.WithError(err)
}
return r
}
func onFull(ctx context.Context, pm *PrjAndMods, r *Result) *Result {
t := util.TimerStart()
logs, err := build.Full(ctx, pm.Prj, pm.Logger)
r.Modules = append(r.Modules, &module.Result{Keys: []string{"fullbuild"}, Status: "OK", Duration: t.End()})
r.Logs = append(r.Logs, logs...)
if err != nil {
return r.WithError(err)
}
return r
}
func onDeployments(_ context.Context, pm *PrjAndMods, r *Result) *Result {
if pm.Prj.Info == nil || len(pm.Prj.Info.Deployments) == 0 {
return r
}
t := util.TimerStart()
fix := pm.Cfg.GetBoolOpt("fix")
pfs, err := pm.PSvc.GetFilesystem(pm.Prj)
if err != nil {
return r.WithError(err)
}
logs, diffs, err := build.Deployments(pm.Prj.Version, pfs, fix, pm.Cfg.GetStringOpt("path"), pm.Prj.Info.Deployments)
r.Modules = append(r.Modules, &module.Result{Keys: []string{"deployments"}, Status: "OK", Diffs: diffs, Duration: t.End()})
r.Logs = append(r.Logs, logs...)
if err != nil {
return r.WithError(err)
}
return r
}