docs
docs copied to clipboard
Clarity on github context usage in Workflows vs. in custom JS action as well as attribute names in docs vs. actual event.
Code of Conduct
- [X] I have read and agree to the GitHub Docs project's Code of Conduct
What article on docs.github.com is affected?
What part(s) of the article would you like to see updated?
Introduction
From Workflows we have github.event_name
but, when creating an action in JS, the payload JSON is github.context.eventName
. I was trying to use github.event_name
in JS which gave undefined. Also note one is camel case and the other snake case.
This is confusing.
A small code example of the action (index.js) I am experimenting with:
const core = require('@actions/core');
const github = require('@actions/github');
async function run() {
try {
core.info(`This event is a: ${github.context.eventName}`);
core.info(`This event's action is ${github.context.action}`);
} catch (error) {
core.setFailed(error.message);
}
}
run();
Should usage from within a Workflow versus using from JS/TS be called out in the docs?
More details
The Github context action has examples as follows:
-
github.event
-
github.event_name
- ... and many others
These seem to be directly useable in a Workflow situation. From this example we have:
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
Where github.head_ref
matches the docs.
However, from within JS, we need to use (for example) github.context.eventName
otherwise these are undefined. See example above.
I suppose using a workflow and creating a custom action are two different things but the language is almost exactly the same as well as the data being operated on (notwithstanding the subtle differences highlighted above).
As mentioned above, should usage from within a Workflow versus using from JS/TS be called out in the docs?
Additional information
Referenced in this discussion
Thanks for opening this issue. A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines.
👋 @ftclausen Thanks so much for opening an issue! We appreciate all the extra context. I'll triage this for the team to take a look :eyes:
Thanks for opening an issue! We've triaged this issue for technical review by a subject matter expert :eyes:
This is a gentle bump for the docs team that this issue is waiting for technical review.
This is a gentle bump for the docs team that this issue is waiting for technical review.
This is a gentle bump for the docs team that this issue is waiting for technical review.
This is a gentle bump for the docs team that this issue is waiting for technical review.
Thank you so much for opening an issue @ftclausen and for your patience as we work through our backlog of reviews!
I've spoken with the team and while we can appreciate the confusion different but similar attribute names can cause when working with GitHub Actions, since the eventName
attribute name is specific to the actions/github
and actions/toolkit
packages, and isn't a GitHub payload parameter or workflow context name, we aren't going to document the syntax. Instead we recommend referring to the specific action's README or repository documentation.
Thanks again for your interest and passion in improving the GitHub Docs :yellow_heart:.