Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates and fixes #62

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go 1.20
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'
go-version-file: 'go.mod'
cache: false

- name: Lint
uses: golangci/golangci-lint-action@v3
Expand Down
56 changes: 26 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
module github.com/metal-stack/metal-robot

go 1.20
go 1.21

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/atedja/go-multilock v0.0.0-20170315063113-31d195f255fb
github.com/blang/semver/v4 v4.0.0
github.com/bradleyfalzon/ghinstallation/v2 v2.6.0
github.com/go-git/go-billy/v5 v5.4.1
github.com/bradleyfalzon/ghinstallation/v2 v2.8.0
github.com/go-git/go-billy/v5 v5.5.0
// IMPORTANT: keep this version as long as https://github.com/go-git/go-git/issues/328 is open
github.com/go-git/go-git/v5 v5.3.0
github.com/go-playground/validator/v10 v10.14.1
github.com/go-playground/webhooks/v6 v6.2.0
github.com/google/go-cmp v0.5.9
github.com/google/go-github/v53 v53.2.0
github.com/go-playground/validator/v10 v10.15.5
github.com/go-playground/webhooks/v6 v6.3.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v56 v56.0.0
github.com/metal-stack/v v1.0.3
github.com/mitchellh/mapstructure v1.5.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/tidwall/gjson v1.15.0
github.com/spf13/viper v1.17.0
github.com/tidwall/gjson v1.17.0
github.com/tidwall/sjson v1.2.5
go.uber.org/zap v1.24.0
golang.org/x/sync v0.3.0
go.uber.org/zap v1.26.0
golang.org/x/sync v0.4.0
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230426101702-58e86b294756 // indirect
github.com/benbjohnson/clock v1.3.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
Expand All @@ -46,27 +43,26 @@ require (
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
171 changes: 67 additions & 104 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/clients/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/metal-stack/metal-robot/pkg/config"
"go.uber.org/zap"

v3 "github.com/google/go-github/v53/github"
v3 "github.com/google/go-github/v56/github"
)

