docs icon indicating copy to clipboard operation
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.

Open ftclausen opened this issue 2 years ago • 4 comments

Code of Conduct

What article on docs.github.com is affected?

github-context

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

ftclausen avatar Jan 31 '23 00:01 ftclausen

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.

welcome[bot] avatar Jan 31 '23 00:01 welcome[bot]

👋 @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:

cmwilson21 avatar Jan 31 '23 15:01 cmwilson21

Thanks for opening an issue! We've triaged this issue for technical review by a subject matter expert :eyes:

github-actions[bot] avatar Mar 01 '23 06:03 github-actions[bot]

This is a gentle bump for the docs team that this issue is waiting for technical review.

github-actions[bot] avatar Mar 29 '23 17:03 github-actions[bot]

This is a gentle bump for the docs team that this issue is waiting for technical review.

github-actions[bot] avatar Jul 05 '23 16:07 github-actions[bot]

This is a gentle bump for the docs team that this issue is waiting for technical review.

github-actions[bot] avatar Aug 03 '23 16:08 github-actions[bot]

This is a gentle bump for the docs team that this issue is waiting for technical review.

github-actions[bot] avatar Sep 02 '23 16:09 github-actions[bot]

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:.

vgrl avatar Sep 21 '23 21:09 vgrl