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

improve github asset detection #32

Merged
merged 1 commit into from
Apr 1, 2024
Merged
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
17 changes: 15 additions & 2 deletions lib/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"regexp"
"strings"

"github.com/marwanhawari/stew/constants"
)
Expand Down Expand Up @@ -122,6 +123,17 @@ func assetsFound(releaseAssets []string, releaseTag string) error {
return nil
}

func filterReleaseAssets(assets []string) []string {
var filteredAssets []string
for _, asset := range assets {
if strings.HasSuffix(asset, ".sha256") {
continue
}
filteredAssets = append(filteredAssets, asset)
}
return filteredAssets
}

// DetectAsset will automatically detect a release asset matching your systems OS/arch or prompt you to manually select an asset
func DetectAsset(userOS string, userArch string, releaseAssets []string) (string, error) {
var detectedOSAssets []string
Expand All @@ -139,7 +151,8 @@ func DetectAsset(userOS string, userArch string, releaseAssets []string) (string
return "", err
}

for _, asset := range releaseAssets {
filteredReleaseAssets := filterReleaseAssets(releaseAssets)
for _, asset := range filteredReleaseAssets {
if reOS.MatchString(asset) {
detectedOSAssets = append(detectedOSAssets, asset)
}
Expand Down Expand Up @@ -176,7 +189,7 @@ func DetectAsset(userOS string, userArch string, releaseAssets []string) (string
}
}
if finalAsset == "" {
finalAsset, err = WarningPromptSelect("Could not automatically detect the release asset matching your OS/Arch. Please select it manually:", releaseAssets)
finalAsset, err = WarningPromptSelect("Could not automatically detect the release asset matching your OS/Arch. Please select it manually:", filteredReleaseAssets)
if err != nil {
return "", err
}
Expand Down
Loading