Skip to content

Commit f5afdc2

Browse files
Merge pull request #16 from NeowayLabs/fix-is-set-new-version-function
type: [fix], message: Fix isSetNewVersion function logic.
2 parents 6aaddfe + 4fdef7b commit f5afdc2

6 files changed

+41
-20
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v1.0.5
2+
- Fix isSetNewVersion function logic (@esequiel.virtuoso)
3+
14
v1.0.4
25
- Fix versioning problem (@lucas.oliveira)
36
- Changed `gitlab-backup.sh` to keep all backups (@lucas.oliveira)
@@ -16,4 +19,4 @@ v1.0.1
1619
- Fix tag name conversion bug. (@esequiel.virtuoso)
1720

1821
v1.0.0
19-
- First version of semantic-release. (@esequiel.virtuoso)
22+
- First version of semantic-release. (@esequiel.virtuoso)

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ git_project_test=integration-tests
1919
git_host_test=localhost
2020
gitlab_container_name=gitlab_integration_tests
2121
run_local=./cmd/semantic-release/semantic-release
22-
backup_file=1689288217_2023_07_13_14.9.2-ee_gitlab_backup.tar
22+
backup_file=1708548861_2024_02_21_14.9.2-ee_gitlab_backup.tar
2323

2424
all: check build
2525

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Add new integration tests if you make a change that needs to interact with a rep
119119
make env
120120
```
121121

122-
This will run a container with a full GitLab. Wait for GitLab to be accessible through the browser.
122+
This will run a container with a full GitLab. Wait for GitLab to be accessible through the browser. It can take up to 5 minutes.
123123

124124
Address: https://localhost:443
125125

@@ -197,4 +197,4 @@ To install the project githooks run:
197197

198198
```
199199
make githooks
200-
```
200+
```

src/git/git.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func isSetNewVersion(latest, version *Version, tag string) (*Version, string) {
467467
if latest == nil || version.isGreaterThan(latest) {
468468
return version, tag
469469
}
470-
return latest, ""
470+
return latest, fmt.Sprintf("%d.%d.%d", latest.Major, latest.Minor, latest.Patch)
471471
}
472472

473473
func (v *Version) isGreaterThan(other *Version) bool {

src/git/git_integration_test.go

+33-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
alphaNumericTagProject = fmt.Sprintf("https://%s/dataplatform/alpha-numeric-tag-project.git", host)
2424
tagsOutOfPatternProject = fmt.Sprintf("https://%s/dataplatform/tags-out-of-pattern-project.git", host)
2525
greatNumbersTagProject = fmt.Sprintf("https://%s/dataplatform/great-numbers-tag-project.git", host)
26+
disorderedTagsProject = fmt.Sprintf("https://%s/dataplatform/disordered-tags-prject.git", host)
2627
)
2728

