Skip to content
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
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/VividCortex/ewma v1.1.1
github.com/alessio/shellescape v1.4.1
github.com/andy-kimball/arenaskl v0.0.0-20200617143215-f701008588b9
github.com/andygrunwald/go-jira v1.14.0
github.com/apache/arrow/go/arrow v0.0.0-20200923215132-ac86123a3f01
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
github.com/aws/aws-sdk-go v1.40.37
Expand Down Expand Up @@ -205,7 +204,6 @@ require (
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/djherbis/atime v1.1.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-kit/log v0.1.0 // indirect
Expand All @@ -226,7 +224,6 @@ require (
github.com/gofrs/flock v0.8.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand Down Expand Up @@ -301,7 +298,6 @@ require (
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
github.com/toqueteos/webbrowser v1.2.0 // indirect
github.com/trivago/tgo v1.0.7 // indirect
github.com/twitchtv/twirp v8.1.0+incompatible // indirect
github.com/twpayne/go-kml v1.5.2 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ github.com/andy-kimball/arenaskl v0.0.0-20200617143215-f701008588b9/go.mod h1:V2
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=
github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxBp0T0eFw1RUQY=
github.com/andygrunwald/go-jira v1.14.0 h1:7GT/3qhar2dGJ0kq8w0d63liNyHOnxZsUZ9Pe4+AKBI=
github.com/andygrunwald/go-jira v1.14.0/go.mod h1:KMo2f4DgMZA1C9FdImuLc04x4WQhn5derQpnsuBFgqE=
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ=
Expand Down Expand Up @@ -680,7 +678,6 @@ github.com/fanixk/geohash v0.0.0-20150324002647-c1f9b5fa157a/go.mod h1:UgNw+PTmm
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
Expand Down Expand Up @@ -946,8 +943,6 @@ github.com/golang-commonmark/mdurl v0.0.0-20180910110917-8d018c6567d6 h1:XkgfhPs
github.com/golang-commonmark/mdurl v0.0.0-20180910110917-8d018c6567d6/go.mod h1:J66ZGl/dC2mj4ElzGfrLUq0N90HvQoUbrYgYNJUjuMs=
github.com/golang-commonmark/puny v0.0.0-20180910110745-050be392d8b8 h1:DUgQdQmDg4sk4SfNR+qOkXcopGz36BL02vp/V7WbPQI=
github.com/golang-commonmark/puny v0.0.0-20180910110745-050be392d8b8/go.mod h1:/8a6mcbf/Hwg6MjnHHp5vqCWw0Bsves9HLPObHAj7XA=
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.0.0 h1:RAqyYixv1p7uEnocuy8P1nru5wprCh/MH2BIlW5z5/o=
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
Expand Down Expand Up @@ -1031,7 +1026,6 @@ github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+u
github.com/google/go-github/v27 v27.0.4/go.mod h1:/0Gr8pJ55COkmv+S/yPKCczSkUPIM/LnFyubufRNIS0=
github.com/google/go-github/v42 v42.0.0 h1:YNT0FwjPrEysRkLIiKuEfSvBPCGKphW5aS5PxwaoLec=
github.com/google/go-github/v42 v42.0.0/go.mod h1:jgg/jvyI0YlDOM1/ps6XYh04HNQ3vKf0CVko62/EhRg=
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
Expand Down Expand Up @@ -2013,8 +2007,6 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/toqueteos/webbrowser v1.2.0 h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
github.com/trivago/tgo v1.0.7 h1:uaWH/XIy9aWYWpjm2CU3RpcqZXmX2ysQ9/Go+d9gyrM=
github.com/trivago/tgo v1.0.7/go.mod h1:w4dpD+3tzNIIiIfkWWa85w5/B77tlvdZckQ+6PkFnhc=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/twitchtv/twirp v8.1.0+incompatible h1:KGXanpa9LXdVE/V5P/tA27rkKFmXRGCtSNT7zdeeVOY=
github.com/twitchtv/twirp v8.1.0+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A=
Expand Down
128 changes: 0 additions & 128 deletions pkg/cmd/release/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,14 @@
package main

import (
"context"
"fmt"
"os/exec"
"regexp"
"sort"
"strings"

"github.com/Masterminds/semver/v3"
)

type releaseInfo struct {
prevReleaseVersion string
nextReleaseVersion string
buildInfo buildInfo
// candidateCommits contains all merge commits that can be considered as release candidates
candidateCommits []string
// releaseSeries represents the major release prefix, e.g. 21.2
releaseSeries string
}

// findNextVersion returns the next release version for given releaseSeries.
func findNextVersion(releaseSeries string) (string, error) {
prevReleaseVersion, err := findPreviousRelease(releaseSeries)
Expand All @@ -44,54 +32,6 @@ func findNextVersion(releaseSeries string) (string, error) {
return nextReleaseVersion, nil
}

// findNextRelease finds all required information for the next release.
func findNextRelease(releaseSeries string) (releaseInfo, error) {
prevReleaseVersion, err := findPreviousRelease(releaseSeries)
if err != nil {
return releaseInfo{}, fmt.Errorf("cannot find previous release: %w", err)
}
nextReleaseVersion, err := bumpVersion(prevReleaseVersion)
if err != nil {
return releaseInfo{}, fmt.Errorf("cannot bump version: %w", err)
}
candidateCommits, err := findCandidateCommits(prevReleaseVersion, releaseSeries)
if err != nil {
return releaseInfo{}, fmt.Errorf("cannot find candidate commits: %w", err)
}
info, err := findHealthyBuild(candidateCommits)
if err != nil {
return releaseInfo{}, fmt.Errorf("cannot find healthy build: %w", err)
}
releasedVersions, err := getVersionsContainingRef(info.SHA)
if err != nil {
return releaseInfo{}, fmt.Errorf("cannot check if the candidate sha was released: %w", err)
}
if len(releasedVersions) > 0 {
return releaseInfo{}, fmt.Errorf("%s has been already released as a part of the following tags: %s",
info.SHA, strings.Join(releasedVersions, ", "))
}
return releaseInfo{
prevReleaseVersion: prevReleaseVersion,
nextReleaseVersion: nextReleaseVersion,
buildInfo: info,
candidateCommits: candidateCommits,
releaseSeries: releaseSeries,
}, nil
}

func getVersionsContainingRef(ref string) ([]string, error) {
cmd := exec.Command("git", "tag", "--contains", ref)
out, err := cmd.Output()
if err != nil {
return []string{}, fmt.Errorf("cannot list tags containing %s: %w", ref, err)
}
var versions []string
for _, v := range findVersions(string(out)) {
versions = append(versions, v.Original())
}
return versions, nil
}

func findVersions(text string) []*semver.Version {
var versions []*semver.Version
for _, line := range strings.Split(text, "\n") {
Expand Down Expand Up @@ -139,71 +79,3 @@ func bumpVersion(version string) (string, error) {
nextVersion := semanticVersion.IncPatch()
return nextVersion.Original(), nil
}

// filterPullRequests finds commits with a particular merge pattern in the commit message.
// GitHub uses "Merge pull request #NNN" and Bors uses "Merge #NNN" in the generated commit messages.
func filterPullRequests(text string) []string {
var shas []string
matchMerge := regexp.MustCompile(`Merge (#|pull request)`)
for _, line := range strings.Split(text, "\n") {
if !matchMerge.MatchString(line) {
continue
}
sha := strings.Fields(line)[0]
shas = append(shas, sha)
}
return shas
}

// getMergeCommits lists all merge commits within a range of two refs.
func getMergeCommits(fromRef, toRef string) ([]string, error) {
cmd := exec.Command("git", "log", "--merges", "--format=format:%H %s", "--ancestry-path",
fmt.Sprintf("%s..%s", fromRef, toRef))
out, err := cmd.Output()
if err != nil {
return []string{}, fmt.Errorf("cannot read git log output: %w", err)
}
return filterPullRequests(string(out)), nil
}

func getCommonBaseRef(fromRef, toRef string) (string, error) {
cmd := exec.Command("git", "merge-base", fromRef, toRef)
out, err := cmd.Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(out)), nil
}

// findCandidateCommits finds all potential merge commits that can be used for the current release.
// It includes all merge commits since previous release.
func findCandidateCommits(prevRelease string, releaseSeries string) ([]string, error) {
releaseBranch := fmt.Sprintf("origin/release-%s", releaseSeries)
commonBaseRef, err := getCommonBaseRef(prevRelease, releaseBranch)
if err != nil {
return []string{}, fmt.Errorf("cannot find common base ref: %w", err)
}
refs, err := getMergeCommits(commonBaseRef, releaseBranch)
if err != nil {
return []string{}, fmt.Errorf("cannot get merge commits: %w", err)
}
return refs, nil
}

// findHealthyBuild walks all potentials merge commits in reverse order and tries to find the latest healthy build.
// The assumption is that every healthy build has a corresponding metadata file published to the release
// qualification bucket.
func findHealthyBuild(potentialRefs []string) (buildInfo, error) {
for _, ref := range potentialRefs {
fmt.Println("Fetching release qualification metadata for", ref)
meta, err := getBuildInfo(context.Background(), pickSHAFlags.qualifyBucket,
fmt.Sprintf("%s/%s.json", pickSHAFlags.qualifyObjectPrefix, ref))
if err != nil {
// TODO: retry if error is not 404
fmt.Println("no metadata qualification for", ref, err)
continue
}
return meta, nil
}
return buildInfo{}, fmt.Errorf("no ref found")
}
Loading