Compare commits
1 Commits
master
...
027b69c1f6
| Author | SHA1 | Date | |
|---|---|---|---|
| 027b69c1f6 |
14
Dockerfile
14
Dockerfile
@@ -2,6 +2,14 @@ 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
|
||||
@@ -11,7 +19,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
||||
-o bumpversion ./src
|
||||
|
||||
FROM gcr.io/distroless/static
|
||||
WORKDIR /
|
||||
COPY --from=builder /app/bumpversion /bumpversion
|
||||
ENTRYPOINT ["/bumpversion"]
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/bumpversion /app/bumpversion
|
||||
ENTRYPOINT ["/app/bumpversion"]
|
||||
CMD ["--version"]
|
||||
|
||||
17
README.md
17
README.md
@@ -6,18 +6,11 @@
|
||||
|
||||
## Разработчику
|
||||
|
||||
```bash
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
go mod init src
|
||||
go mod tidy
|
||||
go build
|
||||
go run .
|
||||
```
|
||||
или
|
||||
|
||||
```bash
|
||||
make
|
||||
```
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
go mod init src
|
||||
go mod tidy
|
||||
go build
|
||||
go run .
|
||||
|
||||
## Девопсу
|
||||
|
||||
|
||||
@@ -86,12 +86,7 @@ func gitCommit(bc *BumpConfig, newVersion string, configPath string) {
|
||||
log.Fatalf("Stat error for %s: %v", p, err)
|
||||
}
|
||||
|
||||
st, ok := status[p]
|
||||
if !ok || st == nil {
|
||||
// nothing to stage for this file
|
||||
continue
|
||||
}
|
||||
|
||||
st := status[p]
|
||||
if st.Worktree != git.Unmodified {
|
||||
if _, err := worktree.Add(p); err != nil {
|
||||
log.Fatalf("Add %s error: %v", p, err)
|
||||
|
||||
21
src/main.go
21
src/main.go
@@ -116,8 +116,8 @@ func bumpVersion(bc *BumpConfig, part string) (string, error) {
|
||||
return newVersion, nil
|
||||
}
|
||||
|
||||
// updateFiles обновляет версию в файле; при fatalIfMissing=true возвращает ошибку, если строка не найдена.
|
||||
func updateFiles(filePaths []string, oldVersion, newVersion string, fatalIfMissing bool) error {
|
||||
// updateFiles обновляет версию в файле
|
||||
func updateFiles(filePaths []string, oldVersion, newVersion string) {
|
||||
for _, path := range filePaths {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -125,20 +125,12 @@ func updateFiles(filePaths []string, oldVersion, newVersion string, fatalIfMissi
|
||||
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)
|
||||
continue
|
||||
} else {
|
||||
log.Printf("Updated file: %s", path)
|
||||
}
|
||||
log.Printf("Updated file: %s", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// updateConfigFile обновляет исходный конфигурационный файл
|
||||
@@ -209,7 +201,6 @@ 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()
|
||||
|
||||
@@ -237,9 +228,7 @@ func main() {
|
||||
fmt.Printf("New version: %s\n", newVersion)
|
||||
|
||||
// Обновляем файлы, указанные в конфигурации
|
||||
if err := updateFiles(bc.FilePaths, bc.CurrentVersion, newVersion, !*noFatal); err != nil {
|
||||
log.Fatalf("Error updating files: %v", err)
|
||||
}
|
||||
updateFiles(bc.FilePaths, bc.CurrentVersion, newVersion)
|
||||
|
||||
// Обновляем конфигурационный файл
|
||||
if err := updateConfigFile(cfg_name, newVersion); err != nil {
|
||||
|
||||
@@ -200,9 +200,7 @@ func TestUpdateFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := updateFiles(filePaths, oldV, newV, true); err != nil {
|
||||
t.Fatalf("updateFiles returned error: %v", err)
|
||||
}
|
||||
updateFiles(filePaths, oldV, newV)
|
||||
|
||||
for _, p := range filePaths {
|
||||
data, err := os.ReadFile(p)
|
||||
@@ -215,25 +213,6 @@ 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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user