Compare commits

...

3 Commits

Author SHA1 Message Date
123cd38a18 Add fatal missing-version handling with opt-out flag
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-01 13:11:33 +03:00
f9865168c9 Fix entrypoint
All checks were successful
continuous-integration/drone/push Build is passing
2025-12-24 14:22:01 +03:00
08c1a170dc Bump version
All checks were successful
continuous-integration/drone/push Build is passing
2025-12-24 12:42:18 +03:00
8 changed files with 64 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.2
current_version = 1.0.0
commit = True
tag = True
tag_name = {new_version}

View File

@@ -15,7 +15,7 @@ steps:
path: /var/run/docker.sock
settings:
dockerfile: Dockerfile
tags: 0.1.2
tags: 1.0.0
force_tag: true
registry: registry.halfakop.ru
repo: registry.halfakop.ru/golang/bumpversion

View File

@@ -2,14 +2,6 @@ FROM golang:1.24-alpine AS builder
ARG SOURCE_VERSION
ARG SOURCE_COMMIT
ARG GOPROXY
ARG GONOSUMDB
ENV GOPROXY=${GOPROXY}
ENV GONOSUMDB=${GONOSUMDB}
RUN go env GOPROXY
RUN test -n "$GOPROXY" || (echo "GOPROXY not set" && exit 1)
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
@@ -19,7 +11,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-o bumpversion ./src
FROM gcr.io/distroless/static
WORKDIR /app
COPY --from=builder /app/bumpversion /app/bumpversion
ENTRYPOINT ["/app/bumpversion"]
WORKDIR /
COPY --from=builder /app/bumpversion /bumpversion
ENTRYPOINT ["/bumpversion"]
CMD ["--version"]

View File

@@ -1,4 +1,4 @@
# BumpVersion v0.1.2
# BumpVersion v1.0.0
[![Build Status](https://drone.halfakop.ru/api/badges/rad/bumpversion/status.svg)](https://drone.halfakop.ru/rad/bumpversion)
@@ -6,11 +6,18 @@
## Разработчику
```bash
export PATH=$PATH:/usr/local/go/bin
go mod init src
go mod tidy
go build
go run .
```
или
```bash
make
```
## Девопсу

View File

@@ -1 +1 @@
0.1.2
1.0.0

View File

@@ -86,7 +86,12 @@ func gitCommit(bc *BumpConfig, newVersion string, configPath string) {
log.Fatalf("Stat error for %s: %v", p, err)
}
st := status[p]
st, ok := status[p]
if !ok || st == nil {
// nothing to stage for this file
continue
}
if st.Worktree != git.Unmodified {
if _, err := worktree.Add(p); err != nil {
log.Fatalf("Add %s error: %v", p, err)

View File

@@ -116,8 +116,8 @@ func bumpVersion(bc *BumpConfig, part string) (string, error) {
return newVersion, nil
}
// updateFiles обновляет версию в файле
func updateFiles(filePaths []string, oldVersion, newVersion string) {
// updateFiles обновляет версию в файле; при fatalIfMissing=true возвращает ошибку, если строка не найдена.
func updateFiles(filePaths []string, oldVersion, newVersion string, fatalIfMissing bool) error {
for _, path := range filePaths {
data, err := os.ReadFile(path)
if err != nil {
@@ -125,12 +125,20 @@ func updateFiles(filePaths []string, oldVersion, newVersion string) {
continue
}
newData := strings.ReplaceAll(string(data), oldVersion, newVersion)
if newData == string(data) {
log.Printf("Version %s not found in %s; skip update", oldVersion, path)
if fatalIfMissing {
return fmt.Errorf("version %s not found in %s", oldVersion, path)
}
continue
}
if err := os.WriteFile(path, []byte(newData), 0644); err != nil {
log.Printf("Unable to write file %s: %v", path, err)
} else {
continue
}
log.Printf("Updated file: %s", path)
}
}
return nil
}
// updateConfigFile обновляет исходный конфигурационный файл
@@ -167,7 +175,7 @@ func resolveFlag(positive, negative *bool, defaultValue bool) (bool, error) {
const AppName = "BumpVersion"
var (
AppVersion = "0.1.3"
AppVersion = "1.0.0"
AppCommit = "unknown"
)
@@ -201,6 +209,7 @@ func main() {
noCommit := flag.Bool("no-commit", false, "Do not create a commit")
tag := flag.Bool("tag", false, "Add a git tag")
noTag := flag.Bool("no-tag", false, "Do not add a git tag")
noFatal := flag.Bool("no-fatal", false, "Do not fail if a configured file does not contain the current version")
push := flag.Bool("push", false, "Force push to repository")
flag.Parse()
@@ -228,7 +237,9 @@ func main() {
fmt.Printf("New version: %s\n", newVersion)
// Обновляем файлы, указанные в конфигурации
updateFiles(bc.FilePaths, bc.CurrentVersion, newVersion)
if err := updateFiles(bc.FilePaths, bc.CurrentVersion, newVersion, !*noFatal); err != nil {
log.Fatalf("Error updating files: %v", err)
}
// Обновляем конфигурационный файл
if err := updateConfigFile(cfg_name, newVersion); err != nil {

View File

@@ -200,7 +200,9 @@ func TestUpdateFiles(t *testing.T) {
}
}
updateFiles(filePaths, oldV, newV)
if err := updateFiles(filePaths, oldV, newV, true); err != nil {
t.Fatalf("updateFiles returned error: %v", err)
}
for _, p := range filePaths {
data, err := os.ReadFile(p)
@@ -213,6 +215,25 @@ func TestUpdateFiles(t *testing.T) {
}
}
func TestUpdateFilesMissingVersionFatal(t *testing.T) {
tmpDir := t.TempDir()
oldV := "1.2.3"
newV := "1.2.4"
target := filepath.Join(tmpDir, "README.md")
if err := os.WriteFile(target, []byte("no version here\n"), 0o644); err != nil {
t.Fatalf("write: %v", err)
}
if err := updateFiles([]string{target}, oldV, newV, true); err == nil {
t.Fatalf("expected error when version is missing")
}
if err := updateFiles([]string{target}, oldV, newV, false); err != nil {
t.Fatalf("did not expect error when no-fatal is set: %v", err)
}
}
func TestResolveFlag(t *testing.T) {
boolPtr := func(b bool) *bool { return &b }