GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(engine): clear push errors recovered by a later push of the same branch by Goldloli · Pull Request #11067 · updatecli/updatecli

fix(engine): clear push errors recovered by a later push of the same branch #11067

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.

Sign up for GitHub

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
olblak merged 8 commits into updatecli:main from Goldloli:fix/push-scm-errors
Nov 12, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(engine): clear push errors recovered by a later push of the same branch #11067

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
8 commits
Select commit Hold shift + click to select a range
6d73133
fix(engine): clear push errors recovered by a later push of the same …
Goldloli Oct 29, 2026
c0481b1
fix(engine): restore recovered target results before actions run
Goldloli Oct 29, 2026
70d0a64
fix(engine): only clear checkout failures after an actual push
olblak Nov 9, 2026
a6cb0de
fix(engine): report the recovering push's branch reset on restored ta…
olblak Nov 9, 2026
80f88b2
fix(engine): report every push failure, in a stable order
olblak Nov 9, 2026
d1bc1b3
fix(engine): key push failures by checkout directory
olblak Nov 9, 2026
fa6b100
fix(engine): mark failed target pushes as failures explicitly
olblak Nov 9, 2026
b1c32b5
Merge branch 'main' into fix/push-scm-errors
Goldloli Nov 12, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

150 changes: 136 additions & 14 deletions 150 pkg/core/engine/scm.go
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package engine

