Skip to content

Commit dbb94ec

Browse files
authored
Merge pull request #6 from xmudrii/bot-changes
Implement required patches for kcp
2 parents f3351d3 + 98bc8f1 commit dbb94ec

File tree

6 files changed

+59
-17
lines changed

6 files changed

+59
-17
lines changed

artifacts/scripts/construct.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ set -o nounset
3737
set -o pipefail
3838
set -o xtrace
3939

40-
if [ ! $# -eq 15 ]; then
41-
echo "usage: $0 repo src_branch dst_branch dependent_k8s.io_repos required_packages kubernetes_remote subdirectories source_repo_org source_repo_name base_package is_library recursive_delete_pattern skip_tags last_published_upstream_hash git_default_branch"
40+
if [ ! $# -eq 17 ]; then
41+
echo "usage: $0 repo src_branch dst_branch dependent_k8s.io_repos required_packages kubernetes_remote subdirectories source_repo_org source_repo_name base_package is_library recursive_delete_pattern skip_tags skip_non_semver_tags semver_tags_base last_published_upstream_hash git_default_branch"
4242
exit 1
4343
fi
4444

@@ -72,12 +72,16 @@ IS_LIBRARY="${2}"
7272
RECURSIVE_DELETE_PATTERN="${3}"
7373
# Skip syncing tags
7474
SKIP_TAGS="${4}"
75+
# Skip tags that do not start with 'v'
76+
SKIP_NON_SEMVER_TAGS="${5}"
77+
# Major version to use for building the tag (e.g. v1, v2...)
78+
SEMVER_TAGS_BASE="${6}"
7579
# last published upstream hash of this branch
76-
LAST_PUBLISHED_UPSTREAM_HASH="${5}"
80+
LAST_PUBLISHED_UPSTREAM_HASH="${7}"
7781
# name of the main branch. master for k8s.io/kubernetes
78-
GIT_DEFAULT_BRANCH="${6}"
82+
GIT_DEFAULT_BRANCH="${8}"
7983

80-
readonly REPO SRC_BRANCH DST_BRANCH DEPS REQUIRED SOURCE_REMOTE SOURCE_REPO_ORG SUBDIRS SOURCE_REPO_NAME BASE_PACKAGE IS_LIBRARY RECURSIVE_DELETE_PATTERN SKIP_TAGS LAST_PUBLISHED_UPSTREAM_HASH GIT_DEFAULT_BRANCH
84+
readonly REPO SRC_BRANCH DST_BRANCH DEPS REQUIRED SOURCE_REMOTE SOURCE_REPO_ORG SUBDIRS SOURCE_REPO_NAME BASE_PACKAGE IS_LIBRARY RECURSIVE_DELETE_PATTERN SKIP_TAGS SKIP_NON_SEMVER_TAGS SEMVER_TAGS_BASE LAST_PUBLISHED_UPSTREAM_HASH GIT_DEFAULT_BRANCH
8185

8286
SCRIPT_DIR=$(dirname "${BASH_SOURCE}")
8387
source "${SCRIPT_DIR}"/util.sh
@@ -177,7 +181,9 @@ if [ -z "${SKIP_TAGS}" ]; then
177181
--push-script ${PUSH_SCRIPT} \
178182
--dependencies "${DEPS}" \
179183
--mapping-output-file "../tag-${REPO}-{{.Tag}}-mapping" \
180-
--publish-v0-semver \
184+
--publish-semver-tags \
185+
--skip-non-semver-tags="${SKIP_NON_SEMVER_TAGS}" \
186+
--semver-tags-base "${SEMVER_TAGS_BASE}" \
181187
-alsologtostderr \
182188
"${EXTRA_ARGS[@]-}"
183189
if [ "${LAST_HEAD}" != "$(git rev-parse ${LAST_BRANCH})" ]; then

artifacts/scripts/util.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ sync_repo() {
171171
local f_mainline_commits=""
172172
if [ "${new_branch}" = "true" ] && [ "${src_branch}" = "${git_default_branch}" ]; then
173173
# new master branch
174-
filter-branch "${commit_msg_tag}" "${subdirectories}" "${recursive_delete_pattern}" ${src_branch} filtered-branch
174+
filter-branch "${commit_msg_tag}" "${subdirectories}" "${recursive_delete_pattern}" "upstream/${src_branch}" filtered-branch
175175

176176
# find commits on the main line (will mostly be merges, but could be non-merges if filter-branch dropped
177177
# the corresponding fast-forward merge and left the feature branch commits)

cmd/publishing-bot/config/rules.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ type BranchRule struct {
7373
type RepositoryRule struct {
7474
DestinationRepository string `yaml:"destination"`
7575
Branches []BranchRule `yaml:"branches"`
76+
// the value to use as vX in vX.Y.Z published at the destination repo
77+
DestinationTagBase string `yaml:"destination-tag-base,omitempty"`
7678
// SmokeTest applies to all branches
7779
SmokeTest string `yaml:"smoke-test,omitempty"` // a multiline bash script
7880
Library bool `yaml:"library,omitempty"`
@@ -81,10 +83,13 @@ type RepositoryRule struct {
8183
}
8284

8385
type RepositoryRules struct {
84-
SkippedSourceBranches []string `yaml:"skip-source-branches,omitempty"`
85-
SkipGomod bool `yaml:"skip-gomod,omitempty"`
86-
SkipTags bool `yaml:"skip-tags,omitempty"`
87-
Rules []RepositoryRule `yaml:"rules"`
86+
SkippedSourceBranches []string `yaml:"skip-source-branches,omitempty"`
87+
SkipGomod bool `yaml:"skip-gomod,omitempty"`
88+
SkipTags bool `yaml:"skip-tags,omitempty"`
89+
// this skips tags in the source repo that are not valid semver tags
90+
// e.g. v1.2.3 is valid, but <prefix>/v1.2.3 is not valid.
91+
SkipNonSemverTags bool `yaml:"skip-non-semver-tags,omitempty"`
92+
Rules []RepositoryRule `yaml:"rules"`
8893

8994
// ls-files patterns like: */BUILD *.ext pkg/foo.go Makefile
9095
RecursiveDeletePatterns []string `yaml:"recursive-delete-patterns"`

cmd/publishing-bot/publisher.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ func (p *PublisherMunger) construct() error {
292292
p.plog.Infof("synchronizing tags is disabled")
293293
}
294294

295+
skipNonSemverTags := "false"
296+
if p.reposRules.SkipNonSemverTags {
297+
skipNonSemverTags = "true"
298+
p.plog.Infof("synchronizing non-semver tags is disabled")
299+
}
300+
295301
// get old published hash to eventually skip cherry picking
296302
var lastPublishedUpstreamHash string
297303
bs, err := os.ReadFile(path.Join(p.baseRepoPath, publishedFileName(repoRule.DestinationRepository, branchRule.Name)))
@@ -318,6 +324,8 @@ func (p *PublisherMunger) construct() error {
318324
strconv.FormatBool(repoRule.Library),
319325
strings.Join(p.reposRules.RecursiveDeletePatterns, " "),
320326
skipTags,
327+
skipNonSemverTags,
328+
repoRule.DestinationTagBase,
321329
lastPublishedUpstreamHash,
322330
p.config.GitDefaultBranch,
323331
)

cmd/sync-tags/main.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"io"
2525
"os"
2626
"os/exec"
27+
"regexp"
2728
"strings"
2829
"text/template"
2930
"time"
@@ -78,7 +79,10 @@ func main() {
7879
dependencies := flag.String("dependencies", "", "comma-separated list of repo:branch pairs of dependencies")
7980
skipFetch := flag.Bool("skip-fetch", false, "skip fetching tags")
8081
mappingOutputFile := flag.String("mapping-output-file", "", "a file name to write the source->dest hash mapping to ({{.Tag}} is substituted with the tag name, {{.Branch}} with the local branch name)")
81-
publishSemverTags := flag.Bool("publish-v0-semver", false, "publish v0.x.y tag at destination repo for v1.x.y tag at the source repo")
82+
publishV0Semver := flag.Bool("publish-v0-semver", false, "publish v0.x.y tag at destination repo for v1.x.y tag at the source repo")
83+
publishSemverTags := flag.Bool("publish-semver-tags", false, "publish vX.Y.Z tag at destination repo for vX.Y.Z tag at the source repo")
84+
skipNonSemverTags := flag.Bool("skip-non-semver-tags", false, "skip non-semver tags at the source repo")
85+
semverTagsBase := flag.String("semver-tags-base", "v0", "the value to use as vX in vX.Y.Z published at the destination repo")
8286

8387
flag.Usage = Usage
8488
flag.Parse()
@@ -91,6 +95,10 @@ func main() {
9195
glog.Fatalf("source-branch cannot be empty")
9296
}
9397

98+
if *publishV0Semver && *publishSemverTags {
99+
glog.Fatalf("only one of publish-v0-semver and publish-semver-tags can be true")
100+
}
101+
94102
var dependentRepos []string
95103
if *dependencies != "" {
96104
for _, pair := range strings.Split(*dependencies, ",") {
@@ -188,23 +196,37 @@ func main() {
188196
// create or update tags from srcTagCommits as local tags with the given prefix
189197
createdTags := []string{}
190198
for name, kh := range srcTagCommits {
199+
if *skipNonSemverTags {
200+
if _, semverErr := semver.Parse(strings.TrimPrefix(name, "v")); semverErr != nil {
201+
continue
202+
}
203+
}
204+
191205
bName := name
192206
if *prefix != "" {
193207
bName = *prefix + name[1:] // remove the v
194208
}
195209

196210
var (
197-
semverTag = ""
198-
publishSemverTag = false
211+
semverTag = ""
212+
publishSemverTag = false
213+
versionPrefixRegex = regexp.MustCompile(`^v\d+\.`)
199214
)
200215
// if we are publishing semver tags
201-
if *publishSemverTags {
216+
if *publishV0Semver {
202217
// and this is a valid v1... semver tag
203218
if _, semverErr := semver.Parse(name[1:]); semverErr == nil && strings.HasPrefix(name, "v1.") {
204219
publishSemverTag = true
205220
semverTag = "v0." + strings.TrimPrefix(name, "v1.") // replace v1.x.y with v0.x.y
206221
}
207222
}
223+
if *publishSemverTags {
224+
// and this is a valid semver tag
225+
if _, semverErr := semver.Parse(strings.TrimPrefix(name, "v")); semverErr == nil {
226+
publishSemverTag = true
227+
semverTag = *semverTagsBase + "." + versionPrefixRegex.ReplaceAllString(name, "")
228+
}
229+
}
208230

209231
// ignore non-annotated tags
210232
tag, err := r.TagObject(kh)
@@ -291,7 +313,7 @@ func main() {
291313
fmt.Printf("Writing source->dest hash mapping to %q\n", fname)
292314
f, err := os.Create(fname)
293315
if err != nil {
294-
glog.Fatal(f)
316+
glog.Fatal(err)
295317
}
296318
if err := writeKubeCommitMapping(f, sourceCommitsToDstCommits, srcFirstParents); err != nil {
297319
glog.Fatal(err)

pkg/golang/install.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222
"os/exec"
2323
"path/filepath"
24+
"runtime"
2425
"strings"
2526

2627
"github.com/golang/glog"
@@ -95,7 +96,7 @@ func installGoVersion(v, pth string) error {
9596
}
9697
defer os.RemoveAll(tmpPath)
9798

98-
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("curl -SLf https://storage.googleapis.com/golang/go%s.linux-amd64.tar.gz | tar -xz --strip 1 -C %s", v, tmpPath))
99+
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("curl -SLf https://storage.googleapis.com/golang/go%s.%s-%s.tar.gz | tar -xz --strip 1 -C %s", v, runtime.GOOS, runtime.GOARCH, tmpPath))
99100
cmd.Dir = tmpPath
100101
cmd.Stdout = os.Stdout
101102
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)