type Github struct {
Expand Down
15 changes: 10 additions & 5 deletions pkg/webhooks/github/actions/aggregate_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"errors"

"github.com/Masterminds/semver/v3"
"github.com/atedja/go-multilock"
"github.com/blang/semver/v4"
v3 "github.com/google/go-github/v53/github"
v3 "github.com/google/go-github/v56/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/metal-stack/metal-robot/pkg/git"
Expand Down Expand Up @@ -62,13 +62,13 @@ func NewAggregateReleases(logger *zap.SugaredLogger, client *clients.Github, raw
if typedConfig.Branch != nil {
branch = *typedConfig.Branch
}
if typedConfig.BranchBase != nil {
if typedConfig.BranchBase != nil && *typedConfig.BranchBase != "" {
branchBase = *typedConfig.BranchBase
}
if typedConfig.CommitMsgTemplate != nil {
commitMessageTemplate = *typedConfig.CommitMsgTemplate
}
if typedConfig.PullRequestTitle != nil {
if typedConfig.PullRequestTitle != nil && *typedConfig.PullRequestTitle != "" {
pullRequestTitle = *typedConfig.PullRequestTitle
}

Expand Down Expand Up @@ -113,12 +113,17 @@ func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateRe

tag := p.TagName
trimmed := strings.TrimPrefix(tag, "v")
_, err := semver.Make(trimmed)
parsedVersion, err := semver.NewVersion(trimmed)
if err != nil {
r.logger.Infow("skip applying release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName)
return nil //nolint:nilerr
}

if parsedVersion.Prerelease() != "" {
r.logger.Infow("skip applying release actions to aggregation repo because is a pre-release", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName)
return nil //nolint:nilerr
}

// preventing concurrent git repo modifications
var once sync.Once
r.lock.Lock()
Expand Down
10 changes: 5 additions & 5 deletions pkg/webhooks/github/actions/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func InitActions(logger *zap.SugaredLogger, cs clients.ClientMap, config config.
func (w *WebhookActions) ProcessReleaseEvent(ctx context.Context, payload *ghwebhooks.ReleasePayload) {
ctx, cancel := context.WithTimeout(ctx, constants.WebhookHandleTimeout)
defer cancel()
g, ctx := errgroup.WithContext(ctx)
g, _ := errgroup.WithContext(ctx)

for _, a := range w.ar {
a := a
Expand Down Expand Up @@ -182,7 +182,7 @@ func (w *WebhookActions) ProcessReleaseEvent(ctx context.Context, payload *ghweb
func (w *WebhookActions) ProcessPullRequestEvent(ctx context.Context, payload *ghwebhooks.PullRequestPayload) {
ctx, cancel := context.WithTimeout(ctx, constants.WebhookHandleTimeout)
defer cancel()
g, ctx := errgroup.WithContext(ctx)
g, _ := errgroup.WithContext(ctx)

for _, a := range w.dp {
a := a
Expand Down Expand Up @@ -238,7 +238,7 @@ func (w *WebhookActions) ProcessPullRequestEvent(ctx context.Context, payload *g
func (w *WebhookActions) ProcessPushEvent(ctx context.Context, payload *ghwebhooks.PushPayload) {
ctx, cancel := context.WithTimeout(ctx, constants.WebhookHandleTimeout)
defer cancel()
g, ctx := errgroup.WithContext(ctx)
g, _ := errgroup.WithContext(ctx)

for _, a := range w.ar {
a := a
Expand Down Expand Up @@ -291,7 +291,7 @@ func (w *WebhookActions) ProcessPushEvent(ctx context.Context, payload *ghwebhoo
func (w *WebhookActions) ProcessRepositoryEvent(ctx context.Context, payload *ghwebhooks.RepositoryPayload) {
ctx, cancel := context.WithTimeout(ctx, constants.WebhookHandleTimeout)
defer cancel()
g, ctx := errgroup.WithContext(ctx)
g, _ := errgroup.WithContext(ctx)

for _, a := range w.rm {
a := a
Expand Down Expand Up @@ -322,7 +322,7 @@ func (w *WebhookActions) ProcessRepositoryEvent(ctx context.Context, payload *gh
func (w *WebhookActions) ProcessIssueCommentEvent(ctx context.Context, payload *ghwebhooks.IssueCommentPayload) {
ctx, cancel := context.WithTimeout(ctx, constants.WebhookHandleTimeout)
defer cancel()
g, ctx := errgroup.WithContext(ctx)
g, _ := errgroup.WithContext(ctx)

for _, i := range w.ih {
i := i
Expand Down
8 changes: 4 additions & 4 deletions pkg/webhooks/github/actions/distribute_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"errors"

"github.com/atedja/go-multilock"
v3 "github.com/google/go-github/v53/github"
v3 "github.com/google/go-github/v56/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/metal-stack/metal-robot/pkg/git"
Expand Down Expand Up @@ -60,13 +60,13 @@ func newDistributeReleases(logger *zap.SugaredLogger, client *clients.Github, ra
if typedConfig.SourceRepositoryURL == "" {
return nil, fmt.Errorf("source repository-url must be specified")
}
if typedConfig.BranchTemplate != nil {
if typedConfig.BranchTemplate != nil && *typedConfig.BranchTemplate != "" {
branchTemplate = *typedConfig.BranchTemplate
}
if typedConfig.CommitMsgTemplate != nil {
commitMessageTemplate = *typedConfig.CommitMsgTemplate
}
if typedConfig.PullRequestTitle != nil {
if typedConfig.PullRequestTitle != nil && *typedConfig.PullRequestTitle != "" {
pullRequestTitle = *typedConfig.PullRequestTitle
}

Expand Down Expand Up @@ -124,7 +124,7 @@ func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distribut
}
lock := multilock.New(targetRepos...)

g, ctx := errgroup.WithContext(ctx)
g, _ := errgroup.WithContext(ctx)
for targetRepoName, targetRepo := range d.targetRepos {
targetRepoName := targetRepoName
targetRepo := targetRepo
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhooks/github/actions/docs_preview_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

v3 "github.com/google/go-github/v53/github"
v3 "github.com/google/go-github/v56/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/mitchellh/mapstructure"
Expand Down
19 changes: 9 additions & 10 deletions pkg/webhooks/github/actions/release_drafter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"regexp"
"strings"

"github.com/blang/semver/v4"
"github.com/google/go-github/v53/github"
"github.com/Masterminds/semver/v3"
"github.com/google/go-github/v56/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/metal-stack/metal-robot/pkg/markdown"
"github.com/metal-stack/metal-robot/pkg/utils"
"github.com/mitchellh/mapstructure"
"go.uber.org/zap"

v3 "github.com/google/go-github/v53/github"
v3 "github.com/google/go-github/v56/github"
)

var (
Expand Down Expand Up @@ -142,7 +142,7 @@ func (r *releaseDrafter) draft(ctx context.Context, p *releaseDrafterParams) err
return nil
}
trimmedVersion := strings.TrimPrefix(componentTag, "v")
componentSemver, err := semver.Parse(trimmedVersion)
componentSemver, err := semver.NewVersion(trimmedVersion)
if err != nil {
r.logger.Debugw("skip adding release draft because tag is not semver compatible", "repo", p.RepositoryName, "release", componentTag)
return nil //nolint:nilerr
Expand All @@ -158,7 +158,7 @@ func (r *releaseDrafter) draft(ctx context.Context, p *releaseDrafterParams) err
return r.createOrUpdateRelease(ctx, infos, body, p)
}

func (r *releaseDrafter) updateReleaseBody(org string, priorBody string, component string, componentVersion semver.Version, componentBody *string, releaseURL string) string {
func (r *releaseDrafter) updateReleaseBody(org string, priorBody string, component string, componentVersion *semver.Version, componentBody *string, releaseURL string) string {
m := markdown.Parse(priorBody)

releaseSection := ensureReleaseSection(m, r.draftHeadline)
Expand Down Expand Up @@ -213,8 +213,8 @@ func (r *releaseDrafter) updateReleaseBody(org string, priorBody string, compone
groups := utils.RegexCapture(utils.SemanticVersionMatcher, section.Heading)
old := groups["full_match"]
old = strings.TrimPrefix(old, "v")
oldVersion, err := semver.Parse(old)
if err == nil && componentVersion.GT(oldVersion) {
oldVersion, err := semver.NewVersion(old)
if err == nil && componentVersion.GreaterThan(oldVersion) {
// in this case we need to merge contents together and update the headline
section.Heading = heading
section.AppendContent(body)
Expand Down Expand Up @@ -404,12 +404,11 @@ func (r *releaseDrafter) guessNextVersionFromLatestRelease(ctx context.Context)
groups := utils.RegexCapture(utils.SemanticVersionMatcher, *latest.TagName)
t := groups["full_match"]
t = strings.TrimPrefix(t, "v")
latestTag, err := semver.Parse(t)
latestTag, err := semver.NewVersion(t)
if err != nil {
r.logger.Warnw("latest release of repository was not a semver tag", "repository", r.repoName, "latest-tag", *latest.TagName)
} else {
latestTag.Patch = latestTag.Patch + 1
return "v" + latestTag.String(), nil
return "v" + latestTag.IncPatch().String(), nil
}
}
return "v0.0.1", nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/webhooks/github/actions/release_drafter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package actions
import (
"testing"

"github.com/blang/semver/v4"
"github.com/Masterminds/semver/v3"
"github.com/google/go-cmp/cmp"
v3 "github.com/google/go-github/v53/github"
v3 "github.com/google/go-github/v56/github"
"go.uber.org/zap/zaptest"
)

Expand All @@ -16,7 +16,7 @@ func TestReleaseDrafter_updateReleaseBody(t *testing.T) {
headline string
priorBody string
component string
componentVersion semver.Version
componentVersion *semver.Version
componentBody *string
releaseURL string

Expand Down
2 changes: 1 addition & 1 deletion pkg/webhooks/github/actions/repository_maintainers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

v3 "github.com/google/go-github/v53/github"
v3 "github.com/google/go-github/v56/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/mitchellh/mapstructure"
Expand Down
6 changes: 3 additions & 3 deletions pkg/webhooks/github/actions/yaml_translate_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"errors"

"github.com/Masterminds/semver/v3"
"github.com/atedja/go-multilock"
"github.com/blang/semver/v4"
v3 "github.com/google/go-github/v53/github"
v3 "github.com/google/go-github/v56/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/metal-stack/metal-robot/pkg/git"
Expand Down Expand Up @@ -139,7 +139,7 @@ func (r *yamlTranslateReleases) translateRelease(ctx context.Context, p *yamlTra

tag := p.TagName
trimmed := strings.TrimPrefix(tag, "v")
_, err := semver.Make(trimmed)
_, err := semver.NewVersion(trimmed)
if err != nil {
r.logger.Infow("skip applying translate release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName)
return nil //nolint:nilerr
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhooks/gitlab/actions/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func InitActions(logger *zap.SugaredLogger, cs clients.ClientMap, config config.
func (w *WebhookActions) ProcessTagEvent(ctx context.Context, payload *glwebhooks.TagEventPayload) {
ctx, cancel := context.WithTimeout(ctx, constants.WebhookHandleTimeout)
defer cancel()
g, ctx := errgroup.WithContext(ctx)
g, _ := errgroup.WithContext(ctx)

for _, a := range w.ar {
a := a
Expand Down
Loading