-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: continue jobs + steps after failure (#840)
* fix: continue jobs + steps after failure To allow proper if expression handling on jobs and steps (like always, success, failure, ...) we need to continue running all executors in the prepared chain. To keep the error handling intact we add an occurred error to the go context and handle it later in the pipeline/chain. Also we add the job result to the needs context to give expressions access to it. The needs object, failure and success functions are split between run context (on jobs) and step context. Closes #442 Co-authored-by: Björn Brauer <[email protected]> * style: correct linter warnings Co-authored-by: Björn Brauer <[email protected]> * fix: job if value defaults to success() As described in the documentation, a default value of "success()" is applied when no "if" value is present on the job. https://docs.github.com/en/actions/learn-github-actions/expressions#job-status-check-functions Co-authored-by: Markus Wolf <[email protected]> * fix: check job needs recursively Ensure job result includes results of previous jobs Co-authored-by: Markus Wolf <[email protected]> * test: add runner test for job status check functions Co-authored-by: Markus Wolf <[email protected]> * test: add unit tests for run context if evaluation Co-authored-by: Björn Brauer <[email protected]> * refactor: move if expression evaluation Move if expression evaluation into own function (step context) to better support unit testing. Co-authored-by: Björn Brauer <[email protected]> * test: add unit tests for step context if evaluation Co-authored-by: Markus Wolf <[email protected]> * fix: handle job error more resilient The job error is not stored in a context map instead of a context added value. Since context values are immutable an added value requires to keep the new context in all cases. This is fragile since it might slip unnoticed to other parts of the code. Storing the error of a job in the context map will make it more stable, since the map is always there and the context of the pipeline is stable for the whole run. * feat: steps should use a default if expression of success() * test: add integration test for if-expressions * chore: disable editorconfig-checker for yaml multiline string Co-authored-by: Björn Brauer <[email protected]> Co-authored-by: Björn Brauer <[email protected]>
- Loading branch information
1 parent
a545cea
commit 1891c72
Showing
13 changed files
with
523 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type jobErrorContextKey string | ||
|
||
const jobErrorContextKeyVal = jobErrorContextKey("job.error") | ||
|
||
// JobError returns the job error for current context if any | ||
func JobError(ctx context.Context) error { | ||
val := ctx.Value(jobErrorContextKeyVal) | ||
if val != nil { | ||
if container, ok := val.(map[string]error); ok { | ||
return container["error"] | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func SetJobError(ctx context.Context, err error) { | ||
ctx.Value(jobErrorContextKeyVal).(map[string]error)["error"] = err | ||
} | ||
|
||
// WithJobErrorContainer adds a value to the context as a container for an error | ||
func WithJobErrorContainer(ctx context.Context) context.Context { | ||
container := map[string]error{} | ||
return context.WithValue(ctx, jobErrorContextKeyVal, container) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.