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

false negative on use env in env definition #158

Closed
kazuk opened this issue Jun 26, 2022 · 12 comments
Closed

false negative on use env in env definition #158

kazuk opened this issue Jun 26, 2022 · 12 comments
Labels
enhancement New feature or request

Comments

@kazuk
Copy link

kazuk commented Jun 26, 2022

this commit passes actionlint

kazuk/sbom-ghr@fe18f2d

but The workflow is not valid. shown as bellow.

The workflow is not valid. .github/workflows/rust.yml (Line: 18, Col: 18): Unrecognized named-value: 'env'. Located at position 1 within expression: env.KEY_PREFIX .github/workflows/rust.yml (Line: 43, Col: 22): Unrecognized named-value: 'env'. Located at position 1 within expression: env.KEY_PREFIX
@rhysd rhysd added the enhancement New feature or request label Jun 26, 2022
@rhysd
Copy link
Owner

rhysd commented Jun 26, 2022

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#env

Variables in the env map cannot be defined in terms of other variables in the map.

Official document mentioned this limitation here.

https://docs.github.com/en/actions/learn-github-actions/contexts#env-context

You can use the env context in the value of any key in a step except for the id and uses keys.

id and uses also seem to ban env context.

@rhysd rhysd closed this as completed in 3843609 Jun 26, 2022
@rhysd
Copy link
Owner

rhysd commented Jun 26, 2022

Now workflow like below

on: push

jobs:
  my_job:
    runs-on: ubuntu-latest
    env:
      FOO: aaa
    steps:
      - uses: test/${{ env.FOO }}@main
        env:
          BAR: ${{ env.FOO }}
        id: foo-${{ env.FOO }}

causes errors as follows:

test.yaml:9:24: undefined variable "env". available variables are "github", "inputs", "job", "matrix", "needs", "runner", "secrets", "steps", "strategy" [expression]
  |
9 |       - uses: test/${{ env.FOO }}@main
  |                        ^~~~~~~
test.yaml:11:20: undefined variable "env". available variables are "github", "inputs", "job", "matrix", "needs", "runner", "secrets", "steps", "strategy" [expression]
   |
11 |           BAR: ${{ env.FOO }}
   |                    ^~~~~~~
test.yaml:12:21: undefined variable "env". available variables are "github", "inputs", "job", "matrix", "needs", "runner", "secrets", "steps", "strategy" [expression]
   |
12 |         id: foo-${{ env.FOO }}
   |                     ^~~~~~~

@rhysd
Copy link
Owner

rhysd commented Jun 26, 2022

This fix was included in the latest release v1.6.14.

@MatthewRyanRead
Copy link

MatthewRyanRead commented Jun 26, 2022

On v1.6.14 I am seeing a lot of errors around uses of env.SOMETHING. It seems to be cases where the variables may be defined/injected on a custom runner and aren't runner defaults or initialized earlier in the workflow.

@rhysd
Copy link
Owner

rhysd commented Jun 27, 2022

@MatthewRyanRead Do you mean referring env context in env: is allowed when it is run on self-hosted runner? Could you show the link to the actual workflow if it is public?

@guidojw
Copy link

guidojw commented Jun 27, 2022

Since these changes, I am experiencing a problem accessing top-level env in a job step's env.

Commit: csvalpha/sofia@51db186

The job configuration worked before, so this new error seems to be incorrect.

@wwalser
Copy link

wwalser commented Jun 27, 2022

I too was referencing env.GITHUB_SHA in the end: declarations of an individual task. That is now reporting as invalid.

@AndrewGable
Copy link

We are also seeing a new error reported on a previously "passing" workflow file.

Failing run: https://github.com/Expensify/App/runs/7078764707?check_suite_focus=true

Workflow file: https://github.com/Expensify/App/blob/main/.github/workflows/platformDeploy.yml

@guidojw
Copy link

guidojw commented Jun 27, 2022

@rhysd Is this on your radar or should I open a new issue for it?

@rhysd
Copy link
Owner

rhysd commented Jun 28, 2022

Thank you for the information.

I understood what is wrong.

  • env: at job level and top level do not allow to refer env context
  • but env: at step level allows

I'll fix this and soon release 1.6.15

@rhysd
Copy link
Owner

rhysd commented Jun 28, 2022

I added the fix at 323ceb4.

@rhysd
Copy link
Owner

rhysd commented Jun 28, 2022

The fix was released with v1.6.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants