From 9bf11b382c0b360bfc1e1f0ea71ce389e9604133 Mon Sep 17 00:00:00 2001 From: Simon Ermler Date: Mon, 20 Jan 2025 20:39:11 +0100 Subject: [PATCH 1/3] Add support for alternate package-id --- runner/runners.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/runner/runners.go b/runner/runners.go index b35b71e..1730da3 100644 --- a/runner/runners.go +++ b/runner/runners.go @@ -253,11 +253,15 @@ func ParseWorkspaceMember(workspaceMember string) (string, string, string, error } otherHalf := strings.SplitN(half[1], "@", 2) - if len(otherHalf) != 2 { - return "", "", "", fmt.Errorf("unable to parse workspace member [%s], missing `@`", workspaceMember) + if len(otherHalf) == 2 { + return strings.TrimSpace(otherHalf[0]), strings.TrimSpace(otherHalf[1]), strings.TrimSpace(half[0]), nil + } else { + splitIndex := strings.LastIndex(half[0], "/") + path := half[0][:splitIndex] + pkgName := half[0][splitIndex+1:] + return strings.TrimSpace(pkgName), strings.TrimSpace(half[1]), strings.TrimSpace(path), nil } - return strings.TrimSpace(otherHalf[0]), strings.TrimSpace(otherHalf[1]), strings.TrimSpace(half[0]), nil } else { // This is OK because the workspace member format is `package-name package-version (url)` and // none of name, version or URL may contain a space & be valid From bbfaf038235a0fb6efb9d563fc15ce07d7bbc703 Mon Sep 17 00:00:00 2001 From: Simon Ermler Date: Mon, 20 Jan 2025 20:39:18 +0100 Subject: [PATCH 2/3] Update tests --- runner/runners_test.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/runner/runners_test.go b/runner/runners_test.go index 60ae2f8..76934bd 100644 --- a/runner/runners_test.go +++ b/runner/runners_test.go @@ -471,6 +471,7 @@ func testRunners(t *testing.T, context spec.G, it spec.S) { "path+file:///workspace/todo#todo@1.2.0", "path+file:///workspace/routes#routes@0.5.0", "path+file:///workspace/jokes#jokes@1.5.6", + "path+file:///workspace/other-format/other-format#1.0.0", }) executor.On("Execute", mock.MatchedBy(func(ex effect.Execution) bool { @@ -490,7 +491,7 @@ func testRunners(t *testing.T, context spec.G, it spec.S) { urls, err := runner.WorkspaceMembers(workingDir, destLayer) Expect(err).ToNot(HaveOccurred()) - Expect(urls).To(HaveLen(4)) + Expect(urls).To(HaveLen(5)) url, err := url.Parse("path+file:///workspace/basics") Expect(err).ToNot(HaveOccurred()) @@ -507,6 +508,10 @@ func testRunners(t *testing.T, context spec.G, it spec.S) { url, err = url.Parse("path+file:///workspace/jokes") Expect(err).ToNot(HaveOccurred()) Expect(urls[3]).To(Equal(*url)) + + url, err = url.Parse("path+file:///workspace/other-format") + Expect(err).ToNot(HaveOccurred()) + Expect(urls[4]).To(Equal(*url)) }) }) @@ -830,16 +835,17 @@ func testRunners(t *testing.T, context spec.G, it spec.S) { Expect(version).To(Equal("2.0.0")) Expect(url).To(Equal("path+file:///workspace/basics")) }) - + it("parses alternative package-id", func() { + pkgName, version, url, err := runner.ParseWorkspaceMember("path+file:///workspace/basics/basics#2.0.0") + Expect(err).ToNot(HaveOccurred()) + Expect(pkgName).To(Equal("basics")) + Expect(version).To(Equal("2.0.0")) + Expect(url).To(Equal("path+file:///workspace/basics")) + }) it("fails to parse because there is no hash sign", func() { _, _, _, err := runner.ParseWorkspaceMember("path+file:///workspace/basics") Expect(err).To(MatchError("unable to parse workspace member [path+file:///workspace/basics], missing `#`")) }) - - it("fails to parse because there is no at sign", func() { - _, _, _, err := runner.ParseWorkspaceMember("path+file:///workspace/basics#foo") - Expect(err).To(MatchError("unable to parse workspace member [path+file:///workspace/basics#foo], missing `@`")) - }) }) }) } From 5d3cc1063040e6e2bbaa4c3ea9fc3c7c37a2e9e0 Mon Sep 17 00:00:00 2001 From: Simon Ermler Date: Tue, 21 Jan 2025 22:49:27 +0100 Subject: [PATCH 3/3] Add description for alternative package-id in comment --- runner/runners.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runner/runners.go b/runner/runners.go index 1730da3..eff6297 100644 --- a/runner/runners.go +++ b/runner/runners.go @@ -241,9 +241,12 @@ func (c CargoRunner) WorkspaceMembers(srcDir string, destLayer libcnb.Layer) ([] // parseWorkspaceMember parses a workspace member which can be in a couple of different formats // -// pre-1.77: `package-name package-version (url)`, like `function 0.1.0 (path+file:///Users/dmikusa/Downloads/fn-rs)` -// 1.77+: `url#package-name@package-version` like `path+file:///Users/dmikusa/Downloads/fn-rs#function@0.1.0` +// pre-1.77: `package-name package-version (url)`, like `function 0.1.0 (path+file:///Users/dmikusa/Downloads/fn-rs)` +// 1.77+: +// - `url#package-name@package-version` like `path+file:///Users/dmikusa/Downloads/fn-rs#function@0.1.0` +// - `url#version` for local packages where the workspace member name is equal to the directory name like `path+file:///Users/jondoe/.../services/example-transform#0.1.0` // +// The final directory is assumed to be the package name with the local package format. // returns the package name, version, URL, and optional error in that order func ParseWorkspaceMember(workspaceMember string) (string, string, string, error) { if strings.HasPrefix(workspaceMember, "path+file://") {