From a5754429d0aa3da86323adeedc14396c5cc8a369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ma=C5=82achowski?= Date: Fri, 18 Oct 2024 14:08:27 +0200 Subject: [PATCH 1/5] Restore force push behaviour --- pkg/github/bumper/bumper.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/github/bumper/bumper.go b/pkg/github/bumper/bumper.go index a20e5750c415..51c0d0135711 100644 --- a/pkg/github/bumper/bumper.go +++ b/pkg/github/bumper/bumper.go @@ -144,6 +144,7 @@ func gitPush(remote, remoteBranch, baseBranch string, repo *git.Repository, auth refSpecString := fmt.Sprintf("+%s:refs/heads/%s", localRef.Name(), remoteBranch) logrus.Infof("Pushing changes using %s refspec", refSpecString) err = repo.Push(&git.PushOptions{ + Force: true, RemoteName: forkRemoteName, RefSpecs: []config.RefSpec{ config.RefSpec(refSpecString), From 88026b7a8adbd6c4ec5adb2037a04f570d0c6f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ma=C5=82achowski?= Date: Fri, 18 Oct 2024 14:18:55 +0200 Subject: [PATCH 2/5] Fix paths in worflows for image-autobumper --- .github/workflows/pull-build-image-autobumper.yaml | 1 + .github/workflows/push-build-image-autobumper.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/pull-build-image-autobumper.yaml b/.github/workflows/pull-build-image-autobumper.yaml index 7457be849462..1bc9b3a644e4 100644 --- a/.github/workflows/pull-build-image-autobumper.yaml +++ b/.github/workflows/pull-build-image-autobumper.yaml @@ -7,6 +7,7 @@ on: - 'cmd/image-autobumper/**' - "go.mod" - "go.sum" + - "pkg/**" jobs: build-image: diff --git a/.github/workflows/push-build-image-autobumper.yaml b/.github/workflows/push-build-image-autobumper.yaml index 95053c60bf00..b40b314e5042 100644 --- a/.github/workflows/push-build-image-autobumper.yaml +++ b/.github/workflows/push-build-image-autobumper.yaml @@ -8,6 +8,7 @@ on: - 'cmd/image-autobumper/**' - 'go.mod' - 'go.sum' + - "pkg/**" workflow_dispatch: {} jobs: From ff5349f795637ca9d0a30d56c55bd467fb2cf621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ma=C5=82achowski?= Date: Fri, 18 Oct 2024 14:33:04 +0200 Subject: [PATCH 3/5] Unify build workflows with new approach --- ...umper.yaml => build-image-autobumper.yaml} | 12 ++++++++- .../push-build-image-autobumper.yaml | 26 ------------------- 2 files changed, 11 insertions(+), 27 deletions(-) rename .github/workflows/{pull-build-image-autobumper.yaml => build-image-autobumper.yaml} (67%) delete mode 100644 .github/workflows/push-build-image-autobumper.yaml diff --git a/.github/workflows/pull-build-image-autobumper.yaml b/.github/workflows/build-image-autobumper.yaml similarity index 67% rename from .github/workflows/pull-build-image-autobumper.yaml rename to .github/workflows/build-image-autobumper.yaml index 1bc9b3a644e4..54757917f784 100644 --- a/.github/workflows/pull-build-image-autobumper.yaml +++ b/.github/workflows/build-image-autobumper.yaml @@ -1,13 +1,23 @@ name: pull-build-image-autobumper on: + push: + branches: + - main + paths: + - 'cmd/image-autobumper/Dockerfile' + - 'cmd/image-autobumper/**' + - 'go.mod' + - 'go.sum' + - "pkg/**" pull_request_target: - types: [ opened, edited, synchronize, reopened, ready_for_review ] + types: [ opened, synchronize, reopened, ready_for_review ] paths: - 'cmd/image-autobumper/Dockerfile' - 'cmd/image-autobumper/**' - "go.mod" - "go.sum" - "pkg/**" + workflow_dispatch: {} jobs: build-image: diff --git a/.github/workflows/push-build-image-autobumper.yaml b/.github/workflows/push-build-image-autobumper.yaml deleted file mode 100644 index b40b314e5042..000000000000 --- a/.github/workflows/push-build-image-autobumper.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: push-build-image-autobumper -on: - push: - branches: - - main - paths: - - 'cmd/image-autobumper/Dockerfile' - - 'cmd/image-autobumper/**' - - 'go.mod' - - 'go.sum' - - "pkg/**" - workflow_dispatch: {} - -jobs: - build-image: - uses: ./.github/workflows/image-builder.yml - with: - name: image-autobumper - dockerfile: cmd/image-autobumper/Dockerfile - context: . - print-image: - runs-on: ubuntu-latest - needs: build-image - steps: - - name: Print image - run: echo "Image built ${{ needs.build-image.outputs.images }}" From 4a9312459209e98d3ba1e32c656743ef92a699b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ma=C5=82achowski?= Date: Fri, 18 Oct 2024 14:44:05 +0200 Subject: [PATCH 4/5] Fix issue when remote branch is not found --- pkg/github/bumper/bumper.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/github/bumper/bumper.go b/pkg/github/bumper/bumper.go index 51c0d0135711..7fb6899abec4 100644 --- a/pkg/github/bumper/bumper.go +++ b/pkg/github/bumper/bumper.go @@ -115,9 +115,13 @@ func gitPush(remote, remoteBranch, baseBranch string, repo *git.Repository, auth } // Get the remote head commit + var remoteRefHash plumbing.Hash remoteRef, err := repo.Reference(plumbing.NewRemoteReferenceName(forkRemoteName, remoteBranch), true) - if err != nil { + // Ignore the error if the remote branch does not exist + if err != nil && err != plumbing.ErrReferenceNotFound { return fmt.Errorf("get remote reference: %w", err) + } else { + remoteRefHash = remoteRef.Hash() } // Get the local head commit @@ -127,13 +131,13 @@ func gitPush(remote, remoteBranch, baseBranch string, repo *git.Repository, auth } // Check if the remote head commit is the same as the local head commit - if remoteRef.Hash() == localRef.Hash() { + if remoteRefHash == localRef.Hash() { logrus.Info("Remote is up to date, quitting.") return nil } if dryrun { - logrus.Infof("[Dryrun] Pushing to %s %s", remote, remoteRef.Name()) + logrus.Infof("[Dryrun] Pushing to %s refs/heads/%s", remote, remoteBranch) return nil } From 455613410badacefe80a8170d838b16a171765db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ma=C5=82achowski?= <38684517+KacperMalachowski@users.noreply.github.com> Date: Sat, 19 Oct 2024 17:55:41 +0200 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Przemek Pokrywka <12400578+dekiel@users.noreply.github.com> --- .github/workflows/build-image-autobumper.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build-image-autobumper.yaml b/.github/workflows/build-image-autobumper.yaml index 54757917f784..a31812aaaed7 100644 --- a/.github/workflows/build-image-autobumper.yaml +++ b/.github/workflows/build-image-autobumper.yaml @@ -4,7 +4,6 @@ on: branches: - main paths: - - 'cmd/image-autobumper/Dockerfile' - 'cmd/image-autobumper/**' - 'go.mod' - 'go.sum' @@ -12,7 +11,6 @@ on: pull_request_target: types: [ opened, synchronize, reopened, ready_for_review ] paths: - - 'cmd/image-autobumper/Dockerfile' - 'cmd/image-autobumper/**' - "go.mod" - "go.sum"