forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_release.go
105 lines (83 loc) · 2.2 KB
/
create_release.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
package cmd
import (
semver "github.com/cppforlife/go-semi-semantic/version"
boshrel "github.com/cloudfoundry/bosh-cli/release"
boshreldir "github.com/cloudfoundry/bosh-cli/releasedir"
boshui "github.com/cloudfoundry/bosh-cli/ui"
)
type CreateReleaseCmd struct {
releaseManifestReader boshrel.Reader
releaseDir boshreldir.ReleaseDir
ui boshui.UI
}
func NewCreateReleaseCmd(
releaseManifestReader boshrel.Reader,
releaseDir boshreldir.ReleaseDir,
ui boshui.UI,
) CreateReleaseCmd {
return CreateReleaseCmd{
releaseManifestReader: releaseManifestReader,
releaseDir: releaseDir,
ui: ui,
}
}
func (c CreateReleaseCmd) Run(opts CreateReleaseOpts) error {
var release boshrel.Release
var err error
manifestGiven := len(opts.Args.Manifest.Path) > 0
if manifestGiven {
release, err = c.releaseManifestReader.Read(opts.Args.Manifest.Path)
if err != nil {
return err
}
} else {
release, err = c.buildRelease(opts)
if err != nil {
return err
}
if opts.Final {
err = c.finalizeRelease(opts, release)
if err != nil {
return err
}
}
}
var archivePath string
if manifestGiven || opts.Tarball {
archivePath, err = c.releaseDir.BuildReleaseArchive(release)
if err != nil {
return err
}
}
ReleaseTables{Release: release, ArchivePath: archivePath}.Print(c.ui)
return nil
}
func (c CreateReleaseCmd) buildRelease(opts CreateReleaseOpts) (boshrel.Release, error) {
var err error
name := opts.Name
if len(name) == 0 {
name, err = c.releaseDir.DefaultName()
if err != nil {
return nil, err
}
}
version := semver.Version(opts.Version)
if version.Empty() {
version, err = c.releaseDir.NextDevVersion(name, opts.TimestampVersion)
if err != nil {
return nil, err
}
}
return c.releaseDir.BuildRelease(name, version, opts.Force)
}
func (c CreateReleaseCmd) finalizeRelease(opts CreateReleaseOpts, release boshrel.Release) error {
version := semver.Version(opts.Version)
if version.Empty() {
version, err := c.releaseDir.NextFinalVersion(release.Name())
if err != nil {
return err
}
release.SetVersion(version.AsString())
}
return c.releaseDir.FinalizeRelease(release, opts.Force)
}