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

Issue: GitHub Actions says workflow is not valid because of ${{ !env.ACT }} #720

Closed
merlinstardust opened this issue Jun 3, 2021 · 7 comments
Labels
meta/invalid This doesn't seem right

Comments

@merlinstardust
Copy link

Expected behaviour

GitHub Actions should not error regarding ${{ !env.ACT }}

Actual behaviour

GitHub Actions says workflow is not valid because of ${{ !env.ACT }}

The workflow is not valid. .github/workflows/deploy.yml (Line: 11, Col: 13): Unrecognized named-value: 'env'. Located at position 2 within expression: !env.ACT

Workflow and/or repository

Erroring Workflow

workflow
name: Deploy
on:
    push:
        branches:
            - release
    # run for every pull request
    pull_request: {}
jobs:
    deploy:
        name: Deploy
        if: ${{ !env.ACT }} # skip during local actions testing
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node: [12]
        steps:
            - name: Checkout repo
              uses: actions/checkout@v2

            - name: Setup node
              uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node }}

            - name: 📥 Download deps
              uses: bahmutov/npm-install@v1
              with:
                  useLockFile: false

            - name: Deploy
              run: npx semantic-release@15

@merlinstardust merlinstardust added the kind/bug Something isn't working label Jun 3, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2021

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

@github-actions github-actions bot added the stale label Jul 4, 2021
@merlinstardust
Copy link
Author

Keep

@github-actions github-actions bot removed the stale label Jul 5, 2021
@catthehacker catthehacker added meta/invalid This doesn't seem right and removed kind/bug Something isn't working labels Jul 5, 2021
@catthehacker
Copy link
Member

That's a problem with GitHub and not Act.

@merlinstardust
Copy link
Author

@catthehacker how do you suggest I fix it? Who should I contact? The docs for act include this line, but if it doesn't work with GitHub, that's a bug that should be fixed.

@catthehacker
Copy link
Member

catthehacker commented Jul 5, 2021

act docs mention this but only for a step and it works on GitHub Actions, create issue on https://github.com/actions/runner to implement support for non-existing environment variables in job context of if:

act/README.md

Lines 286 to 296 in dcbd583

# Skipping steps
Act adds a special environment variable `ACT` that can be used to skip a step that you
don't want to run locally. E.g. a step that posts a Slack message or bumps a version number.
```yml
- name: Some step
if: ${{ !env.ACT }}
run: |
...
```

@ChristopherHX
Copy link
Contributor

If you ask me your statement in a job-if is a syntax violation and is correctly rejected by github, but act has no such validation. The env context is only evaluated in the runner not the server (I made my own server).
Please consider using the github context instead:

name: Deploy
on:
    push:
        branches:
            - release
    # run for every pull request
    pull_request: {}
jobs:
    deploy:
        name: Deploy
        if: ${{ !github.event.act }} # skip during local actions testing
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node: [12]
        steps:
            - name: Checkout repo
              uses: actions/checkout@v2

            - name: Setup node
              uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node }}

            - name: 📥 Download deps
              uses: bahmutov/npm-install@v1
              with:
                  useLockFile: false

            - name: Deploy
              run: npx semantic-release@15

And use this event.json file with act or Runner.Client otherwise the Job will run:

{
    "act": true
}

Run act like

act -e event.json

Hint: you can add / append -e event.json as a line into ./.actrc

@diepes
Copy link

diepes commented Sep 5, 2022

I also just got the github error below.
Local with act it ran fine. I am trying to skip a job on local.

[Invalid workflow file: .github/workflows/ci.yml#L15](https://github.com/me/repo/actions/runs/2995855128/workflow) The workflow is not valid. .github/workflows/ci.yml (Line: 15, Col: 9): Unrecognized named-value: 'env'. Located at position 2 within expression: !env.ACT .github/workflows/ci.yml (Line: 39, Col: 9): Unrecognized named-value: 'env'. Located at position 2 within expression: !env.ACT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

4 participants