-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.go
61 lines (50 loc) · 1.53 KB
/
build.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
package baur
import (
"fmt"
"github.com/pkg/errors"
"github.com/simplesurance/baur/storage"
)
// BuildStatus indicates if build for a current application version exist
type BuildStatus int
const (
_ BuildStatus = iota
// BuildStatusInputsUndefined inputs of the application are undefined,
BuildStatusInputsUndefined
// BuildStatusExist a build exist
BuildStatusExist
// BuildStatusOutstanding no build exist
BuildStatusOutstanding
)
func (b BuildStatus) String() string {
switch b {
case BuildStatusInputsUndefined:
return "Inputs Undefined"
case BuildStatusExist:
return "Exist"
case BuildStatusOutstanding:
return "Outstanding"
default:
panic(fmt.Sprintf("incompatible BuildStatus value: %d", b))
}
}
// GetBuildStatus calculates the total input digest of the app and checks in the
// storage if a build for this input digest already exist.
// If the function returns BuildStatusExist the returned build pointer is valid
// otherwise it is nil.
func GetBuildStatus(storer storage.Storer, app *App) (BuildStatus, *storage.BuildWithDuration, error) {
if !app.HasBuildInputs() {
return BuildStatusInputsUndefined, nil, nil
}
d, err := app.TotalInputDigest()
if err != nil {
return -1, nil, errors.Wrap(err, "calculating total input digest failed")
}
build, err := storer.GetLatestBuildByDigest(app.Name, d.String())
if err != nil {
if err == storage.ErrNotExist {
return BuildStatusOutstanding, nil, nil
}
return -1, nil, errors.Wrap(err, "fetching latest build failed")
}
return BuildStatusExist, build, nil
}