Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-yurchenko committed Jul 27, 2021
1 parent a2a9bdd commit aedea01
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog

## [1.0.1] - 2021-07-27
### Fixed
- Files in nested directories are unreachable

### Changed
- Support whitespaces in Docker label definition

## [1.0.0] - 2021-07-27
_First release_

[0.1.1]: https://github.com/anton-yurchenko/version-bump/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/anton-yurchenko/version-bump/releases/tag/v1.0.0
25 changes: 14 additions & 11 deletions bump/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bump

import (
"fmt"
"path"
"regexp"
"strings"

Expand Down Expand Up @@ -197,6 +198,7 @@ func (b *Bump) bumpComponent(name string, l Language, action int, versions map[s
}

modifiedFiles, err := b.incrementVersion(
dir,
filterFiles(langSettings.Files, f),
*langSettings,
action,
Expand All @@ -213,12 +215,13 @@ func (b *Bump) bumpComponent(name string, l Language, action int, versions map[s
return files, nil
}

func (b *Bump) incrementVersion(files []string, lang langs.Language, action int, versions map[string]int, version *string) ([]string, error) {
func (b *Bump) incrementVersion(dir string, files []string, lang langs.Language, action int, versions map[string]int, version *string) ([]string, error) {
var identified bool
modifiedFiles := make([]string, 0)

for _, file := range files {
fileContent, err := readFile(b.FS, file)
filepath := path.Join(dir, file)
fileContent, err := readFile(b.FS, filepath)
if err != nil {
return []string{}, errors.Wrapf(err, "error reading a file %v", file)
}
Expand All @@ -233,7 +236,7 @@ func (b *Bump) incrementVersion(files []string, lang langs.Language, action int,
if regex.MatchString(line) {
oldVersion, err = semver.StrictNewVersion(regex.ReplaceAllString(line, "${1}"))
if err != nil {
return []string{}, errors.Wrapf(err, "error parsing semantic version at file %v", file)
return []string{}, errors.Wrapf(err, "error parsing semantic version at file %v", filepath)
}
break outer
}
Expand All @@ -245,7 +248,7 @@ func (b *Bump) incrementVersion(files []string, lang langs.Language, action int,
for _, field := range *lang.JSONFields {
oldVersion, err = semver.StrictNewVersion(gjson.Get(strings.Join(fileContent, ""), field).String())
if err != nil {
return []string{}, errors.Wrapf(err, "error parsing semantic version at file %v", file)
return []string{}, errors.Wrapf(err, "error parsing semantic version at file %v", filepath)
}
break
}
Expand All @@ -263,7 +266,7 @@ func (b *Bump) incrementVersion(files []string, lang langs.Language, action int,
newVersion = oldVersion.IncPatch()
}

console.VersionUpdate(oldVersion.String(), newVersion.String(), file)
console.VersionUpdate(oldVersion.String(), newVersion.String(), filepath)
*version = newVersion.String()
identified = true
versions[oldVersion.String()]++
Expand All @@ -289,11 +292,11 @@ func (b *Bump) incrementVersion(files []string, lang langs.Language, action int,
}

newContent = append(newContent, "")
if err := writeFile(b.FS, file, strings.Join(newContent, "\n")); err != nil {
return []string{}, errors.Wrapf(err, "error writing to file %v", file)
if err := writeFile(b.FS, filepath, strings.Join(newContent, "\n")); err != nil {
return []string{}, errors.Wrapf(err, "error writing to file %v", filepath)
}

modifiedFiles = append(modifiedFiles, file)
modifiedFiles = append(modifiedFiles, filepath)
}

if lang.JSONFields != nil {
Expand All @@ -304,11 +307,11 @@ func (b *Bump) incrementVersion(files []string, lang langs.Language, action int,
return []string{}, errors.Wrapf(err, "error setting new version on content of a file %v", file)
}

if err := writeFile(b.FS, file, newContent); err != nil {
return []string{}, errors.Wrapf(err, "error writing to file %v", file)
if err := writeFile(b.FS, filepath, newContent); err != nil {
return []string{}, errors.Wrapf(err, "error writing to file %v", filepath)
}

modifiedFiles = append(modifiedFiles, file)
modifiedFiles = append(modifiedFiles, filepath)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bump/bump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func main() {
import "fmt"
const (
Version string = "1.2.3"
Version string = "1.2.4"
SomeVeryLongVariableNameThatAddsALotOfWhitespace string = "abc"
)
Expand Down
2 changes: 1 addition & 1 deletion bump/modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
Version string = "1.0.0"
Version string = "1.0.1"
Patch int = 3
Minor int = 2
Major int = 1
Expand Down
2 changes: 1 addition & 1 deletion langs/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

var dockerRegex = []string{
fmt.Sprintf("^LABEL \"[vV]ersion\"=\"[vV]?(?P<version>%v)\"", changelog.SemVerRegex),
fmt.Sprintf("^LABEL\\s+\"[vV]ersion\"\\s*=\\s*\"[vV]?(?P<version>%v)\"", changelog.SemVerRegex),
}
2 changes: 1 addition & 1 deletion langs/langs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestNew(t *testing.T) {
a := assert.New(t)

var dockerRegex = []string{
fmt.Sprintf("^LABEL \"[vV]ersion\"=\"[vV]?(?P<version>%v)\"", changelog.SemVerRegex),
fmt.Sprintf("^LABEL\\s+\"[vV]ersion\"\\s*=\\s*\"[vV]?(?P<version>%v)\"", changelog.SemVerRegex),
}

var golangRegex = []string{
Expand Down

0 comments on commit aedea01

Please sign in to comment.