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

Workflow expression variable reference checks miss some variables #61

Closed
briantist opened this issue Mar 29, 2023 · 8 comments · Fixed by actions/languageservices#15
Closed
Assignees
Labels
bug Something isn't working

Comments

@briantist
Copy link

briantist commented Mar 29, 2023

Describe the bug
The expression checker looks to see if variables that are referenced are actually defined and warns if a context reference may not be valid. This can cause bugs like #47 , but also it's missing some variables completely.

From the above issue:

name: "Context access might be invalid"
on: push
jobs:
  context-access-might-be-invalid:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup environment variables
        uses: rlespinasse/github-slug-action@v4

      - name: Print custom environment variables
        run: echo ${{ env.GITHUB_REF_SLUG }}

This raises the Context access might be invalid warning for env.GITHUB_REF_SLUG.

If the expression itself branches like so, only the "false" path as evaluated in the extension will raise a warning:

name: "Context access might be invalid"
on: push
jobs:
  context-access-might-be-invalid:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup environment variables
        uses: rlespinasse/github-slug-action@v4

      - name: Print custom environment variables
        run: echo ${{ true == false && env.FAKE_VAR || env.GITHUB_REF_SLUG }}

Here, the warning will be raised again, but only for env.GITHUB_REF_SLUG.

If we "define" the env var in an env block explicitly:

name: "Context access might be invalid"
on: push
jobs:
  context-access-might-be-invalid:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup environment variables
        uses: rlespinasse/github-slug-action@v4

      - name: Print custom environment variables
        env:
          GITHUB_REF_SLUG: whatever
        run: echo ${{ true == false && env.FAKE_VAR || env.GITHUB_REF_SLUG }}

then the warning goes away completely, and env.FAKE_VAR is never considered.

Alternatively, if we change the expression to something that can be evaluated as true at parse time:

name: "Context access might be invalid"
on: push
jobs:
  context-access-might-be-invalid:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup environment variables
        uses: rlespinasse/github-slug-action@v4

      - name: Print custom environment variables
        run: echo ${{ true && env.FAKE_VAR || env.GITHUB_REF_SLUG }}

Then the warning will change to env.FAKE_VAR only, ignoring the other one.

To Reproduce
See above.

Expected behavior
Both vars are warned against.

Extension Version
v0.25.3

@briantist briantist added the bug Something isn't working label Mar 29, 2023
@ad-m-ss
Copy link

ad-m-ss commented Mar 30, 2023

Another instance is about matrix variable:

image

Example workflow:

jobs:
  build-python-test:
    name: Build Python for test
    runs-on: ubuntu-20.04
    steps:
      - uses: 8398a7/action-slack@v3
        with:
          status: ${{ job.status }}
          job_name: Test
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
          MATRIX_CONTEXT: ${{ toJson(matrix) }}

@cschleiden
Copy link
Member

@briantist Thanks for reporting this, I agree this is something we should look into.

@ad-m-ss That is a valid error. The job isn't using a matrix strategy, so it won't be defined.

@cschleiden
Copy link
Member

This is fixed and will be included in the next release.

@dev0T
Copy link

dev0T commented Jun 7, 2023

and they never fix it

It has been said it will be fixed in the next release.

@cschleiden
Copy link
Member

cschleiden commented Jun 8, 2023

The release should've gone out by now. If you're still seeing issues, would you mind creating another issue with more details? Thanks

@PhiFry
Copy link

PhiFry commented Jun 19, 2023

When is the release?

@ElonGaties
Copy link

I don't seem to have the release here either weirdly

@klausbadelt
Copy link

duplicate of #222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants