[GH-ISSUE #1071] Error in if-expression #619

Closed
opened 2026-03-01 21:45:00 +03:00 by kerem · 4 comments
Owner

Originally created by @jonny7 on GitHub (Mar 23, 2022).
Original GitHub issue: https://github.com/nektos/act/issues/1071

Thanks very much for this project 🙂

System information

- Operating System: macOS
- Architecture: x64 (64-bit)
- Apple M1: no 
- Docker version: 20.10.12
- `act` version: 0.2.26

Expected behaviour

I have been running this element of a pipeline fine with 0.2.25 last night. I've just updated and I'm getting errors now around the if statement. So I would expect that this would continue to work and it works on GitHub, see here for reproducible

Actual behaviour

Calling

if: contains(github.event.pull_request.labels.*.name, 'skip-ci')

fails with

❌  Error in if-expression: "if: contains(github.event.pull_request.labels.*.name, 'skip-ci')" (Unable to dereference 'name' on non-struct 'invalid')

Workflow and/or repository

Repo has a working example that works on GH and did on 0.2.25 of act. The relevant workflow is this


on:
  pull_request

jobs:
  skip-pipeline:
    runs-on: ubuntu-latest
    outputs:
      skip: ${{ steps.set-skip.outputs.skip || false }}
    steps:
      - name: Set skip output var
        id: set-skip
        if: contains(github.event.pull_request.labels.*.name, 'skip-ci')
        run: echo "::set-output name=skip::true"

Steps to reproduce

The pipeline I'm using it with was based on pull_request, so act pull_request.

act output

DEBU[0000] evaluating expression 'contains(github.event.pull_request.labels.*.name, 'skip-ci')' 
DEBU[0000] expression 'contains(github.event.pull_request.labels.*.name, 'skip-ci')' evaluated to '%!t(<nil>)' 
[Integration Testing/skip-pipeline]   ❌  Error in if-expression: "if: contains(github.event.pull_request.labels.*.name, 'skip-ci')" (Unable to dereference 'name' on non-struct 'invalid')
Originally created by @jonny7 on GitHub (Mar 23, 2022). Original GitHub issue: https://github.com/nektos/act/issues/1071 Thanks very much for this project 🙂 ## System information - Operating System: macOS - Architecture: x64 (64-bit) - Apple M1: no - Docker version: 20.10.12 - `act` version: 0.2.26 ## Expected behaviour I have been running this element of a pipeline fine with `0.2.25` last night. I've just updated and I'm getting errors now around the if statement. So I would expect that this would continue to work and it works on GitHub, see here for [reproducible ](https://github.com/jonny7/act-example/runs/5659657478?check_suite_focus=true) ## Actual behaviour Calling ```yaml if: contains(github.event.pull_request.labels.*.name, 'skip-ci') ``` fails with ``` ❌ Error in if-expression: "if: contains(github.event.pull_request.labels.*.name, 'skip-ci')" (Unable to dereference 'name' on non-struct 'invalid') ``` ## Workflow and/or repository [Repo](https://github.com/jonny7/act-example) has a working example that works on GH and did on 0.2.25 of act. The relevant workflow is this ```yaml on: pull_request jobs: skip-pipeline: runs-on: ubuntu-latest outputs: skip: ${{ steps.set-skip.outputs.skip || false }} steps: - name: Set skip output var id: set-skip if: contains(github.event.pull_request.labels.*.name, 'skip-ci') run: echo "::set-output name=skip::true" ``` ## Steps to reproduce The pipeline I'm using it with was based on `pull_request`, so `act pull_request`. ## `act` output ``` DEBU[0000] evaluating expression 'contains(github.event.pull_request.labels.*.name, 'skip-ci')' DEBU[0000] expression 'contains(github.event.pull_request.labels.*.name, 'skip-ci')' evaluated to '%!t(<nil>)' [Integration Testing/skip-pipeline] ❌ Error in if-expression: "if: contains(github.event.pull_request.labels.*.name, 'skip-ci')" (Unable to dereference 'name' on non-struct 'invalid') ```
Author
Owner

@ChristopherHX commented on GitHub (Mar 23, 2022):

Yes it's a bug, the new expression evaluator should not return such errors.
Workaround, it probably take some months till v0.2.27
You can just create the missing object
pull_request.json

{
    "pull_request": {
        "labels": [
            {
                "name": "act"
            }
        ]
    }
}

act pull_request -e pull_request.json

github.event.pull_request.labels.*.name didn't work in act 0.2.25, because it was misinterpreted as github.event.pull_request.labels['*'].name.

<!-- gh-comment-id:1076485064 --> @ChristopherHX commented on GitHub (Mar 23, 2022): Yes it's a bug, the new expression evaluator should not return such errors. **Workaround**, _it probably take some months till v0.2.27_ You can just create the missing object pull_request.json ```json { "pull_request": { "labels": [ { "name": "act" } ] } } ``` `act pull_request -e pull_request.json` `github.event.pull_request.labels.*.name` didn't work in act 0.2.25, because it was misinterpreted as `github.event.pull_request.labels['*'].name`.
Author
Owner

@jonny7 commented on GitHub (Mar 24, 2022):

Thanks @ChristopherHX

This workaround is cool right now for me

<!-- gh-comment-id:1077616515 --> @jonny7 commented on GitHub (Mar 24, 2022): Thanks @ChristopherHX This workaround is cool right now for me
Author
Owner

@jonny7 commented on GitHub (Mar 24, 2022):

I should leave open as it is a bug - my mistake

<!-- gh-comment-id:1077659327 --> @jonny7 commented on GitHub (Mar 24, 2022): I should leave open as it is a bug - my mistake
Author
Owner

@dror-weiss commented on GitHub (Apr 5, 2022):

Same here, in a more widespread use case such as searching for a special commit message:

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  ubuntu:
    if: !contains(github.event.commits.*.message, '[skip ci]')

The commits element doesn't exist in a pull_request event, so this should be relatively easy to fix, IMO.

<!-- gh-comment-id:1089041765 --> @dror-weiss commented on GitHub (Apr 5, 2022): Same here, in a more widespread use case such as searching for a special commit message: ```yml on: push: branches: [ main ] pull_request: branches: [ main ] jobs: ubuntu: if: !contains(github.event.commits.*.message, '[skip ci]') ``` The `commits` element doesn't exist in a `pull_request` event, so this should be relatively easy to fix, IMO.
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#619
No description provided.