From 7fdf5ddcf38cc010546beaea82ec1c8afc5737de Mon Sep 17 00:00:00 2001 From: k3nny Date: Tue, 7 Jul 2026 00:33:57 +0200 Subject: [PATCH] fix(maven): skip pom.xml update when file does not exist If pom.xml (or the configured maven.pom_path) is absent, releaser now logs a notice and proceeds to tag and push without failing. This makes the tool usable in non-Maven projects. An os.Stat error that is not ErrNotExist (e.g. permission denied) still surfaces as an error. Co-Authored-By: Claude Sonnet 4.6 --- CHANGELOG.md | 3 ++- README.md | 2 +- cmd/main.go | 14 +++++++++++--- cmd/main_test.go | 37 +++++++++++++++++++++++++++++++++---- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a22b69..065b3e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,12 @@ All notable changes to this project will be documented in this file. Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). -## [0.4.1] - 2026-07-07 +## [0.4.2] - 2026-07-07 ### Fixed - **CI build step** — `go build ./cmd/...` failed with "output already exists and is a directory" because Go tried to write a binary named `cmd`, conflicting with the source directory; fixed by passing `-o /dev/null` +- **Optional pom.xml** — releaser no longer fails when `pom.xml` (or the configured `maven.pom_path`) does not exist; it logs a notice and proceeds directly to tag and push, making the tool usable in non-Maven projects ## [0.4.0] - 2026-07-07 diff --git a/README.md b/README.md index 4fd3455..3aa1ffc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # releaser -![release](https://img.shields.io/badge/release-v0.4.1-blue.svg) +![release](https://img.shields.io/badge/release-v0.4.2-blue.svg) A CI-friendly release automation tool for GitFlow workflows using Conventional Commits. diff --git a/cmd/main.go b/cmd/main.go index 80294ad..8639547 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -203,9 +203,15 @@ func run(o options) error { return nil } - // --- pom.xml (skipped with --tag-only) --- - if !o.tagOnly { - pomPath := filepath.Join(absRepo, cfg.Maven.PomPath) + // --- pom.xml (skipped with --tag-only or when the file does not exist) --- + pomPath := filepath.Join(absRepo, cfg.Maven.PomPath) + _, statErr := os.Stat(pomPath) + hasPom := !errors.Is(statErr, os.ErrNotExist) + if statErr != nil && hasPom { + return fmt.Errorf("check pom path: %w", statErr) + } + + if !o.tagOnly && hasPom { currentPomVersion, err := maven.ReadVersion(pomPath) if err != nil { return fmt.Errorf("read pom version: %w", err) @@ -235,6 +241,8 @@ func run(o options) error { return fmt.Errorf("commit pom.xml: %w", err) } fmt.Fprintf(os.Stderr, "info: committed: %s\n", commitMsg) + } else if !o.tagOnly && !hasPom { + fmt.Fprintln(os.Stderr, "info: no pom.xml found — skipping version bump commit") } // --- Git tag --- diff --git a/cmd/main_test.go b/cmd/main_test.go index 6e18481..40f8054 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -211,6 +211,7 @@ func TestRunPomOverride(t *testing.T) { } func TestRunMissingPom(t *testing.T) { + // --pom points to a non-existent file: pom update is skipped, tag is still created. _, dir := setupRepo(t) addFile(t, dir, "x.go", "// fix") repo, _ := gogit.PlainOpen(dir) @@ -218,10 +219,38 @@ func TestRunMissingPom(t *testing.T) { w.Add("x.go") w.Commit("fix: patch", &gogit.CommitOptions{Author: testSig()}) - // Use --pom to point to a non-existent file; keeps the working tree clean. - err := execCmd(t, "--branch", "release/1.2", "--repo", dir, "--pom", "nonexistent.xml") - if err == nil { - t.Fatal("expected error for missing pom.xml") + err := execCmd(t, "--no-push", "--branch", "release/1.2", "--repo", dir, "--pom", "nonexistent.xml") + if err != nil { + t.Fatalf("missing pom should be skipped, got error: %v", err) + } + + // Tag must still have been created. + repo2, _ := gogit.PlainOpen(dir) + _, err = repo2.Tag("v1.2.0") + if err != nil { + t.Error("expected tag v1.2.0 to be created") + } +} + +func TestRunNoPomAtDefaultPath(t *testing.T) { + // Repo with no pom.xml at the default path: runs without error, creates tag. + dir := t.TempDir() + repo, err := gogit.PlainInit(dir, false) + if err != nil { + t.Fatal(err) + } + addFile(t, dir, "main.go", "package main") + commitAll(t, repo, dir, "fix: initial") + + err = execCmd(t, "--no-push", "--branch", "release/2.0", "--repo", dir) + if err != nil { + t.Fatalf("no pom.xml should not be an error: %v", err) + } + + repo2, _ := gogit.PlainOpen(dir) + _, err = repo2.Tag("v2.0.0") + if err != nil { + t.Error("expected tag v2.0.0 to be created") } }