-
Notifications
You must be signed in to change notification settings - Fork 49
/
auto_version_cmd.go
62 lines (57 loc) 路 1.71 KB
/
auto_version_cmd.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
package app
import (
"io/ioutil"
"net/http"
"os"
"github.com/cashapp/hermit/errors"
"github.com/cashapp/hermit/github"
"github.com/cashapp/hermit/manifest/autoversion"
"github.com/cashapp/hermit/manifest/digest"
"github.com/cashapp/hermit/state"
"github.com/cashapp/hermit/ui"
)
type autoVersionCmd struct {
ContinueOnError bool `help:"Continue on errors."`
UpdateDigests bool `help:"Update digests when auto-versioning."`
Manifest []string `arg:"" type:"existingfile" required:"" help:"Manifests to upgrade." predictor:"hclfile"`
}
func (a *autoVersionCmd) Run(l *ui.UI, hclient *http.Client, state *state.State, client *github.Client) error {
for _, path := range a.Manifest {
l.Debugf("Auto-versioning %s", path)
info, err := os.Stat(path)
if err != nil {
return errors.WithStack(err)
}
original, err := ioutil.ReadFile(path)
if err != nil {
return errors.WithStack(err)
}
err = autoVersionManifest(l, hclient, state, client, path)
if err != nil {
if !a.ContinueOnError {
return errors.Wrap(err, path)
}
l.Warnf("Could not update digests for %q: %s", path, err)
err = ioutil.WriteFile(path, original, info.Mode())
if err != nil {
return errors.Wrapf(err, "could not restore original manifest: %s", path)
}
}
}
return nil
}
func autoVersionManifest(l *ui.UI, hclient *http.Client, state *state.State, client *github.Client, path string) error {
version, err := autoversion.AutoVersion(hclient, client, path)
if err != nil {
return errors.WithStack(err)
}
if version == "" {
return nil
}
l.Infof("Auto-versioned %s to %s", path, version)
err = digest.UpdateDigests(l, hclient, state, path)
if err != nil {
return errors.WithStack(err)
}
return nil
}