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

fix: bump go-ci to v0.6.1 #52

Merged
merged 1 commit into from
Oct 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.17
require (
github.com/go-logr/logr v0.4.0
github.com/magefile/mage v1.14.0
github.com/mt-sre/go-ci v0.4.0
github.com/mt-sre/go-ci v0.6.1
github.com/onsi/ginkgo/v2 v2.2.0
github.com/onsi/gomega v1.20.1
github.com/onsi/gomega v1.21.1
github.com/operator-framework/api v0.10.7
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.8.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mt-sre/go-ci v0.4.0 h1:9ukF1DJr+OiwtDo+AVHd6ZCxFgkpxTh0+dW2gCecSgo=
github.com/mt-sre/go-ci v0.4.0/go.mod h1:z5TRo2gmer7QEwhN52OvpZ393XR9eur0X6r8GwHsb0o=
github.com/mt-sre/go-ci v0.6.1 h1:9yas9JkSO7r8sRLvXqahpdPUe9fT3ASJPJDVInQCT/0=
github.com/mt-sre/go-ci v0.6.1/go.mod h1:Rhc+vQ+8uOiIhFJ6Pnyas4UB29BJsxmLKGmLCmzEi5s=
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
Expand All @@ -407,8 +407,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q=
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/onsi/gomega v1.21.1 h1:OB/euWYIExnPBohllTicTHmGTrMaqJ67nIu80j0/uEM=
github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/operator-framework/api v0.10.7 h1:GlZJ6m+0WSVdSsSjTbhKKAvHXamWJXhwXHUhVwL8LBE=
github.com/operator-framework/api v0.10.7/go.mod h1:PtQSNSuVrhSC6YE6JJJZv3nnZJc32osKX8FmFUZK05U=
Expand Down
109 changes: 36 additions & 73 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

Expand All @@ -20,6 +19,7 @@ import (
"github.com/mt-sre/go-ci/command"
"github.com/mt-sre/go-ci/container"
"github.com/mt-sre/go-ci/web"
"github.com/mt-sre/go-ci/git"
)

var Aliases = map[string]interface{}{
Expand Down Expand Up @@ -96,13 +96,14 @@ var _projectRoot = func() string {
return root
}

topLevel := git(command.WithArgs{"rev-parse", "--show-toplevel"})

if err := topLevel.Run(); err != nil || !topLevel.Success() {
panic("failed to get working directory")
root, err := git.RevParse(context.Background(),
git.WithRevParseFormat(git.RevParseFormatTopLevel),
)
if err != nil {
panic(err)
}

return strings.TrimSpace(topLevel.Stdout())
return root
}()

var _module = func() string {
Expand All @@ -128,55 +129,38 @@ var _version = func() string {
return bundleVersion
}

listTags := git(command.WithArgs{"tag", "-l"})

if err := listTags.Run(); err != nil || !listTags.Success() {
panic("failed to get tags")
}

tags := strings.Fields(listTags.Stdout())
if len(tags) < 1 {
return zeroVer
}

latest := tags[len(tags)-1]

commitCount := git(command.WithArgs{"rev-list", latest + "..", "--count"})

if err := commitCount.Run(); err != nil || !commitCount.Success() {
return zeroVer
}

count, err := strconv.Atoi(strings.TrimSpace(commitCount.Stdout()))
latest, err := git.LatestVersion(context.Background())
if err != nil {
return zeroVer
}
if errors.Is(err, git.ErrNoTagsFound) {
return zeroVer
}

if count < 1 {
return latest
panic(err)
}

return fmt.Sprintf("%s-%d", latest, count)
return latest+"-"+_shortSHA
}()

var _branch = func() string {
branch := git(command.WithArgs{"rev-parse", "--abbrev-ref", "HEAD"})

if err := branch.Run(); err != nil || !branch.Success() {
panic("failed to get current branch")
branch, err := git.RevParse(context.Background(),
git.WithRevParseFormat(git.RevParseFormatAbbrevRef),
)
if err != nil {
panic(err)
}

return strings.TrimSpace(branch.Stdout())
return branch
}()

var _shortSHA = func() string {
sha := git(command.WithArgs{"rev-parse", "--short", "HEAD"})

if err := sha.Run(); err != nil || !sha.Success() {
panic("failed to get short SHA")
short, err := git.RevParse(context.Background(),
git.WithRevParseFormat(git.RevParseFormatShort),
)
if err != nil {
panic(err)
}

return strings.TrimSpace(sha.Stdout())
return short
}()

var _taggedManagerImage = _managerImageReference + ":" + _version
Expand All @@ -189,8 +173,6 @@ var _managerImageReference = func() string {
return "quay.io/app-sre/reference-addon-manager"
}()

var git = command.NewCommandAlias("git")

type Deps mg.Namespace

func (Deps) DownloadSource(ctx context.Context) error {
Expand Down Expand Up @@ -559,44 +541,25 @@ func (Check) Verify(ctx context.Context) error {
// Dirty checks if the git repository has
// uncommitted changes.
func (Check) Dirty(ctx context.Context) error {
status := git(
command.WithArgs{"status", "--porcelain"},
status, err := git.Status(ctx,
git.WithStatusFormat(git.StatusFormatPorcelain),
)

if err := status.Run(); err != nil {
return fmt.Errorf("starting to check git status: %w", err)
}

if !status.Success() {
return fmt.Errorf("checking git status: %w", status.Error())
if err != nil {
return fmt.Errorf("getting git status: %w", err)
}

if out := status.Stdout(); out != "" {
if diff, err := getDiff(ctx); err == nil {
fmt.Fprintln(os.Stdout, diff)
}

return errors.New("repo is dirty")
if status == "" {
return nil
}

return nil
}

func getDiff(ctx context.Context) (string, error) {
diff := git(
command.WithContext{Context: ctx},
command.WithArgs{"diff", "--name-status"},
diff, err := git.Diff(ctx,
git.WithDiffFormat(git.DiffFormatNameStatus),
)

if err := diff.Run(); err != nil {
return "", fmt.Errorf("starting to get diff: %w", err)
}

if !diff.Success() {
return "", fmt.Errorf("getting diff: %w", diff.Error())
if err == nil {
fmt.Fprintln(os.Stdout, diff)
}

return strings.TrimSpace(diff.Stdout()), nil
return errors.New("repo is dirty")
}

type Test mg.Namespace
Expand Down