Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use last release tag and branch #467

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 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,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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading