Skip to content

Commit

Permalink
feat: --no-download option in find-release-version
Browse files Browse the repository at this point in the history
- This only applies to GitHub and S3 sources, as other sources fetch the
  SHA1 directly instead of downloading and calculating SHA1.

Co-authored-by: claire tinati <[email protected]>
  • Loading branch information
2 people authored and syslxg committed Oct 10, 2022
1 parent 2cb63dc commit b91829f
Show file tree
Hide file tree
Showing 22 changed files with 782 additions and 289 deletions.
23 changes: 11 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ require (
github.com/cloudfoundry/bosh-cli v6.4.1+incompatible
github.com/cloudfoundry/bosh-utils v0.0.0-20210130100352-ab14c90ad9f2
github.com/cucumber/godog v0.12.5
github.com/cucumber/messages-go/v16 v16.0.1
github.com/ghodss/yaml v1.0.0
github.com/go-git/go-billy/v5 v5.3.1
github.com/go-git/go-git/v5 v5.4.2
github.com/google/go-github/v40 v40.0.0
github.com/masterminds/sprig v2.22.0+incompatible
github.com/maxbrunsfeld/counterfeiter/v6 v6.4.1
github.com/onsi/ginkgo v1.15.2
github.com/onsi/gomega v1.11.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.5.0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.18.1
github.com/pivotal-cf-experimental/gomegamatchers v0.0.0-20180326192815-e36bfcc98c3a
github.com/pivotal-cf/go-pivnet/v2 v2.0.11
github.com/pivotal-cf/jhanda v0.0.0-20200619200912-8de8eb943a43
Expand All @@ -42,14 +43,13 @@ require (
github.com/cloudfoundry/socks5-proxy v0.2.0 // indirect
github.com/cppforlife/go-semi-semantic v0.0.0-20160921010311-576b6af77ae4 // indirect
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
Expand Down Expand Up @@ -77,15 +77,14 @@ require (
github.com/shirou/gopsutil v3.21.1+incompatible // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xanzy/ssh-agent v0.3.1 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.25.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
59 changes: 33 additions & 26 deletions go.sum

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions internal/builder/fakes/file_info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions internal/commands/fakes/release_storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/commands/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ stemcell_criteria:
fakeReleaseSources.DownloadReleaseStub = func(s string, lock cargo.ComponentLock) (component.Local, error) {
return releaseSourceList.DownloadRelease(s, lock)
}
fakeReleaseSources.FindReleaseVersionStub = func(requirement component.Spec) (cargo.ComponentLock, error) {
return releaseSourceList.FindReleaseVersion(requirement)
fakeReleaseSources.FindReleaseVersionStub = func(requirement component.Spec, withSHA bool) (cargo.ComponentLock, error) {
return releaseSourceList.FindReleaseVersion(requirement, false)
}
fakeReleaseSources.GetMatchedReleaseStub = func(requirement component.Spec) (cargo.ComponentLock, error) {
return releaseSourceList.GetMatchedRelease(requirement)
Expand Down
5 changes: 3 additions & 2 deletions internal/commands/find_release_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type FindReleaseVersion struct {

Options struct {
flags.Standard
Release string `short:"r" long:"release" description:"release name"`
Release string `short:"r" long:"release" description:"release name"`
NoDownload bool `long:"no-download" description:"do not download any files"`
}
}

Expand Down Expand Up @@ -51,7 +52,7 @@ func (cmd FindReleaseVersion) Execute(args []string) error {
spec.StemcellOS = kilnfileLock.Stemcell.OS
spec.StemcellVersion = kilnfileLock.Stemcell.Version

releaseRemote, err := releaseSource.FindReleaseVersion(spec)
releaseRemote, err := releaseSource.FindReleaseVersion(spec, cmd.Options.NoDownload)
if err != nil {
return err
}
Expand Down
62 changes: 52 additions & 10 deletions internal/commands/find_release_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ stemcell_criteria:
kilnContents := `
---
releases:
- name: uaa
- name: has-constraint
version: ~74.16.0
source: bosh.io
- name: uaac
- name: has-no-constraint
source: bosh.io`

someKilnfilePath = filepath.Join(tmpDir, "Kilnfile")
Expand All @@ -71,10 +71,6 @@ releases:
}
findReleaseVersion = commands.NewFindReleaseVersion(logger, multiReleaseSourceProvider)

fetchExecuteArgs = []string{
"--kilnfile", someKilnfilePath,
"--release", releaseName,
}
logger.Printf("releaseName is: %s", releaseName)
executeErr = findReleaseVersion.Execute(fetchExecuteArgs)
})
Expand All @@ -88,9 +84,15 @@ releases:
})

When("there is no version constraint", func() {
BeforeEach(func() {
releaseName = "has-no-constraint"
fetchExecuteArgs = []string{
"--kilnfile", someKilnfilePath,
"--release", releaseName,
}
})
When("a latest release exists", func() {
BeforeEach(func() {
releaseName = "uaac"
fakeReleasesSource.FindReleaseVersionReturns(component.Lock{
Name: releaseName, Version: "74.12.5",
RemotePath: "remote_url",
Expand All @@ -102,7 +104,7 @@ releases:
When("uaac has releases on bosh.io", func() {
It("returns the latest release version", func() {
Expect(executeErr).NotTo(HaveOccurred())
args := fakeReleasesSource.FindReleaseVersionArgsForCall(0)
args, _ := fakeReleasesSource.FindReleaseVersionArgsForCall(0)
Expect(args.StemcellVersion).To(Equal("4.5.6"))
Expect(args.StemcellOS).To(Equal("some-os"))
Expect(args.Version).To(Equal(""))
Expand All @@ -116,9 +118,15 @@ releases:
})

When("there is a version constraint", func() {
BeforeEach(func() {
releaseName = "has-constraint"
fetchExecuteArgs = []string{
"--kilnfile", someKilnfilePath,
"--release", releaseName,
}
})
When("a release exists", func() {
BeforeEach(func() {
releaseName = "uaa"
fakeReleasesSource.FindReleaseVersionReturns(component.Lock{
Name: releaseName, Version: "74.16.5",
RemotePath: "remote_url",
Expand All @@ -129,7 +137,8 @@ releases:
When("uaa has releases on bosh.io", func() {
It("returns the latest release version", func() {
Expect(executeErr).NotTo(HaveOccurred())
args := fakeReleasesSource.FindReleaseVersionArgsForCall(0)
args, noDownload := fakeReleasesSource.FindReleaseVersionArgsForCall(0)
Expect(noDownload).To(BeFalse())
Expect(args.Version).To(Equal("~74.16.0"))
Expect(args.StemcellVersion).To(Equal("4.5.6"))
Expect(args.StemcellOS).To(Equal("some-os"))
Expand All @@ -139,5 +148,38 @@ releases:
})
})
})

When("--no-download is specified", func() {
BeforeEach(func() {
releaseName = "has-no-constraint"
fetchExecuteArgs = []string{
"--kilnfile", someKilnfilePath,
"--release", releaseName,
"--no-download",
}
})

It("calls source with correct args", func() {
Expect(executeErr).NotTo(HaveOccurred())
_, noDownload := fakeReleasesSource.FindReleaseVersionArgsForCall(0)
Expect(noDownload).To(BeTrue())
})
})

When("--no-download is not specified", func() {
BeforeEach(func() {
releaseName = "has-no-constraint"
fetchExecuteArgs = []string{
"--kilnfile", someKilnfilePath,
"--release", releaseName,
}
})

It("calls source with correct args", func() {
Expect(executeErr).NotTo(HaveOccurred())
_, noDownload := fakeReleasesSource.FindReleaseVersionArgsForCall(0)
Expect(noDownload).To(BeFalse())
})
})
})
})
2 changes: 1 addition & 1 deletion internal/commands/update_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (u UpdateRelease) Execute(args []string) error {
StemcellVersion: kilnfileLock.Stemcell.Version,
StemcellOS: kilnfileLock.Stemcell.OS,
GitHubRepository: releaseSpec.GitHubRepository,
})
}, false)

if err != nil {
if component.IsErrNotFound(err) {
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/update_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ var _ = Describe("UpdateRelease", func() {
})
Expect(err).NotTo(HaveOccurred())

receivedReleaseRequirement := releaseSource.FindReleaseVersionArgsForCall(0)
receivedReleaseRequirement, _ := releaseSource.FindReleaseVersionArgsForCall(0)
releaseRequirement := component.Spec{
Name: releaseName,
Version: newReleaseVersion,
Expand Down
2 changes: 1 addition & 1 deletion internal/component/artifactory_release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (ars ArtifactoryReleaseSource) GetMatchedRelease(spec Spec) (Lock, error) {

// FindReleaseVersion may use any of the fields on Requirement to return the best matching
// release.
func (ars ArtifactoryReleaseSource) FindReleaseVersion(spec Spec) (Lock, error) {
func (ars ArtifactoryReleaseSource) FindReleaseVersion(spec Spec, _ bool) (Lock, error) {
remotePath, err := ars.RemotePath(spec)
if err != nil {
return Lock{}, err
Expand Down
2 changes: 1 addition & 1 deletion internal/component/bosh_io_release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (src BOSHIOReleaseSource) GetMatchedRelease(requirement Spec) (Lock, error)
return Lock{}, ErrNotFound
}

func (src BOSHIOReleaseSource) FindReleaseVersion(spec Spec) (Lock, error) {
func (src BOSHIOReleaseSource) FindReleaseVersion(spec Spec, _ bool) (Lock, error) {
spec = spec.UnsetStemcell()

constraint, err := spec.VersionConstraints()
Expand Down
6 changes: 3 additions & 3 deletions internal/component/bosh_io_release_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ var _ = Describe("BOSHIOReleaseSource", func() {
It("gets the latest version from bosh.io", func() {
rabbitmqRequirement := component.Spec{Name: "cf-rabbitmq"}

foundRelease, err := releaseSource.FindReleaseVersion(rabbitmqRequirement)
foundRelease, err := releaseSource.FindReleaseVersion(rabbitmqRequirement, false)
Expect(err).NotTo(HaveOccurred())
cfRabbitURL := fmt.Sprintf("%s/d/github.com/cloudfoundry/cf-rabbitmq-release?v=309.0.5", testServer.URL())
Expect(foundRelease).To(Equal(component.Lock{
Expand All @@ -327,7 +327,7 @@ var _ = Describe("BOSHIOReleaseSource", func() {
It("gets the latest version from bosh.io", func() {
rabbitmqRequirement := component.Spec{Name: "cf-rabbitmq", Version: "~309"}

foundRelease, err := releaseSource.FindReleaseVersion(rabbitmqRequirement)
foundRelease, err := releaseSource.FindReleaseVersion(rabbitmqRequirement, false)
Expect(err).NotTo(HaveOccurred())
cfRabbitURL := fmt.Sprintf("%s/d/github.com/cloudfoundry/cf-rabbitmq-release?v=309.0.5", testServer.URL())
Expect(foundRelease).To(Equal(component.Lock{
Expand Down Expand Up @@ -358,7 +358,7 @@ var _ = Describe("BOSHIOReleaseSource", func() {
It("returns not found", func() {
rabbitmqRequirement := component.Spec{Name: "cf-rabbitmq"}

foundRelease, err := releaseSource.FindReleaseVersion(rabbitmqRequirement)
foundRelease, err := releaseSource.FindReleaseVersion(rabbitmqRequirement, false)
Expect(err).To(HaveOccurred())
Expect(component.IsErrNotFound(err)).To(BeTrue())
Expect(foundRelease).To(Equal(component.Lock{}))
Expand Down
Loading

0 comments on commit b91829f

Please sign in to comment.