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 7457be849462..a31812aaaed7 100644 --- a/.github/workflows/pull-build-image-autobumper.yaml +++ b/.github/workflows/build-image-autobumper.yaml @@ -1,12 +1,21 @@ name: pull-build-image-autobumper on: + push: + branches: + - main + paths: + - '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 95053c60bf00..000000000000 --- a/.github/workflows/push-build-image-autobumper.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: push-build-image-autobumper -on: - push: - branches: - - main - paths: - - 'cmd/image-autobumper/Dockerfile' - - 'cmd/image-autobumper/**' - - 'go.mod' - - 'go.sum' - 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 }}" diff --git a/pkg/github/bumper/bumper.go b/pkg/github/bumper/bumper.go index a20e5750c415..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 } @@ -144,6 +148,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),