diff --git a/appconfig/appconfig.go b/appconfig/appconfig.go index 271b17c..b4d5460 100755 --- a/appconfig/appconfig.go +++ b/appconfig/appconfig.go @@ -224,7 +224,7 @@ func (c *AppConfig) GetConfigDesc() []string { filterBuilder.WriteString("Filter: ") if len(c.Filter) > 0 { for _, f := range c.Filter { - filterBuilder.WriteString(fmt.Sprintf("\n %s", f)) + fmt.Fprintf(&filterBuilder, "\n %s", f) } } else { filterBuilder.WriteString("None") diff --git a/installer/github_release_installer.go b/installer/github_release_installer.go index e1968f7..69dd729 100755 --- a/installer/github_release_installer.go +++ b/installer/github_release_installer.go @@ -109,9 +109,9 @@ func (i *GitHubReleaseInstaller) Validate() []ValidationError { errors = append(errors, ValidationError{FieldName: "destination", Message: validationIsRequired(), InstallerName: *info.Name}) } } - if opts.DownloadFilename == nil || len(*opts.DownloadFilename.Resolve()) == 0 { + if opts.DownloadFilename == nil { errors = append(errors, ValidationError{FieldName: "download_filename", Message: validationIsRequired(), InstallerName: *info.Name}) - } else if (*opts.DownloadFilename).Resolve() == nil || len(*(*opts.DownloadFilename).Resolve()) == 0 { + } else if info.Platforms.GetShouldRunOnOS(platform.GetPlatform()) && (opts.DownloadFilename.Resolve() == nil || len(*opts.DownloadFilename.Resolve()) == 0) { errors = append(errors, ValidationError{FieldName: fmt.Sprintf("download_filename.%s", platform.GetPlatform()), Message: validationIsRequired(), InstallerName: *info.Name}) } if opts.Strategy != nil { @@ -205,7 +205,7 @@ func (i *GitHubReleaseInstaller) Install() error { filename := i.GetFilename() if filename == "" { - return fmt.Errorf("no download filename provided") + return fmt.Errorf("no download filename matched for the current platform (%s/%s)", runtime.GOOS, runtime.GOARCH) } var machineAliases map[string]string if i.Config.MachineAliases != nil { @@ -778,7 +778,10 @@ func (i *GitHubReleaseInstaller) GetLatestTag() (string, error) { func (i *GitHubReleaseInstaller) GetFilename() string { opts := i.GetOpts() if opts.DownloadFilename != nil { - return *opts.DownloadFilename.Resolve() + resolved := opts.DownloadFilename.Resolve() + if resolved != nil { + return *resolved + } } return "" } diff --git a/installer/github_release_installer_test.go b/installer/github_release_installer_test.go index 05ac138..fafab14 100755 --- a/installer/github_release_installer_test.go +++ b/installer/github_release_installer_test.go @@ -4,6 +4,7 @@ import ( "archive/zip" "bytes" "compress/gzip" + "fmt" "os" "path/filepath" "runtime" @@ -75,7 +76,40 @@ func TestGitHubReleaseValidation(t *testing.T) { }, }, } - assertValidationError(t, newTestGitHubReleaseInstaller(emptyPlatformFilename).Validate(), "download_filename") + assertValidationError(t, newTestGitHubReleaseInstaller(emptyPlatformFilename).Validate(), fmt.Sprintf("download_filename.%s", platform.GetPlatform())) + + // 🟢 download_filename only defined for another platform, but installer is restricted to that platform — should pass + otherPlatform := platform.PlatformLinux + if platform.GetPlatform() == platform.PlatformLinux { + otherPlatform = platform.PlatformMacos + } + otherPlatformOnly := &appconfig.InstallerData{ + Name: lo.ToPtr("ghr-other-platform-only"), + Type: appconfig.InstallerTypeGitHubRelease, + Platforms: &platform.Platforms{Only: &[]platform.Platform{otherPlatform}}, + Opts: &map[string]any{ + "repository": "owner/repo", + "destination": "/some/path", + "download_filename": map[string]*string{ + string(otherPlatform): lo.ToPtr("file.tar.gz"), + }, + }, + } + assertNoValidationErrors(t, newTestGitHubReleaseInstaller(otherPlatformOnly).Validate()) + + // 🔴 download_filename missing for current platform when installer runs on current platform + missingCurrentPlatform := &appconfig.InstallerData{ + Name: lo.ToPtr("ghr-missing-current-platform"), + Type: appconfig.InstallerTypeGitHubRelease, + Opts: &map[string]any{ + "repository": "owner/repo", + "destination": "/some/path", + "download_filename": map[string]*string{ + string(otherPlatform): lo.ToPtr("file.tar.gz"), + }, + }, + } + assertValidationError(t, newTestGitHubReleaseInstaller(missingCurrentPlatform).Validate(), fmt.Sprintf("download_filename.%s", platform.GetPlatform())) // 🔴 Invalid strategy invalidStrategy := &appconfig.InstallerData{