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

[runx] Allow unknown file types #403

Merged
merged 1 commit into from
Oct 25, 2024
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
3 changes: 2 additions & 1 deletion pkg/runx/devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./..."
}
}
}
14 changes: 8 additions & 6 deletions pkg/runx/impl/registry/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/runx/impl/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
1 change: 0 additions & 1 deletion pkg/runx/impl/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")