feat(releaser): write release.env dotenv artifact on every release
ci / vet, staticcheck, test, build (push) Successful in 3m9s

After the next version is determined and dry-run is confirmed off,
release.env is written to the repository root:

  NEXT_VERSION=<nextTag>

This file is not committed — it is left as an untracked artifact so
GitLab CI can expose it as a dotenv artifact and pass NEXT_VERSION to
downstream jobs (e.g. deploy, notify).

The file is skipped in --dry-run mode. Two tests added:
TestRunReleaseEnv and TestRunReleaseEnvDryRun.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 13:54:38 +02:00
parent 12cb3a71af
commit 2614f23856
2 changed files with 48 additions and 0 deletions
+7
View File
@@ -387,6 +387,13 @@ func run(o options) error {
return nil
}
// --- release.env (GitLab CI dotenv artifact) ---
releaseEnvPath := filepath.Join(absRepo, "release.env")
if err := os.WriteFile(releaseEnvPath, []byte("NEXT_VERSION="+nextTag+"\n"), 0644); err != nil {
return fmt.Errorf("write release.env: %w", err)
}
logDone("release.env: NEXT_VERSION=%s", nextTag)
// --- pom.xml + CHANGELOG.md (skipped with --tag-only) ---
if !o.tagOnly {
var filesToCommit []string
+41
View File
@@ -658,6 +658,47 @@ func TestRunChangelogFile(t *testing.T) {
}
}
func TestRunReleaseEnv(t *testing.T) {
_, dir := setupRepo(t)
addFile(t, dir, "x.go", "// fix")
repo, _ := gogit.PlainOpen(dir)
w, _ := repo.Worktree()
w.Add("x.go")
w.Commit("fix: something", &gogit.CommitOptions{Author: testSig()})
err := execCmd(t, "--no-push", "--branch", "release/1.2", "--repo", dir)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
data, err := os.ReadFile(filepath.Join(dir, "release.env"))
if err != nil {
t.Fatal("expected release.env to be created")
}
content := strings.TrimSpace(string(data))
if content != "NEXT_VERSION=1.2.0" {
t.Errorf("release.env content = %q, want %q", content, "NEXT_VERSION=1.2.0")
}
}
func TestRunReleaseEnvDryRun(t *testing.T) {
_, dir := setupRepo(t)
addFile(t, dir, "x.go", "// fix")
repo, _ := gogit.PlainOpen(dir)
w, _ := repo.Worktree()
w.Add("x.go")
w.Commit("fix: something", &gogit.CommitOptions{Author: testSig()})
err := execCmd(t, "--dry-run", "--branch", "release/1.2", "--repo", dir)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if _, err := os.Stat(filepath.Join(dir, "release.env")); err == nil {
t.Error("release.env must not be created in --dry-run mode")
}
}
func TestRunVerbose(t *testing.T) {
_, dir := setupRepo(t)
addFile(t, dir, "x.go", "// feat")