Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to update releases while updating stemcell #513

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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