I'm writing a custom action in JavaScript.
In my GitHub action, I want to make a decision based on the type of the event that triggered it. For example was it a push or a cron job.
How can I access this information with the GitHub Actions Toolkit?
Searching logs On GitHub.com, navigate to the main page of the repository. Under your repository name, click Actions. In the left sidebar, click the workflow you want to see. From the list of workflow runs, click the name of the run to see the workflow run summary.
Earlier this week, GitHub announced a new feature which allows developers to trigger workflows manually from within the “Actions” tab.
From this page, you can use GITHUB_EVENT_NAME
environment variable.
The name of the webhook event that triggered the workflow.
If you are using the @actions/github
package, it gives you access to a context
object which allows you to get the event name like so:
import {context} from '@actions/github';
console.log(context.eventName);
Both methods will give you the same result.
The title of the question and the content of it contradict to each other. You mention event type in the title but the question asks about something else:
was it a push or a cron job
This is not the event type, this is the event name. The name can be accessed via the github.event_name
variable and the type can be read from github.event.action
. (Note the difference between the underscore and the dot.)
Yes, the naming is quite confusing. Just one level under the on
in a workflow yaml, you specify the event name. What you specify even one level deeper after they keyword types
is also called "action". Here is an example:
name: Foo
on:
pull_request:
types: ["ready_for_review", "converted_to_draft"]
jobs:
bar:
runs-on: ["ubuntu-latest"]
steps:
- run: echo "event name is:" ${{ github.event_name }}
- run: echo "event type is:" ${{ github.event.action }}
This outputs:
event name is: pull_request
event type is: converted_to_draft
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With