Skip to content

Commit

Permalink
fix: corectly build URLs for github releases
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Aug 3, 2024
1 parent 32230db commit e183eb1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion entity/githubrelease.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package entity

type GithubRelease struct {
Release `yaml:",inline"`
ExecName string `yaml:"exec-name"`
Release `yaml:",inline"`
}
2 changes: 1 addition & 1 deletion provision/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (p Provisioner) ensureReleases() error {
return errors.New("empty release directory")
}

return ensureReleases(p.Config.Releases, p.Config.GithubReleases, p.Config.Settings)
return ensureReleases(p.Config)
}

func (p Provisioner) runPreflightTasks() error {
Expand Down
24 changes: 15 additions & 9 deletions provision/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,14 +736,19 @@ func processGithubReleases(githubReleases []entity.GithubRelease) ([]entity.Rele
return releases, fmt.Errorf("no ref specified for GitHub release: %+v", githubRelease)
}

refTokens := strings.Split(githubRelease.Ref, "/")
if len(refTokens) != 2 {
return releases, fmt.Errorf("unexpected release name %s", githubRelease.Ref)
}
ref := refTokens[1]
releaseUrl := fmt.Sprintf("https://github.com/%s/releases/download/%s", githubRelease.Ref,
githubRef := githubRelease.Ref
releaseUrl := fmt.Sprintf("https://github.com/%s/releases/download/%s", githubRef,
githubRelease.Url)

ref := githubRelease.ExecName
if ref == "" {
refTokens := strings.Split(githubRef, "/")
if len(refTokens) != 2 {
return releases, fmt.Errorf("unexpected release name %s", githubRef)
}
ref = refTokens[1]
}

release := entity.Release{
Cleanup: githubRelease.Cleanup,
DontLink: githubRelease.DontLink,
Expand All @@ -766,18 +771,19 @@ func processGithubReleases(githubReleases []entity.GithubRelease) ([]entity.Rele
return releases, nil
}

func ensureReleases(releases []entity.Release, githubReleases []entity.GithubRelease, s settings.Settings) error {
func ensureReleases(config entity.Config) error {
var releaseErrs []error

processedReleases, err := processGithubReleases(githubReleases)
releases := config.Releases
processedReleases, err := processGithubReleases(config.GithubReleases)
if err == nil {
releases = append(releases, processedReleases...)
} else {
releaseErrs = append(releaseErrs, err)
}

for _, release := range releases {
err = ensureRelease(release, s)
err = ensureRelease(release, config.Settings)
if err != nil {
internal.Log.Errorf("Error ensuring release %s: %v", release.Name(), err)
}
Expand Down

0 comments on commit e183eb1

Please sign in to comment.