Skip to content

Commit d4348fd

Browse files
Merge pull request openshift#561 from stevekuznetsov/skuznets/bumper-fetch-mode
OPRUN-1873: scripts/bumper: allow fetching using https
2 parents 6799db7 + 9fee111 commit d4348fd

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

scripts/bumper/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bumper

scripts/bumper/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.20-openshift-4.14 as builder
2+
3+
WORKDIR /src
4+
COPY main.go go.mod ./
5+
RUN go build -o /bin/bumper -mod=mod ./...
6+
7+
FROM quay.io/centos/centos:stream8
8+
9+
RUN dnf install -y git glibc make
10+
COPY --from=builder /bin/bumper /usr/bin/bumper
11+
COPY --from=builder /usr/bin/go /usr/bin/go
12+
COPY --from=builder /usr/lib/golang /usr/lib/golang
13+
14+
ENTRYPOINT ["bumper"]

scripts/bumper/main.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ const (
3232
publish mode = "publish"
3333
)
3434

35+
type fetchMode string
36+
37+
const (
38+
https fetchMode = "https"
39+
ssh fetchMode = "ssh"
40+
)
41+
3542
const (
3643
githubOrg = "openshift"
3744
githubRepo = "operator-framework-olm"
@@ -49,6 +56,7 @@ type options struct {
4956
mode string
5057
logLevel string
5158
centralRef string
59+
fetchMode string
5260

5361
dryRun bool
5462
githubLogin string
@@ -71,6 +79,7 @@ func (o *options) Bind(fs *flag.FlagSet) {
7179
fs.StringVar(&o.commitFileInput, "commits-input", "", "File to read commits data from in order to drive sync process.")
7280
fs.StringVar(&o.logLevel, "log-level", logrus.InfoLevel.String(), "Logging level.")
7381
fs.StringVar(&o.centralRef, "central-ref", "origin/master", "Git ref for the central branch that will be updated, used as the base for determining what commits need to be cherry-picked.")
82+
fs.StringVar(&o.fetchMode, "fetch-mode", string(ssh), "Method to use for fetching from git remotes.")
7483

7584
fs.BoolVar(&o.dryRun, "dry-run", true, "Whether to actually create the pull request with github client")
7685
fs.StringVar(&o.githubLogin, "github-login", githubLogin, "The GitHub username to use.")
@@ -93,6 +102,12 @@ func (o *options) Validate() error {
93102
return fmt.Errorf("--mode must be one of %v", []mode{summarize, synchronize})
94103
}
95104

105+
switch fetchMode(o.fetchMode) {
106+
case ssh, https:
107+
default:
108+
return fmt.Errorf("--fetch-mode must be one of %v", []fetchMode{https, ssh})
109+
}
110+
96111
if _, err := logrus.ParseLevel(o.logLevel); err != nil {
97112
return fmt.Errorf("--log-level invalid: %w", err)
98113
}
@@ -150,7 +165,7 @@ func main() {
150165
logrus.WithError(err).Fatal("could not unmarshal input commits")
151166
}
152167
} else {
153-
commits, err = detectNewCommits(ctx, logger.WithField("phase", "detect"), opts.stagingDir, opts.centralRef)
168+
commits, err = detectNewCommits(ctx, logger.WithField("phase", "detect"), opts.stagingDir, opts.centralRef, fetchMode(opts.fetchMode))
154169
if err != nil {
155170
logger.WithError(err).Fatal("failed to detect commits")
156171
}
@@ -250,7 +265,7 @@ type commit struct {
250265
var repoRegex = regexp.MustCompile(`Upstream-repository: ([^ ]+)\n`)
251266
var commitRegex = regexp.MustCompile(`Upstream-commit: ([a-f0-9]+)\n`)
252267

253-
func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, centralRef string) ([]commit, error) {
268+
func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, centralRef string, mode fetchMode) ([]commit, error) {
254269
lastCommits := map[string]string{}
255270
if err := fs.WalkDir(os.DirFS(stagingDir), ".", func(path string, d fs.DirEntry, err error) error {
256271
if err != nil {
@@ -301,9 +316,16 @@ func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, cen
301316

302317
var commits []commit
303318
for repo, lastCommit := range lastCommits {
319+
var remote string
320+
switch mode {
321+
case ssh:
322+
remote = "[email protected]:operator-framework/" + repo
323+
case https:
324+
remote = "https://github.com/operator-framework/" + repo + ".git"
325+
}
304326
if _, err := runCommand(logger, exec.CommandContext(ctx,
305327
"git", "fetch",
306-
"[email protected]:operator-framework/"+repo,
328+
remote,
307329
"master",
308330
)); err != nil {
309331
return nil, err

0 commit comments

Comments
 (0)