import (
"cmp"
"fmt"
"io"
"maps"
"slices"
"strings"
"sync"
Expand Down Expand Up @@ -107,6 +109,76 @@ func (e *Engine) failedSCMError(p *pipeline.Pipeline) error {
func (e *Engine) pushSCMCommits() error {
errs := []string{}

// pushFailureKey identifies the working copy a push failure belongs to.
// SCM configurations may share a repository URL and a working branch while
// using different working directories, so the directory is part of the key:
// a push from one checkout must not clear the failure of another checkout
// whose commits were not published. Such a failure is only recovered when
// the branch publication below visits that checkout, which is the same
// outcome as before failures could be recovered at all.
type pushFailureKey struct {
url string
branch string
directory string
}

// pushErrs records push errors per working copy.
// A working branch is shared by every target of the same SCM, so an error
// reported while pushing one target must be cleared as soon as another
// target, or the branch publication below, manages to push that branch or
// finds it up to date.
// Every message is kept, not only the last one: two targets sharing a working
// branch may fail for different reasons, and dropping the earlier cause would
// hide it from the returned error.
pushErrs := map[pushFailureKey][]string{}

// pushFailedTargets records, per working copy, the targets whose push
// failed with the result they had before the failure.
// Failing to push sets the target result to FAILURE, and actions are only
// created for targets in an attention state, so the previous result must be
// restored once the branch is published: otherwise the action would silently
// be skipped even though the target's changes have been pushed.
type failedTarget struct {
result *result.Target
before result.Target
}
pushFailedTargets := map[pushFailureKey][]failedTarget{}

recordPushFailure := func(key pushFailureKey, msg string, targetResult *result.Target, before result.Target) {
pushErrs[key] = append(pushErrs[key], msg)
pushFailedTargets[key] = append(pushFailedTargets[key], failedTarget{
result: targetResult,
before: before,
})
}

// checkoutFailed records, per working copy, whether a
// checkout failed before pushing. The remote branch status check reports a
// branch as up to date when the local working branch does not exist, which
// is what a failed checkout may leave behind, so such failures are only
// cleared by an actual push and never by finding the remote branch up to date.
checkoutFailed := map[pushFailureKey]bool{}

// clearPushFailure forgets the failures of a working copy and restores its
// failed targets. When the recovery comes from a push, pushed is true and
// branchReset is what that push reported: the restored results must carry
// it, as actions rely on it to know that the working branch was reset,
// while the saved results predate any push of this execution.
clearPushFailure := func(key pushFailureKey, pushed, branchReset bool) {
delete(pushErrs, key)
delete(checkoutFailed, key)

for _, failed := range pushFailedTargets[key] {
if failed.result != nil {
*failed.result = failed.before
if pushed {
failed.result.Scm.BranchReset = branchReset
}
}
}
delete(pushFailedTargets, key)
}

changedSCM := map[string][]string{}

inconclusiveSCM := e.inconclusiveSCMBranches()
Expand Down Expand Up @@ -136,6 +208,11 @@ func (e *Engine) pushSCMCommits() error {

url := scmHandler.GetURL()
_, branch, _ := scmHandler.GetBranches()
pushKey := pushFailureKey{
url: url,
branch: branch,
directory: scmHandler.GetDirectory(),
}

if _, ok := allScm[url]; !ok {
allScm[url] = map[string]*scm.ScmHandler{}
Expand All @@ -158,19 +235,30 @@ func (e *Engine) pushSCMCommits() error {
if err != nil {
msg := fmt.Sprintf("checking out git repository: %v", err)
log.Errorf("%s", msg)
errs = append(errs, msg)
recordPushFailure(pushKey, msg, target.Result, *target.Result)
checkoutFailed[pushKey] = true
target.Result.Result = result.FAILURE
continue
}

// PushCommits reports the failure by overwriting the target
// result, so its previous value is saved first to be restored if
// the branch is eventually published.
resultBeforePush := *target.Result
err = target.PushCommits()
if err != nil {
msg := fmt.Sprintf("pushing commits for target %q: %s", target.Config.Name, err.Error())
// PushCommits already names the target in its error.
msg := err.Error()
log.Errorf("%s", msg)
errs = append(errs, msg)
recordPushFailure(pushKey, msg, target.Result, resultBeforePush)
// PushCommits already marks the target failed, but the
// result must not depend on how it reports the error.
target.Result.Result = result.FAILURE
continue
}
// The shared working branch has been pushed, so errors reported
// by previous targets of that working copy are no longer relevant.
clearPushFailure(pushKey, true, target.Result.Scm.BranchReset)
log.Debugf("Pushed to URL: %q on branch: %q", redact.URL(url), branch)

if _, ok := changedSCM[url]; !ok {
Expand All @@ -191,23 +279,54 @@ func (e *Engine) pushSCMCommits() error {
log.Infof("Pushed changes to %d of %d SCM repositories", countPushedScms, countScms)
}

for url := range allScm {
for branch := range allScm[url] {

// Repositories and branches are visited in a stable order, so that the
// output and the returned error do not depend on map iteration.
for _, url := range slices.Sorted(maps.Keys(allScm)) {
for _, branch := range slices.Sorted(maps.Keys(allScm[url])) {
scmHandlerPtr := allScm[url][branch]
if scmHandlerPtr == nil {
continue
}

stopCapture := e.captureSCMConsoleOutput(url, branch)
if err := pushSCMBranch(*scmHandlerPtr, url, branch, slices.Contains(inconclusiveSCM[url], branch)); err != nil {
// Only the working copy of the first target found for this branch is
// published, so only its failures can be recovered here.
pushKey := pushFailureKey{
url: url,
branch: branch,
directory: (*scmHandlerPtr).GetDirectory(),
}
branchInconclusive := slices.Contains(inconclusiveSCM[url], branch)
pushed, branchReset, err := pushSCMBranch(*scmHandlerPtr, url, branch, branchInconclusive)
switch {
case err != nil:
log.Errorf("%s", err)
errs = append(errs, err.Error())
case branchInconclusive:
// Nothing was checked, so earlier failures are kept.
case pushed || !checkoutFailed[pushKey]:
// The working branch has just been pushed, or the remote branch
// already contains the local commits, so earlier push errors for
// that working copy are no longer relevant.
clearPushFailure(pushKey, pushed, branchReset)
}
stopCapture()
}
}

// Only keep push errors that no later push of the same working copy managed
// to recover from, in a stable order.
failedKeys := slices.SortedFunc(maps.Keys(pushErrs), func(a, b pushFailureKey) int {
return cmp.Or(
cmp.Compare(a.url, b.url),
cmp.Compare(a.branch, b.branch),
cmp.Compare(a.directory, b.directory),
)
})
for _, key := range failedKeys {
errs = append(errs, pushErrs[key]...)
}

if len(errs) > 0 {
return fmt.Errorf(
"errors occurred while pushing SCM commits:\n\t* %s",
Expand All @@ -218,36 +337,39 @@ func (e *Engine) pushSCMCommits() error {
}

// pushSCMBranch pushes the commits of a working branch, unless one of its targets didn't run.
func pushSCMBranch(scmHandler scm.ScmHandler, url, branch string, inconclusive bool) error {
// It reports whether a push was performed, false meaning the branch was found up to date
// or was not checked at all because it is inconclusive, and, when it was, whether the
// push reset the working branch.
func pushSCMBranch(scmHandler scm.ScmHandler, url, branch string, inconclusive bool) (pushed, branchReset bool, err error) {
if inconclusive {
log.Debugf("Not publishing branch %q to %q as at least one of its target(s) didn't run during this execution\n", branch, redact.URL(url))
return nil
return false, false, nil
}

isRemoteBranchUpToDate, err := scmHandler.IsRemoteBranchUpToDate()
if err != nil {
return fmt.Errorf("checking remote branch status for %q on branch %q: %s", redact.URL(url), branch, err.Error())
return false, false, fmt.Errorf("checking remote branch status for %q on branch %q: %s", redact.URL(url), branch, err.Error())
}

if isRemoteBranchUpToDate {
log.Debugf("No changes to push to %q on branch %q\n", redact.URL(url), branch)
return nil
return false, false, nil
}

log.Infof("\n\u26A0 According to the git history, some commits must be pushed to %q %q\n", redact.URL(url), branch)

err = scmHandler.Checkout()
if err != nil {
return fmt.Errorf("checking out git repository: %v", err)
return false, false, fmt.Errorf("checking out git repository: %v", err)
}

isPushed, err := scmHandler.Push()
if err != nil {
return fmt.Errorf("pushing commits to %q on branch %q: %s", redact.URL(url), branch, err.Error())
return false, false, fmt.Errorf("pushing commits to %q on branch %q: %s", redact.URL(url), branch, err.Error())
}
log.Debugf("Pushed changes to %q on branch %q: %t\n", redact.URL(url), branch, isPushed)

return nil
return true, isPushed, nil
}

// pruneSCMBranches removes all working branches from the SCM.
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.