-
Notifications
You must be signed in to change notification settings - Fork 20
/
bump.go
102 lines (83 loc) · 1.75 KB
/
bump.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
package main
import (
"fmt"
"os"
"strings"
bumper "github.com/giantswarm/semver-bump/bump"
"github.com/giantswarm/semver-bump/storage"
"github.com/urfave/cli"
)
var (
initialVersion = "0.0.1"
)
func bump() cli.Command {
cmd := bumpcmd{}
flags := append([]cli.Flag{}, cmd.flags()...)
return cli.Command{
Name: "bump",
Usage: "bump function version",
Flags: flags,
Action: cmd.bump,
}
}
type bumpcmd struct {
verbose bool
}
func (b *bumpcmd) flags() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: "v",
Usage: "verbose mode",
Destination: &b.verbose,
},
}
}
// bump will take the found valid function and bump its version
func (b *bumpcmd) bump(c *cli.Context) error {
path, err := os.Getwd()
if err != nil {
return err
}
fn, err := findFuncfile(path)
if err != nil {
return err
}
fmt.Println("bumping version for", fn)
funcfile, err := parsefuncfile(fn)
if err != nil {
return err
}
funcfile, err = bumpversion(*funcfile)
if err != nil {
return err
}
if err := storefuncfile(fn, funcfile); err != nil {
return err
}
fmt.Println("Bumped to version", funcfile.Version)
return nil
}
func bumpversion(funcfile funcfile) (*funcfile, error) {
funcfile.Name = cleanImageName(funcfile.Name)
if funcfile.Version == "" {
funcfile.Version = initialVersion
return &funcfile, nil
}
s, err := storage.NewVersionStorage("local", funcfile.Version)
if err != nil {
return nil, err
}
version := bumper.NewSemverBumper(s, "")
newver, err := version.BumpPatchVersion("", "")
if err != nil {
return nil, err
}
funcfile.Version = newver.String()
return &funcfile, nil
}
func cleanImageName(name string) string {
if i := strings.Index(name, ":"); i != -1 {
name = name[:i]
}
return name
}