-
Is there anyway to access the GH context from within an action, without having to specify e.g. env og secrets as inputs for the action? Right now I serialize e.g. secrets as a parameter for the action and deserialize within the action. Thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Can anyone confirm that accessing GH context is not possible within an action, without specifying it as a parameter input? |
Beta Was this translation helpful? Give feedback.
-
I don’t think it’s currently possible to access the context directly. Consider github-script, which provides a partial context containing some of the items from the workflow github context. That partial context is actually just rehydrated from the environment. If it were possible to get the real context directly it would make sense for github-script to do that. The fact it doesn’t suggests it’s not possible. One workaround is to add inputs to your action, but set the default using the context, eg:
actions/github-script/blob/00e1b58cd9e040d944127e75b3d9df586e4b0479/action.yml#L13 That’s ok if it makes sense to give users of the action the option to override the default value. |
Beta Was this translation helpful? Give feedback.
-
That’s a pretty good idea and letting the user option out by overriding the inputs makes perfectly sense. In my case I need access to both the github and secrets context for setting up variables based on the environment context in the json-variables action. The default assignment makes usage syntax far more clean, while still being able to overwrite. |
Beta Was this translation helpful? Give feedback.
-
But it is explicitly stated in Automatic token authentication - GitHub Docs
Is this just plain wrong? |
Beta Was this translation helpful? Give feedback.
-
I was wondering exactly the same thing. I think the way to get the GITHUB_TOKEN using the context is using a default input value. You can see an example in the GitHub actions/checkout@v2 action:
actions/checkout/blob/2541b1294d2704b0964813337f33b291d3f8596b/action.yml#L24
As far as I know there are some ways to pass values to the action:
And:
I have not found any information in the documentation regarding using contexts in the action definition file. It is not mentioned in the action.yml syntax: Metadata syntax for GitHub Actions - GitHub Docs |
Beta Was this translation helpful? Give feedback.
I don’t think it’s currently possible to access the context directly.
Consider github-script, which provides a partial context containing some of the items from the workflow github context. That partial context is actually just rehydrated from the environment. If it were possible to get the real context directly it would make sense for github-script to do that. The fact it doesn’t suggests it’s not possible.
One workaround is to add inputs to your action, but set the default using the context, eg:
actions/github-scrip…