forked from coop-cloud/tagcmp
Compare commits
4 Commits
72eabea81d
...
03d2daced9
Author | SHA1 | Date |
---|---|---|
knoflook | 03d2daced9 | |
decentral1se | 778718caed | |
decentral1se | ed6331dc7a | |
decentral1se | 0581b1f5ed |
|
@ -0,0 +1,34 @@
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: coopcloud.tech/tagcmp
|
||||||
|
steps:
|
||||||
|
- name: make check
|
||||||
|
image: golang:1.17
|
||||||
|
commands:
|
||||||
|
- make check
|
||||||
|
|
||||||
|
- name: make build
|
||||||
|
image: golang:1.17
|
||||||
|
commands:
|
||||||
|
- make build
|
||||||
|
|
||||||
|
- name: make test
|
||||||
|
image: golang:1.17
|
||||||
|
commands:
|
||||||
|
- make test
|
||||||
|
|
||||||
|
- name: notify on failure
|
||||||
|
image: plugins/matrix
|
||||||
|
settings:
|
||||||
|
homeserver: https://matrix.autonomic.zone
|
||||||
|
roomid: "IFazIpLtxiScqbHqoa:autonomic.zone"
|
||||||
|
userid: "@autono-bot:autonomic.zone"
|
||||||
|
accesstoken:
|
||||||
|
from_secret: autono_bot_access_token
|
||||||
|
depends_on:
|
||||||
|
- make check
|
||||||
|
- make build
|
||||||
|
- make test
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- failure
|
|
@ -0,0 +1,8 @@
|
||||||
|
build:
|
||||||
|
@go build .
|
||||||
|
|
||||||
|
check:
|
||||||
|
@test -z $$(gofmt -l .) || (echo "gofmt: formatting issue - run 'make format' to resolve" && exit 1)
|
||||||
|
|
||||||
|
test:
|
||||||
|
@go test . -cover
|
|
@ -1,5 +1,6 @@
|
||||||
# tagcmp
|
# tagcmp
|
||||||
|
|
||||||
|
[![Build Status](https://build.coopcloud.tech/api/badges/coop-cloud/tagcmp/status.svg?ref=refs/heads/main)](https://build.coopcloud.tech/coop-cloud/tagcmp)
|
||||||
[![Go Report Card](https://goreportcard.com/badge/git.coopcloud.tech/coop-cloud/tagcmp)](https://goreportcard.com/report/git.coopcloud.tech/coop-cloud/tagcmp)
|
[![Go Report Card](https://goreportcard.com/badge/git.coopcloud.tech/coop-cloud/tagcmp)](https://goreportcard.com/report/git.coopcloud.tech/coop-cloud/tagcmp)
|
||||||
|
|
||||||
Comparison operations for image tags. Because registries aren't doing this for
|
Comparison operations for image tags. Because registries aren't doing this for
|
||||||
|
|
18
godoc.md
18
godoc.md
|
@ -12,6 +12,7 @@ Package tagcmp provides image tag comparison operations\.
|
||||||
|
|
||||||
- [Variables](<#variables>)
|
- [Variables](<#variables>)
|
||||||
- [func IsParsable(tag string) bool](<#func-isparsable>)
|
- [func IsParsable(tag string) bool](<#func-isparsable>)
|
||||||
|
- [func UpgradeType(t Tag) int](<#func-upgradetype>)
|
||||||
- [type ByTagAsc](<#type-bytagasc>)
|
- [type ByTagAsc](<#type-bytagasc>)
|
||||||
- [func (t ByTagAsc) Len() int](<#func-bytagasc-len>)
|
- [func (t ByTagAsc) Len() int](<#func-bytagasc-len>)
|
||||||
- [func (t ByTagAsc) Less(i, j int) bool](<#func-bytagasc-less>)
|
- [func (t ByTagAsc) Less(i, j int) bool](<#func-bytagasc-less>)
|
||||||
|
@ -27,6 +28,7 @@ Package tagcmp provides image tag comparison operations\.
|
||||||
- [func (t Tag) IsGreaterThan(tag Tag) bool](<#func-tag-isgreaterthan>)
|
- [func (t Tag) IsGreaterThan(tag Tag) bool](<#func-tag-isgreaterthan>)
|
||||||
- [func (t Tag) IsLessThan(tag Tag) bool](<#func-tag-islessthan>)
|
- [func (t Tag) IsLessThan(tag Tag) bool](<#func-tag-islessthan>)
|
||||||
- [func (t Tag) String() string](<#func-tag-string>)
|
- [func (t Tag) String() string](<#func-tag-string>)
|
||||||
|
- [func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error)](<#func-tag-upgradeelement>)
|
||||||
|
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
@ -69,6 +71,14 @@ func IsParsable(tag string) bool
|
||||||
|
|
||||||
IsParsable determines if a tag is supported by this library
|
IsParsable determines if a tag is supported by this library
|
||||||
|
|
||||||
|
## func UpgradeType
|
||||||
|
|
||||||
|
```go
|
||||||
|
func UpgradeType(t Tag) int
|
||||||
|
```
|
||||||
|
|
||||||
|
UpgradeType takes exit from UpgradeElemene and returns a numeric representation of upgrade or downgrade 1/\-1: patch 2/\-2: minor 4/\-4: major 0: no change
|
||||||
|
|
||||||
## type ByTagAsc
|
## type ByTagAsc
|
||||||
|
|
||||||
ByTagAsc sorts tags in ascending order where the last element is the latest tag\.
|
ByTagAsc sorts tags in ascending order where the last element is the latest tag\.
|
||||||
|
@ -183,6 +193,14 @@ func (t Tag) String() string
|
||||||
|
|
||||||
String formats a Tag correctly in string representation
|
String formats a Tag correctly in string representation
|
||||||
|
|
||||||
|
### func \(Tag\) UpgradeElement
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
UpgradeElement returns a Tag object which is the difference between an old and new tag It can contain negative numbers if comparing with an older tag\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
||||||
|
|
36
tagcmp.go
36
tagcmp.go
|
@ -173,12 +173,36 @@ func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error) {
|
||||||
return Tag{}, fmt.Errorf("%s and %s are not compatible with each other", curTag.String(), newTag.String())
|
return Tag{}, fmt.Errorf("%s and %s are not compatible with each other", curTag.String(), newTag.String())
|
||||||
}
|
}
|
||||||
diff := curTag
|
diff := curTag
|
||||||
diff.Major(strconv.Itoa(strconv.Atoi(newTag.Major) - strconv.Atoi(curTag.Major)))
|
curMajor, err := strconv.Atoi(curTag.Major)
|
||||||
|
if err != nil {
|
||||||
|
return Tag{}, err
|
||||||
|
}
|
||||||
|
curMinor, err := strconv.Atoi(curTag.Minor)
|
||||||
|
if err != nil {
|
||||||
|
return Tag{}, err
|
||||||
|
}
|
||||||
|
curPatch, err := strconv.Atoi(curTag.Patch)
|
||||||
|
if err != nil {
|
||||||
|
return Tag{}, err
|
||||||
|
}
|
||||||
|
newMajor, err := strconv.Atoi(newTag.Major)
|
||||||
|
if err != nil {
|
||||||
|
return Tag{}, err
|
||||||
|
}
|
||||||
|
newMinor, err := strconv.Atoi(newTag.Minor)
|
||||||
|
if err != nil {
|
||||||
|
return Tag{}, err
|
||||||
|
}
|
||||||
|
newPatch, err := strconv.Atoi(newTag.Patch)
|
||||||
|
if err != nil {
|
||||||
|
return Tag{}, err
|
||||||
|
}
|
||||||
|
diff.Major = strconv.Itoa(newMajor - curMajor)
|
||||||
if !curTag.MissingMinor {
|
if !curTag.MissingMinor {
|
||||||
diff.Minor(strconv.Itoa(strconv.Atoi(newTag.Minor) - strconv.Atoi(curTag.Minor)))
|
diff.Minor = strconv.Itoa(newMinor - curMinor)
|
||||||
}
|
}
|
||||||
if !curTag.MissingPatch {
|
if !curTag.MissingPatch {
|
||||||
diff.Patch(strconv.Itoa(strconv.Atoi(newTag.Patch) - strconv.Atoi(curTag.Patch)))
|
diff.Patch = strconv.Itoa(newPatch - curPatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
return diff, nil
|
return diff, nil
|
||||||
|
@ -188,16 +212,16 @@ func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error) {
|
||||||
// 1/-1: patch 2/-2: minor 4/-4: major 0: no change
|
// 1/-1: patch 2/-2: minor 4/-4: major 0: no change
|
||||||
func UpgradeType(t Tag) int {
|
func UpgradeType(t Tag) int {
|
||||||
var major, minor, patch int
|
var major, minor, patch int
|
||||||
major = strconv.Atoi(t.Major)
|
major, _ = strconv.Atoi(t.Major)
|
||||||
if t.MissingMinor {
|
if t.MissingMinor {
|
||||||
minor = 0
|
minor = 0
|
||||||
} else {
|
} else {
|
||||||
minor = strconv.Atoi(t.Minor)
|
minor, _ = strconv.Atoi(t.Minor)
|
||||||
}
|
}
|
||||||
if t.MissingPatch {
|
if t.MissingPatch {
|
||||||
patch = 0
|
patch = 0
|
||||||
} else {
|
} else {
|
||||||
patch := strconv.Atoi(t.Patch)
|
patch, _ = strconv.Atoi(t.Patch)
|
||||||
}
|
}
|
||||||
if major > 0 {
|
if major > 0 {
|
||||||
return 4
|
return 4
|
||||||
|
|
Loading…
Reference in New Issue