Skip to content

Commit

Permalink
improve github asset detection (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanhawari authored Apr 1, 2024
1 parent dc0a3c7 commit b86e6a3
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit b86e6a3

Please sign in to comment.