Skip to content

OPRUN-1873: scripts/bumper: allow fetching using https #561

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

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
1 change: 1 addition & 0 deletions scripts/bumper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bumper
14 changes: 14 additions & 0 deletions scripts/bumper/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.20-openshift-4.14 as builder

WORKDIR /src
COPY main.go go.mod ./
RUN go build -o /bin/bumper -mod=mod ./...

FROM quay.io/centos/centos:stream8

RUN dnf install -y git glibc make
COPY --from=builder /bin/bumper /usr/bin/bumper
COPY --from=builder /usr/bin/go /usr/bin/go
COPY --from=builder /usr/lib/golang /usr/lib/golang

ENTRYPOINT ["bumper"]
28 changes: 25 additions & 3 deletions scripts/bumper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ const (
publish mode = "publish"
)

type fetchMode string

const (
https fetchMode = "https"
ssh fetchMode = "ssh"
)

const (
githubOrg = "openshift"
githubRepo = "operator-framework-olm"
Expand All @@ -49,6 +56,7 @@ type options struct {
mode string
logLevel string
centralRef string
fetchMode string

dryRun bool
githubLogin string
Expand All @@ -71,6 +79,7 @@ func (o *options) Bind(fs *flag.FlagSet) {
fs.StringVar(&o.commitFileInput, "commits-input", "", "File to read commits data from in order to drive sync process.")
fs.StringVar(&o.logLevel, "log-level", logrus.InfoLevel.String(), "Logging level.")
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.")
fs.StringVar(&o.fetchMode, "fetch-mode", string(ssh), "Method to use for fetching from git remotes.")

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

switch fetchMode(o.fetchMode) {
case ssh, https:
default:
return fmt.Errorf("--fetch-mode must be one of %v", []fetchMode{https, ssh})
}

if _, err := logrus.ParseLevel(o.logLevel); err != nil {
return fmt.Errorf("--log-level invalid: %w", err)
}
Expand Down Expand Up @@ -150,7 +165,7 @@ func main() {
logrus.WithError(err).Fatal("could not unmarshal input commits")
}
} else {
commits, err = detectNewCommits(ctx, logger.WithField("phase", "detect"), opts.stagingDir, opts.centralRef)
commits, err = detectNewCommits(ctx, logger.WithField("phase", "detect"), opts.stagingDir, opts.centralRef, fetchMode(opts.fetchMode))
if err != nil {
logger.WithError(err).Fatal("failed to detect commits")
}
Expand Down Expand Up @@ -250,7 +265,7 @@ type commit struct {
var repoRegex = regexp.MustCompile(`Upstream-repository: ([^ ]+)\n`)
var commitRegex = regexp.MustCompile(`Upstream-commit: ([a-f0-9]+)\n`)

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

var commits []commit
for repo, lastCommit := range lastCommits {
var remote string
switch mode {
case ssh:
remote = "[email protected]:operator-framework/" + repo
case https:
remote = "https://github.com/operator-framework/" + repo + ".git"
}
if _, err := runCommand(logger, exec.CommandContext(ctx,
"git", "fetch",
"[email protected]:operator-framework/"+repo,
remote,
"master",
)); err != nil {
return nil, err
Expand Down