[GH-ISSUE #442] I can't get if: ${{ always() }} / if: always() working (with master) #309

Closed
opened 2026-03-01 21:42:14 +03:00 by kerem · 8 comments
Owner

Originally created by @oderwat on GitHub (Dec 9, 2020).
Original GitHub issue: https://github.com/nektos/act/issues/442

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
Originally created by @oderwat on GitHub (Dec 9, 2020). Original GitHub issue: https://github.com/nektos/act/issues/442 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 ```
kerem 2026-03-01 21:42:14 +03:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 16, 2021):

Issue is stale and will be closed in 14 days unless there is new activity

<!-- gh-comment-id:761279516 --> @github-actions[bot] commented on GitHub (Jan 16, 2021): Issue is stale and will be closed in 14 days unless there is new activity
Author
Owner

@oderwat commented on GitHub (Jan 16, 2021):

Nobody?

<!-- gh-comment-id:761279784 --> @oderwat commented on GitHub (Jan 16, 2021): Nobody?
Author
Owner

@edtan commented on GitHub (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():
github.com/nektos/act@e6fcfed458/pkg/common/executor.go (L60-L66)

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.

<!-- gh-comment-id:761919683 --> @edtan commented on GitHub (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()`: https://github.com/nektos/act/blob/e6fcfed458dbccd640e093bffd0fc258d6ce0e6e/pkg/common/executor.go#L60-L66 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.
Author
Owner

@oderwat commented on GitHub (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.

<!-- gh-comment-id:762207169 --> @oderwat commented on GitHub (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.
Author
Owner

@edtan commented on GitHub (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.

<!-- gh-comment-id:762261995 --> @edtan commented on GitHub (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.
Author
Owner

@github-actions[bot] commented on GitHub (Feb 19, 2021):

Issue is stale and will be closed in 14 days unless there is new activity

<!-- gh-comment-id:781725441 --> @github-actions[bot] commented on GitHub (Feb 19, 2021): Issue is stale and will be closed in 14 days unless there is new activity
Author
Owner

@felipecruz91 commented on GitHub (May 10, 2021):

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

<!-- gh-comment-id:836546207 --> @felipecruz91 commented on GitHub (May 10, 2021): I'm experiencing the same scenario. It would be great to have this functionality as part of act.
Author
Owner

@chris3ware commented on GitHub (Sep 15, 2021):

Same here. This feature would be an excellent addition.

<!-- gh-comment-id:920079878 --> @chris3ware commented on GitHub (Sep 15, 2021): Same here. This feature would be an excellent addition.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#309
No description provided.