Skip to content

Commit 86c109f

Browse files
authored
feat(release): added option to extend the release lifetime (#189)
Signed-off-by: Lukasz Dziedziak <lukidzi@gmail.com>
1 parent 0048130 commit 86c109f

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

cmd/internal/github/graphql.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"net/http"
1010
"regexp"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -75,6 +76,17 @@ func (r GQLRelease) IsLTS() bool {
7576
return regexp.MustCompile("^> LTS").MatchString(r.Description)
7677
}
7778

79+
// ExtendedMonths returns the number of additional months this release's lifetime is extended by,
80+
// as specified by a `> ExtensionMonths: N` line in the description. Returns 0 if not set.
81+
func (r GQLRelease) ExtendedMonths() int {
82+
res := regexp.MustCompile(`(?m)^> ExtensionMonths: ([0-9]+)`).FindStringSubmatch(r.Description)
83+
if len(res) == 2 {
84+
n, _ := strconv.Atoi(res[1])
85+
return n
86+
}
87+
return 0
88+
}
89+
7890
// Branch branch that this release was first on
7991
func (r GQLRelease) Branch() string {
8092
// In theory we could extract this from the tag but let's keep this simple

cmd/internal/versionfile/version_file.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ import (
1313
)
1414

1515
type VersionEntry struct {
16-
Edition string `yaml:"edition"`
17-
Version string `yaml:"version"`
18-
Release string `yaml:"release"`
19-
Latest bool `yaml:"latest,omitempty"`
20-
ReleaseDate string `yaml:"releaseDate,omitempty"`
21-
EndOfLifeDate string `yaml:"endOfLifeDate,omitempty"`
22-
Branch string `yaml:"branch"`
23-
Label string `yaml:"label,omitempty"`
24-
LTS bool `yaml:"lts,omitempty"`
16+
Edition string `yaml:"edition"`
17+
Version string `yaml:"version"`
18+
Release string `yaml:"release"`
19+
Latest bool `yaml:"latest,omitempty"`
20+
ReleaseDate string `yaml:"releaseDate,omitempty"`
21+
EndOfLifeDate string `yaml:"endOfLifeDate,omitempty"`
22+
Branch string `yaml:"branch"`
23+
Label string `yaml:"label,omitempty"`
24+
LTS bool `yaml:"lts,omitempty"`
25+
ExtensionMonths int `yaml:"extensionMonths,omitempty"`
2526
}
2627

2728
func (v VersionEntry) Less(o VersionEntry) bool {
@@ -50,6 +51,10 @@ func BuildVersionEntry(edition string, releaseName string, lifetimeMonths int, l
5051
out.LTS = true
5152
lifetime = ltslifetimeMonths
5253
}
54+
if ext := releases[0].ExtendedMonths(); ext > 0 {
55+
lifetime += ext
56+
out.ExtensionMonths = ext
57+
}
5358
releaseDate, err := releases[0].ExtractReleaseDate()
5459
if err != nil {
5560
return out, fmt.Errorf("failed to extract release date for %s because of: %s", releases[0].Name, err.Error())

cmd/internal/versionfile/version_file_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,37 @@ func TestBuildVersionEntry(t *testing.T) {
9696
},
9797
versionfile.VersionEntry{Edition: "mesh", Version: "1.2.1", Release: "1.2.x", Latest: true, ReleaseDate: "2020-12-12", EndOfLifeDate: "2021-12-12", Branch: "release-1.2"},
9898
),
99+
simpleCase(
100+
"extended adds months on top of regular lifetime",
101+
[]github.GQLRelease{
102+
{Name: "1.2.0", Description: "> ExtensionMonths: 6", PublishedAt: d1},
103+
{Name: "1.2.1", PublishedAt: d1.Add(time.Hour * 24 * 8), IsLatest: true},
104+
},
105+
versionfile.VersionEntry{Edition: "mesh", Version: "1.2.1", Release: "1.2.x", Latest: true, ReleaseDate: "2020-12-12", EndOfLifeDate: "2022-06-12", Branch: "release-1.2", ExtensionMonths: 6},
106+
),
107+
simpleCase(
108+
"extended combined with lts adds months on top of lts lifetime",
109+
[]github.GQLRelease{
110+
{Name: "1.2.0", Description: "> LTS\n> ExtensionMonths: 6", PublishedAt: d1},
111+
{Name: "1.2.1", PublishedAt: d1.Add(time.Hour * 48)},
112+
},
113+
versionfile.VersionEntry{Edition: "mesh", Version: "1.2.1", Release: "1.2.x", LTS: true, ReleaseDate: "2020-12-12", EndOfLifeDate: "2023-06-12", Branch: "release-1.2", ExtensionMonths: 6},
114+
),
115+
simpleCase(
116+
"extended combined with custom release date",
117+
[]github.GQLRelease{
118+
{Name: "1.2.0", Description: "> Released on 2019/01/01\n> ExtensionMonths: 6"},
119+
},
120+
versionfile.VersionEntry{Edition: "mesh", Version: "1.2.0", Release: "1.2.x", ReleaseDate: "2019-01-01", EndOfLifeDate: "2020-07-01", Branch: "release-1.2", ExtensionMonths: 6},
121+
),
122+
simpleCase(
123+
"extended on non-first release is ignored",
124+
[]github.GQLRelease{
125+
{Name: "1.2.1", Description: "> ExtensionMonths: 6", PublishedAt: d1.Add(time.Hour * 48)},
126+
{Name: "1.2.0", Description: "foo", PublishedAt: d1},
127+
},
128+
versionfile.VersionEntry{Edition: "mesh", Version: "1.2.1", Release: "1.2.x", ReleaseDate: "2020-12-12", EndOfLifeDate: "2021-12-12", Branch: "release-1.2"},
129+
),
99130
} {
100131
t.Run(v.desc, func(t *testing.T) {
101132
res, err := versionfile.BuildVersionEntry(v.inEdition, v.inReleaseName, v.inLifetimeMonths, v.inLtsLifetimeMonths, v.inReleases)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/kumahq/ci-tools
22

3-
go 1.25.1
3+
go 1.26.0
44

55
require (
66
github.com/Masterminds/semver/v3 v3.4.0

mise.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[tools]
2-
golangci-lint = "2.6.2"
2+
golangci-lint = "2.9.0"

0 commit comments

Comments
 (0)