Skip to content
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

I can't get if: ${{ always() }} / if: always() working (with master) #442

Closed
oderwat opened this issue Dec 9, 2020 · 8 comments · Fixed by #840
Closed

I can't get if: ${{ always() }} / if: always() working (with master) #442

oderwat opened this issue Dec 9, 2020 · 8 comments · Fixed by #840
Labels
area/workflow Relating to workflow definitions kind/bug Something isn't working

Comments

@oderwat
Copy link

oderwat commented Dec 9, 2020

For cleaning up the local test environment, we need a way to run commands when the Test job fails. I learned that this could be done using if: always() in the cleanup steps. I didn't get this to work and thought it might not be supported but found issue #387, which describes my problem, which is closed. I saw that the linked commit, which is supposed to fix this, being in master and therefore build master for testing this. Still, it does not work.

Any idea what I may do wrong?

Example (partial):

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
    - name: ActLokal
#      if: ${{ env.GITHUB_ACTOR == "nektos/act" }}
      if: ${{ env.ACT }}
      run: echo "Running ACT"

    - name: NotAct
#      if: ${{ env.GITHUB_ACTOR != "nektos/act" }}
      if: ${{ !env.ACT }}
      run: echo "Running on GitHub"

.... other stuff

    - name: Start MongoDB As Docker
      uses: wbari/start-mongoDB@v0.2
      with:
        mongoDBVersion: 4.4

    - name: Test
      continue-on-error: true
      run: go test --race -v -coverprofile=coverage.txt -covermode=atomic ./...

    - name: Stop and Remove MongoDB
      if: ${{ always() }}
#      if: ${{ !env.ACT && always() }}
      continue-on-error: true
      run: docker stop mongo && docker rm mongo
@github-actions

This comment has been minimized.

@github-actions github-actions bot added the stale label Jan 16, 2021
@oderwat

This comment has been minimized.

@edtan
Copy link
Contributor

edtan commented Jan 18, 2021

From what I can tell, act currently will stop running on the first error in a series of steps, so it never reaches the last step where you have defined the always() expression. The implementation of running the steps in series is in NewPipelineExecutor():

for _, executor := range executors {
if rtn == nil {
rtn = executor
} else {
rtn = rtn.Then(executor)
}
}

I'm not exactly sure how to go about resolving this, but any pointers would be appreciated - I'd be happy to help PR a solution. I did notice that there was a NewConditionalExecutor, but it is not currently being referenced anywhere aside from some tests, so perhaps that could be utilized?

update: It looks like continue-on-error is currently defined but not used anywhere - I think we might be able to add a check to Then() to check the continue-on-error flag.

@oderwat
Copy link
Author

oderwat commented Jan 18, 2021

So when I understand it right, the feature actually does not exists or is not fully implemented. Sadly I am currently not able to invest time to help with a PR. I think the feature itself is needed to replicate the behavior on Github and hope that it can be added without too much of an investment.

@edtan
Copy link
Contributor

edtan commented Jan 18, 2021

Yes, my understanding is that the feature is not implemented in act yet. I can try to look into a PR for this when I have time again - hopefully next weekend.

@github-actions github-actions bot removed the stale label Jan 19, 2021
@github-actions

This comment has been minimized.

@felipecruz91
Copy link

I'm experiencing the same scenario. It would be great to have this functionality as part of act.

@catthehacker catthehacker reopened this May 11, 2021
@catthehacker catthehacker added area/workflow Relating to workflow definitions needs-work Extra attention is needed stale-exempt Exempt from stale and removed stale labels May 11, 2021
@catthehacker catthehacker added this to Needs triage in Bug squashing via automation May 11, 2021
@catthehacker catthehacker added the kind/bug Something isn't working label May 11, 2021
@catthehacker catthehacker moved this from Needs triage to Mid priority in Bug squashing May 11, 2021
@catthehacker catthehacker moved this from Work in progress to To do in Bug squashing Aug 17, 2021
@chris3ware
Copy link

Same here. This feature would be an excellent addition.

KnisterPeter added a commit to xing/act that referenced this issue Oct 14, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Oct 28, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
KnisterPeter added a commit to xing/act that referenced this issue Nov 4, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Nov 17, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Nov 22, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 23, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Nov 24, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 25, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 27, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Nov 27, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Nov 30, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
ZauberNerd added a commit to xing/act that referenced this issue Nov 30, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Nov 30, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Dec 3, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Dec 6, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Dec 6, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
github-actions bot pushed a commit to xing/act that referenced this issue Dec 6, 2021
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 nektos#442

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
@mergify mergify bot closed this as completed in #840 Dec 8, 2021
Bug squashing automation moved this from To do to Closed Dec 8, 2021
mergify bot pushed a commit that referenced this issue Dec 8, 2021
* 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 <zaubernerd@zaubernerd.de>

* style: correct linter warnings

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>

* 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 <mail@markus-wolf.de>

* fix: check job needs recursively

Ensure job result includes results of previous jobs

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* test: add runner test for job status check functions

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* test: add unit tests for run context if evaluation

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>

* 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 <zaubernerd@zaubernerd.de>

* test: add unit tests for step context if evaluation

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* 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 <zaubernerd@zaubernerd.de>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
@catthehacker catthehacker removed stale-exempt Exempt from stale needs-work Extra attention is needed labels Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/workflow Relating to workflow definitions kind/bug Something isn't working
Projects
Bug squashing
  
Closed
Development

Successfully merging a pull request may close this issue.

5 participants