forked from knative/test-infra
/
main.go
80 lines (65 loc) · 2.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Copyright 2019 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// prow-auto-bumper finds stable Prow components version used by k8s,
// and creates PRs updating them in knative/test-infra
package main
import (
"flag"
"log"
"knative.dev/test-infra/shared/ghutil"
)
func main() {
githubAccount := flag.String("github-account", "", "Token file for Github authentication")
gitUserID := flag.String("git-userid", "", "The github ID of user for hosting fork, i.e. Github ID of bot")
gitUserName := flag.String("git-username", "", "The username to use on the git commit. Requires --git-email")
gitEmail := flag.String("git-email", "", "The email to use on the git commit. Requires --git-username")
dryrun := flag.Bool("dry-run", false, "dry run switch")
flag.Parse()
if nil != dryrun && true == *dryrun {
log.Println("Running in [dry run mode]")
}
gc, err := ghutil.NewGithubClient(*githubAccount)
if nil != err {
log.Fatalf("cannot authenticate to github: %v", err)
}
srcGI := gitInfo{
org: srcOrg,
repo: srcRepo,
head: srcPRHead,
base: srcPRBase,
userID: srcPRUserID,
}
targetGI := gitInfo{
org: org,
repo: repo,
head: PRHead,
base: PRBase,
userID: *gitUserID,
userName: *gitUserName,
email: *gitEmail,
}
gcw := &GHClientWrapper{gc}
bestVersion, err := retryGetBestVersion(gcw, srcGI)
if nil != err {
log.Fatalf("cannot get best version from %s/%s: '%v'", srcGI.org, srcGI.repo, err)
}
log.Printf("Found version to update. Old Version: '%s', New Version: '%s'",
bestVersion.dominantVersions.oldVersion, bestVersion.dominantVersions.newVersion)
msgs, err := bestVersion.updateAllFiles(fileFilters, imageRegexp, *dryrun)
if nil != err {
log.Fatalf("failed updating files: '%v'", err)
}
if err = createOrUpdatePR(gcw, bestVersion, targetGI, msgs, *dryrun); nil != err {
log.Fatalf("failed creating pullrequest: '%v'", err)
}
}