Skip to content

Commit

Permalink
Merge pull request #91 from 030/90-update-number-not-checked
Browse files Browse the repository at this point in the history
[GH-90] Update number was not checked in tags.
  • Loading branch information
030 authored Sep 7, 2021
2 parents 6943898 + de1a395 commit 155f1af
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.3] - 2021-09-07

### Fixed

- Update number was not checked in tags

## [3.0.2] - 2021-08-27

### Changed
Expand Down Expand Up @@ -68,7 +74,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Return latest tag.

[Unreleased]: https://github.com/030/dip/compare/3.0.2...HEAD
[Unreleased]: https://github.com/030/dip/compare/3.0.3...HEAD
[3.0.3]: https://github.com/030/dip/compare/3.0.2...3.0.3
[3.0.2]: https://github.com/030/dip/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/030/dip/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/030/dip/compare/2.2.0...3.0.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ the pipeline will fail as an exit 1 is returned if an image is outdated.
[![dockeri.co](https://dockeri.co/image/utrecht/dip)](https://hub.docker.com/r/utrecht/dip)

```bash
docker run utrecht/dip:3.0.2 dip -image=grafana/grafana -latest=^7\.5\.7$
docker run utrecht/dip:3.0.3 dip -image=grafana/grafana -latest=^7\.5\.7$
```

will return:
Expand Down
2 changes: 1 addition & 1 deletion build/package/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: kdiutd
base: core20
version: 3.0.2
version: 3.0.3
summary: Docker Image Patrol
description: |
Keep docker images up-to-date.
Expand Down
2 changes: 1 addition & 1 deletion deployments/k8s-and-openshift/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ spec:
serviceAccountName: dip
containers:
- name: dip
image: utrecht/dip:3.0.2
image: utrecht/dip:3.0.3
resources:
limits:
memory: "64Mi"
Expand Down
6 changes: 4 additions & 2 deletions internal/semantic/semantic.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ func toInt(tagWithoutChars string) (int, error) {
func update(tag string) (int, error) {
re := regexp.MustCompile(`(_|-\w+\d\.)(\d+)`)
match := re.FindStringSubmatch(tag)
log.Debugf("match elements: '%s'", match)
elements := len(match)
if elements != 2 {
log.Debugf("Cannot determine update number. Required elements is two, but was: '%d'", elements)
if elements != 3 {
log.Debugf("Cannot determine update number. Required elements is three, but was: '%d'", elements)
return 0, nil
}
updateString := match[2]
u, err := strconv.Atoi(updateString)
log.Debugf("Update number: '%d'", u)
if err != nil {
return 0, err
}
Expand Down
18 changes: 18 additions & 0 deletions internal/semantic/semantic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,21 @@ func TestSortAndGetLatestTag(t *testing.T) {
exp := "boo"
assert.Equal(t, exp, act)
}

func TestUpdateJava(t *testing.T) {
exp := 9
act, err := update("16.0.1_9-jre-hotspot-focal")
if err != nil {
t.Error(err)
}
assert.Equal(t, exp, act)
}

func TestUpdateGolangAlpine(t *testing.T) {
exp := 14
act, err := update("1.17.0-alpine3.14")
if err != nil {
t.Error(err)
}
assert.Equal(t, exp, act)
}
18 changes: 18 additions & 0 deletions internal/sort/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ func TestTagsTwo(t *testing.T) {
assert.Equal(t, exp, act)
}

func TestTagsJava(t *testing.T) {
exp := "16.0.1_9-jdk-hotspot-windowsservercore"
act, err := Tags([]string{"14.0.2_12-jre-hotspot-bionic", "16.0.1_9-jdk-hotspot-windowsservercore", "14.0.2_13-jre-hotspot-bionic"})
if err != nil {
t.Error(err)
}
assert.Equal(t, exp, act)
}

func TestTagsGolangAlpine(t *testing.T) {
exp := "1.17.0-alpine3.16"
act, err := Tags([]string{"1.17.0-alpine3.12", "1.17.0-alpine3.14", "1.17.0-alpine3.16", "1.17.0-alpine3.15", "1.17.0-alpine3.13"})
if err != nil {
t.Error(err)
}
assert.Equal(t, exp, act)
}

func TestTagsError(t *testing.T) {
actualError := "cannot find the latest tag. Check whether the tags are semantic"
_, err := Tags([]string{""})
Expand Down

0 comments on commit 155f1af

Please sign in to comment.