Skip to content

Commit

Permalink
Add option to update releases along with stemcell
Browse files Browse the repository at this point in the history
  • Loading branch information
dlinsley committed Nov 26, 2024
1 parent 5bb3031 commit ff03087
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
16 changes: 12 additions & 4 deletions internal/commands/update_stemcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import (

"github.com/pivotal-cf/kiln/internal/commands/flags"
"github.com/pivotal-cf/kiln/internal/component"
"github.com/pivotal-cf/kiln/pkg/cargo"
)

type UpdateStemcell struct {
Options struct {
flags.Standard

Version string `short:"v" long:"version" required:"true" description:"desired version of stemcell"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
Version string `short:"v" long:"version" required:"true" description:"desired version of stemcell"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
UpdateReleases bool `long:"update-releases" default:"false" description:"finds latest matching releases for new stemcell version"`
}
FS billy.Filesystem
MultiReleaseSourceProvider MultiReleaseSourceProvider
Expand Down Expand Up @@ -75,9 +77,15 @@ func (update UpdateStemcell) Execute(args []string) error {
}
spec.StemcellOS = kilnfileLock.Stemcell.OS
spec.StemcellVersion = trimmedInputVersion
spec.Version = rel.Version

remote, err := releaseSource.GetMatchedRelease(spec)
var remote cargo.BOSHReleaseTarballLock
if update.Options.UpdateReleases {
remote, err = releaseSource.FindReleaseVersion(spec, true)
} else {
spec.Version = rel.Version
remote, err = releaseSource.GetMatchedRelease(spec)
}

if err != nil {
return fmt.Errorf("while finding release %q, encountered error: %w", rel.Name, err)
}
Expand Down
52 changes: 49 additions & 3 deletions internal/commands/update_stemcell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ var _ = Describe("UpdateStemcell", func() {
Version: "^1",
},
Releases: []cargo.BOSHReleaseTarballSpecification{
{Name: release1Name, GitHubRepository: "https://example.com/lemon"},
{Name: release2Name, GitHubRepository: "https://example.com/orange"},
{Name: release1Name, GitHubRepository: "https://example.com/lemon", Version: "*"},
{Name: release2Name, GitHubRepository: "https://example.com/orange", Version: "*"},
},
}
kilnfileLock = cargo.KilnfileLock{
Expand Down Expand Up @@ -115,6 +115,27 @@ var _ = Describe("UpdateStemcell", func() {
}
})

releaseSource.FindReleaseVersionCalls(func(requirement cargo.BOSHReleaseTarballSpecification, download bool) (cargo.BOSHReleaseTarballLock, error) {
switch requirement.Name {
case release1Name:
remote := cargo.BOSHReleaseTarballLock{
Name: release1Name, Version: release1Version,
RemotePath: newRelease1RemotePath,
RemoteSource: publishableReleaseSourceID,
}
return remote, nil
case release2Name:
remote := cargo.BOSHReleaseTarballLock{
Name: release2Name, Version: release2Version,
RemotePath: newRelease2RemotePath,
RemoteSource: unpublishableReleaseSourceID,
}
return remote, nil
default:
panic("unexpected release name")
}
})

releaseSource.DownloadReleaseCalls(func(_ string, remote cargo.BOSHReleaseTarballLock) (component.Local, error) {
switch remote.Name {
case release1Name:
Expand All @@ -130,7 +151,7 @@ var _ = Describe("UpdateStemcell", func() {
}
return local, nil
default:
panic("unexpected release name")
panic("unexpected release name '"+remote.Name +"'")
}
})

Expand Down Expand Up @@ -214,6 +235,31 @@ var _ = Describe("UpdateStemcell", func() {
GitHubRepository: "https://example.com/orange",
}))
})
It("looks up the correct releases with -ffr", func() {
err := update.Execute([]string{
"--kilnfile", kilnfilePath, "--version", "1.100", "--releases-directory", releasesDirPath, "--update-releases", "true",
})
Expect(err).NotTo(HaveOccurred())

Expect(releaseSource.FindReleaseVersionCallCount()).To(Equal(2))

req1, noDownload1 := releaseSource.FindReleaseVersionArgsForCall(0)
Expect(req1).To(Equal(cargo.BOSHReleaseTarballSpecification{
Name: release1Name, Version: "*",
StemcellOS: newStemcellOS, StemcellVersion: newStemcellVersion,
GitHubRepository: "https://example.com/lemon",
}))
Expect(noDownload1).To(BeTrue())

req2, noDownload2 := releaseSource.FindReleaseVersionArgsForCall(1)
Expect(req2).To(Equal(cargo.BOSHReleaseTarballSpecification{
Name: release2Name, Version: "*",
StemcellOS: newStemcellOS, StemcellVersion: newStemcellVersion,
GitHubRepository: "https://example.com/orange",
}))
Expect(noDownload2).To(BeTrue())
})


It("downloads the correct releases", func() {
err := update.Execute([]string{
Expand Down

0 comments on commit ff03087

Please sign in to comment.