From f86103dd4a2dc8857c8451735057ba3b28427853 Mon Sep 17 00:00:00 2001 From: divolgin Date: Tue, 29 Oct 2024 13:28:30 -0700 Subject: [PATCH 1/2] Use last release tag and branch --- dagger/release.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/dagger/release.go b/dagger/release.go index 2106694c..28754068 100644 --- a/dagger/release.go +++ b/dagger/release.go @@ -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 } @@ -90,7 +95,8 @@ 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})) _, err = tagContainer.Stdout(ctx) if err != nil { return err @@ -165,9 +171,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. @@ -200,7 +205,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 @@ -222,6 +227,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 { From ccc9c9b1ebbe523045800b5555695c21c7670b53 Mon Sep 17 00:00:00 2001 From: divolgin Date: Tue, 29 Oct 2024 13:40:59 -0700 Subject: [PATCH 2/2] Also fetch tags --- dagger/release.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dagger/release.go b/dagger/release.go index 28754068..61166f3c 100644 --- a/dagger/release.go +++ b/dagger/release.go @@ -96,7 +96,8 @@ func (r *Replicated) Release( 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", "fetch", "dagger", latestReleaseBranchName})) + With(CacheBustingExec([]string{"git", "fetch", "dagger", latestReleaseBranchName})). + With(CacheBustingExec([]string{"git", "fetch", "dagger", "--tags"})) _, err = tagContainer.Stdout(ctx) if err != nil { return err