diff --git a/pkg/runx/devbox.json b/pkg/runx/devbox.json index abfecc7..6296b29 100644 --- a/pkg/runx/devbox.json +++ b/pkg/runx/devbox.json @@ -5,7 +5,8 @@ "shell": { "scripts": { "build": "go build -o dist/runx cmd/runx/main.go", - "build-pkg": "go build -o dist/pkg cmd/pkg/main.go" + "build-pkg": "go build -o dist/pkg cmd/pkg/main.go", + "test": "go test ./..." } } } diff --git a/pkg/runx/impl/registry/artifact.go b/pkg/runx/impl/registry/artifact.go index a0178b4..90025fe 100644 --- a/pkg/runx/impl/registry/artifact.go +++ b/pkg/runx/impl/registry/artifact.go @@ -8,23 +8,25 @@ import ( ) func findArtifactForPlatform(artifacts []types.ArtifactMetadata, platform types.Platform) (types.ArtifactMetadata, error) { - foundPlatform := false + var artifactForPlatform types.ArtifactMetadata for _, artifact := range artifacts { if isArtifactForPlatform(artifact.Name, platform) { - foundPlatform = true + artifactForPlatform = artifact if isKnownArchive(artifact.Name) { - // We only consider known archives because sometimes releases contain multiple files + // We prefer known archives because sometimes releases contain multiple files // for the same platform. Some times those files are alternative installation methods // like `.dmg`, `.msi`, or `.deb`, and sometimes they are metadata files like `.sha256` // or a `.sig` file. We don't want to install those. + // If no known archive is found, but the platform is supported, we return the last artifact + // with a matching platform. This is useful when releases don't have extensions. return artifact, nil } } } - if !foundPlatform { - return types.ArtifactMetadata{}, types.ErrPlatformNotSupported + if artifactForPlatform.Name != "" { + return artifactForPlatform, nil } - return types.ArtifactMetadata{}, types.ErrNoKnownArchive + return types.ArtifactMetadata{}, types.ErrPlatformNotSupported } func isArtifactForPlatform(artifactName string, platform types.Platform) bool { diff --git a/pkg/runx/impl/registry/registry_test.go b/pkg/runx/impl/registry/registry_test.go index aa142b9..91fd887 100644 --- a/pkg/runx/impl/registry/registry_test.go +++ b/pkg/runx/impl/registry/registry_test.go @@ -98,8 +98,8 @@ func TestFindArtifactForPlatform(t *testing.T) { errTypeWant error }{ {[]types.ArtifactMetadata{{Name: "mac-amd64.tar.gz"}}, types.NewPlatform("darwin", "amd64"), true, nil}, - {[]types.ArtifactMetadata{{Name: "linux-amd64.deb"}}, types.NewPlatform("linux", "amd64"), false, types.ErrNoKnownArchive}, - {[]types.ArtifactMetadata{{Name: "linux-amd64"}}, types.NewPlatform("linux", "amd64"), false, types.ErrNoKnownArchive}, + {[]types.ArtifactMetadata{{Name: "linux-amd64.deb"}}, types.NewPlatform("linux", "amd64"), true, nil}, + {[]types.ArtifactMetadata{{Name: "linux-amd64"}}, types.NewPlatform("linux", "amd64"), true, nil}, {[]types.ArtifactMetadata{{Name: "darwin_arm64.tar"}}, types.NewPlatform("windows", "amd64"), false, types.ErrPlatformNotSupported}, {[]types.ArtifactMetadata{{Name: "darwin_arm64"}}, types.NewPlatform("windows", "amd64"), false, types.ErrPlatformNotSupported}, {[]types.ArtifactMetadata{{Name: "mac-amd64.tar.gz"}}, types.NewPlatform("", ""), false, types.ErrPlatformNotSupported}, diff --git a/pkg/runx/impl/types/errors.go b/pkg/runx/impl/types/errors.go index e226819..ab73383 100644 --- a/pkg/runx/impl/types/errors.go +++ b/pkg/runx/impl/types/errors.go @@ -5,4 +5,3 @@ import "errors" var ErrPackageNotFound = errors.New("package not found") var ErrReleaseNotFound = errors.New("release not found") var ErrPlatformNotSupported = errors.New("package doesn't support platform") -var ErrNoKnownArchive = errors.New("package doesn't come in a known archive")