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

uniform versioning with/without release assets #8

Merged
merged 2 commits into from
Mar 30, 2022
Merged
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
10 changes: 6 additions & 4 deletions remote_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/ForestEckhardt/freezer/github"
"github.com/paketo-buildpacks/packit/v2/vacation"
Expand Down Expand Up @@ -79,8 +80,9 @@ func (r RemoteFetcher) Get(buildpack RemoteBuildpack) (string, error) {
}

path := cachedEntry.URI
tagName := strings.TrimPrefix(release.TagName, "v")

if release.TagName != cachedEntry.Version || !exist {
if tagName != cachedEntry.Version || !exist {
missingReleaseArtifacts := !(len(release.Assets) > 0)
var bundle io.ReadCloser
if missingReleaseArtifacts || buildpack.Offline {
Expand All @@ -95,7 +97,7 @@ func (r RemoteFetcher) Get(buildpack RemoteBuildpack) (string, error) {
}
}

path = filepath.Join(buildpackCacheDir, fmt.Sprintf("%s.tgz", release.TagName))
path = filepath.Join(buildpackCacheDir, fmt.Sprintf("%s.tgz", tagName))

if missingReleaseArtifacts || buildpack.Offline {
downloadDir, err := r.fileSystem.TempDir("", buildpack.Repo)
Expand All @@ -109,7 +111,7 @@ func (r RemoteFetcher) Get(buildpack RemoteBuildpack) (string, error) {
return "", err
}

err = r.packager.Execute(downloadDir, path, release.TagName, buildpack.Offline)
err = r.packager.Execute(downloadDir, path, tagName, buildpack.Offline)
if err != nil {
return "", err
}
Expand All @@ -128,7 +130,7 @@ func (r RemoteFetcher) Get(buildpack RemoteBuildpack) (string, error) {
}

err = r.buildpackCache.Set(key, CacheEntry{
Version: release.TagName,
Version: tagName,
URI: path,
})

Expand Down
49 changes: 49 additions & 0 deletions remote_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,55 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) {
})
})

context("when there is a v prepending the release tag", func() {
it.Before(func() {
gitReleaseFetcher.GetCall.Returns.Release = github.Release{
TagName: "v1.2.3",
Assets: []github.ReleaseAsset{
{
URL: "some-url",
},
},
TarballURL: "some-tarball-url",
}

buildpackCache.GetCall.Returns.CacheEntry = freezer.CacheEntry{
Version: "some-other-tag",
}

Expect(os.MkdirAll(filepath.Join(cacheDir, "some-org", "some-repo"), os.ModePerm)).To(Succeed())
})

it("removes the v from the tag", func() {
uri, err := remoteFetcher.Get(remoteBuildpack)
Expect(err).ToNot(HaveOccurred())

Expect(gitReleaseFetcher.GetCall.Receives.Org).To(Equal("some-org"))
Expect(gitReleaseFetcher.GetCall.Receives.Repo).To(Equal("some-repo"))

Expect(buildpackCache.GetCall.Receives.Key).To(Equal("some-org:some-repo"))

Expect(gitReleaseFetcher.GetReleaseAssetCall.Receives.Asset).To(Equal(github.ReleaseAsset{
URL: "some-url",
}))

Expect(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz")).To(BeAnExistingFile())
file, err := os.Open(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz"))
Expect(err).ToNot(HaveOccurred())

err = vacation.NewArchive(file).Decompress(filepath.Join(cacheDir, "some-org", "some-repo"))
Expect(err).ToNot(HaveOccurred())

content, err := os.ReadFile(filepath.Join(cacheDir, "some-org", "some-repo", "some-file"))
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(Equal("some content"))

Expect(buildpackCache.SetCall.CallCount).To(Equal(1))

Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz")))
})
})

context("failure cases", func() {
context("when there is a failure in the gitReleaseFetcher get", func() {
it.Before(func() {
Expand Down