Skip to content

Commit

Permalink
Use branches to make releases (#465)
Browse files Browse the repository at this point in the history
* Use branches to make releases

* Change remote name from tag to dagger
  • Loading branch information
divolgin authored Oct 29, 2024
1 parent 0ca15fb commit 93fe3e9
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions dagger/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func (r *Replicated) Release(
buildFileContent = strings.ReplaceAll(buildFileContent, "const version = \"unknown\"", fmt.Sprintf("const version = \"%d.%d.%d\"", major, minor, patch))
updatedSource := source.WithNewFile("./pkg/version/build.go", buildFileContent)

releaseBranchName := fmt.Sprintf("release-%d.%d.%d", major, minor, patch)
githubTokenPlaintext, err := githubToken.Plaintext(ctx)
if err != nil {
return err
}

// mount that and commit the updated build.go to git (don't push)
// so that goreleaser won't have a dirty git tree error
gitCommitContainer := dag.Container().
Expand All @@ -68,25 +74,23 @@ func (r *Replicated) Release(
WithWorkdir("/go/src/github.com/replicatedhq/replicated").
WithExec([]string{"git", "config", "user.email", "[email protected]"}).
WithExec([]string{"git", "config", "user.name", "Replicated Release Pipeline"}).
WithExec([]string{"git", "remote", "add", "dagger", fmt.Sprintf("https://%[email protected]/replicatedhq/replicated.git", githubTokenPlaintext)}).
WithExec([]string{"git", "checkout", "-b", releaseBranchName}).
WithExec([]string{"git", "add", "pkg/version/build.go"}).
WithExec([]string{"git", "commit", "-m", fmt.Sprintf("Set version to %d.%d.%d", major, minor, patch)})
WithExec([]string{"git", "commit", "-m", fmt.Sprintf("Set version to %d.%d.%d", major, minor, patch)}).
WithExec([]string{"git", "push", "dagger", releaseBranchName}).
_, err = gitCommitContainer.Stdout(ctx)
if err != nil {
return err
}
updatedSource = gitCommitContainer.Directory("/go/src/github.com/replicatedhq/replicated")

githubTokenPlaintext, err := githubToken.Plaintext(ctx)
if err != nil {
return err
}
tagContainer := dag.Container().
From("alpine/git:latest").
WithMountedDirectory("/go/src/github.com/replicatedhq/replicated", updatedSource).
WithWorkdir("/go/src/github.com/replicatedhq/replicated").
WithExec([]string{"git", "remote", "add", "tag", fmt.Sprintf("https://%[email protected]/replicatedhq/replicated.git", githubTokenPlaintext)}).
With(CacheBustingExec([]string{"git", "tag", fmt.Sprintf("v%d.%d.%d", major, minor, patch)})).
With(CacheBustingExec([]string{"git", "push", "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)}))
_, err = tagContainer.Stdout(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -161,8 +165,9 @@ func (r *Replicated) Release(
goreleaserContainer := dag.Goreleaser(dagger.GoreleaserOpts{
Version: goreleaserVersion,
}).Ctr().
WithSecretVariable("GITHUB_TOKEN", githubToken).
WithEnvVariable("GORELEASER_CURRENT_TAG", latestVersion)
WithSecretVariable("GITHUB_TOKEN", githubToken)
// TODO: add back after next release
// WithEnvVariable("GORELEASER_CURRENT_TAG", latestVersion)

if snapshot {
_, err := dag.
Expand Down

0 comments on commit 93fe3e9

Please sign in to comment.