Skip to content

Commit

Permalink
Use last release tag and branch (#467)
Browse files Browse the repository at this point in the history
* Use last release tag and branch

* Also fetch tags
  • Loading branch information
divolgin authored Oct 29, 2024
1 parent 475a8e6 commit bde6660
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions dagger/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ func (r *Replicated) Release(
return err
}

major, minor, patch, err := parseVersion(ctx, latestVersion, version)
latestReleaseBranchName, err := getReleaseBranchName(ctx, latestVersion)
if err != nil {
return err
}

major, minor, patch, err := getNextVersion(ctx, latestVersion, version)
if err != nil {
return err
}
Expand Down Expand Up @@ -90,7 +95,9 @@ func (r *Replicated) Release(
WithMountedDirectory("/go/src/github.com/replicatedhq/replicated", updatedSource).
WithWorkdir("/go/src/github.com/replicatedhq/replicated").
With(CacheBustingExec([]string{"git", "tag", fmt.Sprintf("v%d.%d.%d", major, minor, patch)})).
With(CacheBustingExec([]string{"git", "push", "dagger", fmt.Sprintf("v%d.%d.%d", major, minor, patch)}))
With(CacheBustingExec([]string{"git", "push", "dagger", fmt.Sprintf("v%d.%d.%d", major, minor, patch)})).
With(CacheBustingExec([]string{"git", "fetch", "dagger", latestReleaseBranchName})).
With(CacheBustingExec([]string{"git", "fetch", "dagger", "--tags"}))
_, err = tagContainer.Stdout(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -165,9 +172,8 @@ func (r *Replicated) Release(
goreleaserContainer := dag.Goreleaser(dagger.GoreleaserOpts{
Version: goreleaserVersion,
}).Ctr().
WithSecretVariable("GITHUB_TOKEN", githubToken)
// TODO: add back after next release
// WithEnvVariable("GORELEASER_CURRENT_TAG", latestVersion)
WithSecretVariable("GITHUB_TOKEN", githubToken).
WithEnvVariable("GORELEASER_CURRENT_TAG", latestVersion)

if snapshot {
_, err := dag.
Expand Down Expand Up @@ -200,7 +206,7 @@ func (r *Replicated) Release(
return nil
}

func parseVersion(ctx context.Context, latestVersion string, version string) (int64, int64, int64, error) {
func getNextVersion(ctx context.Context, latestVersion string, version string) (int64, int64, int64, error) {
parsedLatestVersion, err := semver.NewVersion(latestVersion)
if err != nil {
return 0, 0, 0, err
Expand All @@ -222,6 +228,15 @@ func parseVersion(ctx context.Context, latestVersion string, version string) (in
}
}

func getReleaseBranchName(ctx context.Context, latestVersion string) (string, error) {
parsedLatestVersion, err := semver.NewVersion(latestVersion)
if err != nil {
return "", err
}

return fmt.Sprintf("release-%d.%d.%d", parsedLatestVersion.Major(), parsedLatestVersion.Minor(), parsedLatestVersion.Patch()), nil
}

func getLatestVersion(ctx context.Context) (string, error) {
resp, err := http.DefaultClient.Get("https://api.github.com/repos/replicatedhq/replicated/releases/latest")
if err != nil {
Expand Down

0 comments on commit bde6660

Please sign in to comment.