2829
func TestNewGitNoError(t *testing.T) {
@@ -47,7 +48,7 @@ func TestNewGitRepositoryAlreadyClonedNoError(t *testing.T) {
4748
func TestNewGitRepositoryNotFound(t *testing.T) {
4849
f := setup()
4950
f.gitLabVersioning.url = "any"
50-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-set-project")
51+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-set-project")
5152
f.gitLabVersioning.username = "root"
5253
f.gitLabVersioning.password = "password"
5354
_, err := f.newGitService()
@@ -58,7 +59,7 @@ func TestNewGitRepositoryNotFound(t *testing.T) {
5859
func TestNewGitEmptyRepositoryError(t *testing.T) {
5960
f := getValidSetup()
6061
f.gitLabVersioning.url = noBranchProject
61-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-branch-project")
62+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-branch-project")
6263
_, err := f.newGitService()
6364
tests.AssertError(t, err)
6465
tests.AssertEqualValues(t, "error while initiating git package due to : remote repository is empty", err.Error())
@@ -117,7 +118,7 @@ func TestNewGitCommitGetCurrentVersionNoError(t *testing.T) {
117118
func TestNewGitUpgradeRemoteRepositoryAddChangesError(t *testing.T) {
118119
f := getValidSetup()
119120
f.gitLabVersioning.url = noTagsProject
120-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-tags-project")
121+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-tags-project")
121122
f.gitFunctions.errAddToStage = errors.New("no changes to add")
122123
repo, err := f.newGitService()
123124
tests.AssertNoError(t, err)
@@ -137,7 +138,7 @@ func TestNewGitUpgradeRemoteRepositoryAddChangesError(t *testing.T) {
137138
func TestNewGitUpgradeRemoteRepositoryCommitChangesError(t *testing.T) {
138139
f := getValidSetup()
139140
f.gitLabVersioning.url = noTagsProject
140-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-tags-project")
141+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-tags-project")
141142
f.gitFunctions.errCommitChanges = errors.New("commit is old dated")
142143
repo, err := f.newGitService()
143144
tests.AssertNoError(t, err)
@@ -157,7 +158,7 @@ func TestNewGitUpgradeRemoteRepositoryCommitChangesError(t *testing.T) {
157158
func TestNewGitUpgradeRemoteRepositoryPushError(t *testing.T) {
158159
f := getValidSetup()
159160
f.gitLabVersioning.url = noTagsProject
160-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-tags-project")
161+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-tags-project")
161162
f.gitFunctions.errPush = errors.New("nothing to push")
162163
repo, err := f.newGitService()
163164
tests.AssertNoError(t, err)
@@ -177,7 +178,7 @@ func TestNewGitUpgradeRemoteRepositoryPushError(t *testing.T) {
177178
func TestNewGitUpgradeRemoteRepositorySetTagError(t *testing.T) {
178179
f := getValidSetup()
179180
f.gitLabVersioning.url = noTagsProject
180-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-tags-project")
181+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-tags-project")
181182
f.gitFunctions.errSetTag = errors.New("unable to set new tag")
182183
repo, err := f.newGitService()
183184
tests.AssertNoError(t, err)
@@ -197,7 +198,7 @@ func TestNewGitUpgradeRemoteRepositorySetTagError(t *testing.T) {
197198
func TestNewGitUpgradeRemoteRepositoryPushTagsError(t *testing.T) {
198199
f := getValidSetup()
199200
f.gitLabVersioning.url = noTagsProject
200-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-tags-project")
201+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-tags-project")
201202
f.gitFunctions.errPushTag = errors.New("unable to push tags to remote repository")
202203
repo, err := f.newGitService()
203204
tests.AssertNoError(t, err)
@@ -217,7 +218,7 @@ func TestNewGitUpgradeRemoteRepositoryPushTagsError(t *testing.T) {
217218
func TestNewGitUpgradeRemoteRepositoryNoError(t *testing.T) {
218219
f := getValidSetup()
219220
f.gitLabVersioning.url = noTagsProject
220-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-tags-project")
221+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-tags-project")
221222
repo, err := f.newGitService()
222223
tests.AssertNoError(t, err)
223224

@@ -246,7 +247,7 @@ func TestNewGitUpgradeRemoteRepositoryNoError(t *testing.T) {
246247
func TestNewGitUpgradeRemoteRepositoryProtectedTagError(t *testing.T) {
247248
f := getValidSetup()
248249
f.gitLabVersioning.url = protectedTagProject
249-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "protected-tag-project")
250+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("protected-tag-project")
250251
repo, err := f.newGitService()
251252
tests.AssertNoError(t, err)
252253

@@ -259,7 +260,7 @@ func TestNewGitUpgradeRemoteRepositoryProtectedTagError(t *testing.T) {
259260
func TestNewGitUpgradeRemoteRepositoryAlreadyPushedTagError(t *testing.T) {
260261
f := getValidSetup()
261262
f.gitLabVersioning.url = noTagsProject
262-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "no-tags-project")
263+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("no-tags-project")
263264
repo, err := f.newGitService()
264265
tests.AssertNoError(t, err)
265266

@@ -282,7 +283,7 @@ func TestNewGitUpgradeRemoteRepositoryAlreadyPushedTagError(t *testing.T) {
282283
func TestNewGitUpgradeRemoteRepositoryPushToProtectedBranchError(t *testing.T) {
283284
f := getValidSetup()
284285
f.gitLabVersioning.url = protectedBranchProject
285-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "protected-branch-project")
286+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("protected-branch-project")
286287
repo, err := f.newGitService()
287288
tests.AssertNoError(t, err)
288289

@@ -300,7 +301,7 @@ func TestNewGitUpgradeRemoteRepositoryPushToProtectedBranchError(t *testing.T) {
300301
func TestNewGitGetCurrentVersionFromRepoWithAlphaCharacteres(t *testing.T) {
301302
f := getValidSetup()
302303
f.gitLabVersioning.url = alphaTagProject
303-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "alpha-tag-project")
304+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("alpha-tag-project")
304305
repo, err := f.newGitService()
305306
tests.AssertNoError(t, err)
306307

@@ -312,7 +313,7 @@ func TestNewGitGetCurrentVersionFromRepoWithAlphaCharacteres(t *testing.T) {
312313
func TestNewGitGetCurrentVersionFromRepoWithAlphaAndNumericCharacteres(t *testing.T) {
313314
f := getValidSetup()
314315
f.gitLabVersioning.url = alphaNumericTagProject
315-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "alpha-numeric-tag-project")
316+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("alpha-numeric-tag-project")
316317
repo, err := f.newGitService()
317318
tests.AssertNoError(t, err)
318319

@@ -324,7 +325,7 @@ func TestNewGitGetCurrentVersionFromRepoWithAlphaAndNumericCharacteres(t *testin
324325
func TestNewGitGetCurrentVersionFromRepoWithTagsOutOfPattern(t *testing.T) {
325326
f := getValidSetup()
326327
f.gitLabVersioning.url = tagsOutOfPatternProject
327-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "tags-out-of-pattern-project")
328+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("tags-out-of-pattern-project")
328329
repo, err := f.newGitService()
329330
tests.AssertNoError(t, err)
330331

@@ -337,7 +338,7 @@ func TestNewGitGetCurrentVersionFromRepoWithTagsOutOfPattern(t *testing.T) {
337338
func TestNewGitGetCurrentVersionFromRepoWithGreatNumbersTag(t *testing.T) {
338339
f := getValidSetup()
339340
f.gitLabVersioning.url = greatNumbersTagProject
340-
f.gitLabVersioning.destinationDirectory = fmt.Sprintf("%s/%s", os.Getenv("HOME"), "great-numbers-tag-project")
341+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("great-numbers-tag-project")
341342
repo, err := f.newGitService()
342343
tests.AssertNoError(t, err)
343344

@@ -346,3 +347,20 @@ func TestNewGitGetCurrentVersionFromRepoWithGreatNumbersTag(t *testing.T) {
346347
tests.AssertEqualValues(t, "3.0.2", result)
347348
f.cleanLocalRepo(t)
348349
}
350+
351+
func TestNewGitGetCurrentVersionFromRepoWithDisorderedTags(t *testing.T) {
352+
f := getValidSetup()
353+
f.gitLabVersioning.url = disorderedTagsProject
354+
f.gitLabVersioning.destinationDirectory = getDestinationDirectory("disordered-tags-prject")
355+
repo, err := f.newGitService()
356+
tests.AssertNoError(t, err)
357+
358+
result, err := repo.GetMostRecentTag()
359+
tests.AssertNil(t, err)
360+
tests.AssertEqualValues(t, "20.1.0", result)
361+
f.cleanLocalRepo(t)
362+
}
363+
364+
func getDestinationDirectory(repo string) string {
365+
return fmt.Sprintf("%s/%s", os.Getenv("HOME"), repo)
366+
}
Binary file not shown.

0 commit comments

Comments
 (0)