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

Context access might be invalid warning shows for push, not for pull_request event #97

Open
4 tasks
garysassano opened this issue Aug 23, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@garysassano
Copy link

Describe the bug
See screenshots below.

To Reproduce
Steps to reproduce the behavior:

  1. With this workflow '...'
  2. Do this '...'
  3. See error

Expected behavior
Context access might be invalid shows up for all kind of events where the context might be missing.

Screenshots
image
image

Package/Area

  • Expressions
  • Workflow Parser
  • Language Service
  • Language Server

Package Version
v1.x.y

Additional context
Add any other context about the problem here.

@garysassano
Copy link
Author

Apparently, you access the head_commit property without specifying an event type (github.event.head_commit.messag), even though the structure of the payload should be correct according to the docs.

Also, technically the Context access might be invalid warning should always be displayed when accessing any event-specific context, since you have no guarantee of which event type triggered the workflow UNLESS the workflow specifies a single trigger, in which case that event type context would be guaranteed to be valid.

@johnseth97
Copy link

Also, technically the Context access might be invalid warning should always be displayed when accessing any event-specific context, since you have no guarantee of which event type triggered the workflow UNLESS the workflow specifies a single trigger, in which case that event type context would be guaranteed to be valid.

If that's the case, it would be nice to be able to suppress the warning. Maybe something similar to flake8, i.e. #github-actions-context-manually-verified posted at the end of the offending line.

@johnseth97
Copy link

johnseth97 commented Sep 25, 2024

You could try putting in a default value with the or operator

${{ <output> || <default_value> }}

@eric-nclusion
Copy link

I am using this hacky workaround, which works, but is not ideal:

${{ fromJson(toJson(github.event)).push.head.sha }}

This will suppress the warning.

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

No branches or pull requests

3 participants