I did manage to find how to do so by first adding a step to print out the github object.

steps:
  - name: Echo github obj
    run: echo ${{ toJson(github) }}

This allowed me to see that the github object contains an event_name key, which, in the case of a workflow_dispatch event, contains workflow_dispatch.

It was then very easy to modify my if clause to also check for this key.

my-job:
  runs-on: [ubuntu-latest]
  if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch'
  steps:
    # more steps

note: somehow using double quotes around "workflow_dispatch" in the if clause raises an error (Unknown identifier), so make sure to use single quotes

🌐
GitHub
docs.github.com › actions › using-workflows › events-that-trigger-workflows
Events that trigger workflows - GitHub Docs
You can configure your workflows to run when specific activity on GitHub happens, at a scheduled time, or when an event outside of GitHub occurs.
🌐
GitHub
docs.github.com › en › rest › using-the-rest-api › github-event-types
GitHub event types - GitHub Docs
September 6, 2011 - Each event object includes a payload property and the value is unique to each event type. The payload object for this event is described below. Activity related to an issue or pull request comment. The type of activity is specified in the action property of the payload object.
Discussions

Documentation for github.event objects
Is there a way to see the actual documentation / specs for the github object we can access when setting up workflows? I tried to echo github.event for instance but that just prints object… My end g... More on github.com
🌐 github.com
4
12
In GitHub Actions, how to get the type of a trigger event as a variable? - Stack Overflow
I’m trying to set up a GitHub action for when pull requests are opened or closed and I’d like to get the type of the trigger to add it to the message. The YAML is as follows: on: pull_request: ... More on stackoverflow.com
🌐 stackoverflow.com
Complete list of github actions contexts - Stack Overflow
Context variables are available in most cases and exceptions are documented (as you found): https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log · The payload, on the other hand, depends on the event type. More on stackoverflow.com
🌐 stackoverflow.com
continuous integration - Which properties does `github.event` in a GitHub Workflow have? - Stack Overflow
When using GitHub Actions, it is possible to access contexts in an expression. One of the contexts is the github context. It has a property github.event, which is an object. What properties does the More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
docs.github.com › en › actions › reference › workflows-and-actions › contexts
Contexts reference - GitHub Docs
The inputs context contains input properties passed to an action, to a reusable workflow, or to a manually triggered workflow. For reusable workflows, the input names and types are defined in the workflow_call event configuration of a reusable workflow, and the input values are passed from jobs.<job_id>.with in an external workflow that calls the reusable workflow.
🌐
GitHub
docs.github.com › articles › getting-started-with-github-actions
Understanding GitHub Actions - GitHub Docs
You can configure a GitHub Actions workflow to be triggered when an event occurs in your repository, such as a pull request being opened or an issue being created. Your workflow contains one or more jobs which can run in sequential order or ...
Find elsewhere
🌐
GitHub
docs.github.com › en › webhooks › webhook-events-and-payloads
Webhook events and payloads - GitHub Docs
If you want to receive an event when a label is added to or removed from an issue, pull request, or discussion, use the labeled or unlabeled action type for the issues, pull_request, or discussion events instead. To subscribe to this event, a GitHub App must have at least read-level access for the "Metadata" repository permission.
🌐
DEV Community
dev.to › kalkwst › workflow-triggering-events-and-event-actions-5cec
Workflow Triggering Events and Event Actions - DEV Community
September 18, 2023 - This means that when you push changes to a branch, or even when you create a new branch or a tag, the event will trigger. The push workflow is typically used in branch-level CI/CD actions. For example, when you push code changes to a repository, GitHub Actions can automatically build the code, run the code through a linter to check for guideline inconsistencies and run the related unit tests.
Top answer
1 of 3
41

I think you want to distinguish between context variables and payloads.

Context variables are available in most cases and exceptions are documented (as you found): https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log

The payload, on the other hand, depends on the event type. If you run a workflow as a result of on: pull_request you'll get a different payload than running it as a result of on: push (etc..).

I have never seen docs that list all payloads, but I believe you can take inspiration from the webhooks. For example, if you run a workflow when a pull request is created, you could look at the webhook payload for pull requests here: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-example-33

Since the two not are documented to be the same, you might have to resort back to just dumping an event and checking what you actually get. In the docs, GitHub has an example how to dump contexts as part of a workflow:

jobs:
  one:
    runs-on: ubuntu-latest
    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJSON(github) }}
        run: echo "$GITHUB_CONTEXT"
2 of 3
8

Yes apparently dumping is the way to go. I have not done it myself, but I have found the dump of the github context in this gist very helpful: https://gist.github.com/colbyfayock/1710edb9f47ceda0569844f791403e7e

{
  "token": "[token]",
  "job": "notifySlack",
  "ref": "refs/pull/4/merge",
  "sha": "[shad]",
  "repository": "colbyfayock/demo-github-actions",
  "repository_owner": "colbyfayock",
  "repositoryUrl": "git://github.com/colbyfayock/demo-github-actions.git",
  "run_id": 120667610,
  "run_number": "2",
  "actor": "colbyfayock",
  "workflow": "Slack Notifications",
  "head_ref": "colbyfayock-patch-2",
  "base_ref": "master",
  "event_name": "pull_request",
  "event": {
    "action": "opened",
    "number": 4,
    "pull_request": {
      "_links": {
        "comments": {
          "href": "..."
        },
        "commits": {
          "href": "https://api.github.com/repos/colbyfayock/demo-github-actions/pulls/4/commits"
        },
        "html": {
          "href": "..."
        },
        "issue": {
          "href": "..."
        },
        "review_comment": {
          "href": "https://api.github.com/repos/colbyfayock/demo-github-actions/pulls/comments{/number}"
        },
        "review_comments": {
          "href": "..."
        },
        "self": {
          "href": "..."
        },
        "statuses": {
          "href": "..."
        }
      },
      "additions": 3,
      "assignee": null,
      "assignees": [],
      "author_association": "OWNER",
      "base": {
        "label": "colbyfayock:master",
        "ref": "master",
        "repo": {
          "archive_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/{archive_format}{/ref}",
          "archived": false,
          "assignees_url": "...",
          "blobs_url": "...",
          "branches_url": "...",
          "clone_url": "https://github.com/colbyfayock/demo-github-actions.git",
          "collaborators_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/collaborators{/collaborator}",
          "comments_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/comments{/number}",
          "commits_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/commits{/sha}",
          "compare_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/compare/{base}...{head}",
          "contents_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/contents/{+path}",
          "contributors_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/contributors",
          "created_at": "2020-05-30 T04:08:32 Z",
          "default_branch": "master",
          "deployments_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/deployments",
          "description": null,
          "disabled": false,
          "downloads_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/downloads",
          "events_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/events",
          "fork": false,
          "forks": 0,
          "forks_count": 0,
          "forks_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/forks",
          "full_name": "colbyfayock/demo-github-actions",
          "git_commits_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/commits{/sha}",
          "git_refs_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/refs{/sha}",
          "git_tags_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/tags{/sha}",
          "git_url": "git://github.com/colbyfayock/demo-github-actions.git",
          "has_downloads": true,
          "has_issues": true,
          "has_pages": false,
          "has_projects": true,
          "has_wiki": true,
          "homepage": null,
          "hooks_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/hooks",
          "html_url": "https://github.com/colbyfayock/demo-github-actions",
          "id": 268006728,
          "issue_comment_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues/comments{/number}",
          "issue_events_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues/events{/number}",
          "issues_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues{/number}",
          "11": 18,
          "keys_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/keys{/key_id}",
          "labels_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/labels{/name}",
          "language": "JavaScript",
          "languages_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/languages",
          "license": {
            "key": "mit",
            "name": "MIT License",
            "node_id": "[node ID]",
            "spdx_id": "MIT",
            "url": "https://api.github.com/licenses/mit"
          },
          "merges_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/merges",
          "milestones_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/milestones{/number}",
          "mirror_url": null,
          "name": "demo-github-actions",
          "node_id": "[node id]",
          "notifications_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/notifications{?since,all,participating}",
          "open_issues": 2,
          "open_issues_count": 2,
          "owner": {
            "avatar_url": "https://avatars2.githubusercontent.com/u/1045274?v=4",
            "events_url": "https://api.github.com/users/colbyfayock/events{/privacy}",
            "followers_url": "https://api.github.com/users/colbyfayock/followers",
            "following_url": "https://api.github.com/users/colbyfayock/following{/other_user}",
            "gists_url": "https://api.github.com/users/colbyfayock/gists{/gist_id}",
            "gravatar_id": "",
            "html_url": "https://github.com/colbyfayock",
            "id": 1045274,
            "login": "colbyfayock",
            "node_id": "[node id]",
            "organizations_url": "https://api.github.com/users/colbyfayock/orgs",
            "received_events_url": "https://api.github.com/users/colbyfayock/received_events",
            "repos_url": "https://api.github.com/users/colbyfayock/repos",
            "site_admin": false,
            "starred_url": "https://api.github.com/users/colbyfayock/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/colbyfayock/subscriptions",
            "type": "User",
            "url": "https://api.github.com/users/colbyfayock"
          },
          "private": false,
          "pulls_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/pulls{/number}",
          "pushed_at": "2020-05-31 T15:18:27 Z",
          "releases_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/releases{/id}",
          "size": 52,
          "ssh_url": "[email protected]:colbyfayock/demo-github-actions.git",
          "stargazers_count": 0,
          "stargazers_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/stargazers",
          "statuses_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/statuses/{sha}",
          "subscribers_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/subscribers",
          "subscription_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/subscription",
          "svn_url": "https://github.com/colbyfayock/demo-github-actions",
          "tags_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/tags",
          "teams_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/teams",
          "trees_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/trees{/sha}",
          "updated_at": "2020-05-31 T15:18:10 Z",
          "url": "https://api.github.com/repos/colbyfayock/demo-github-actions",
          "watchers": 0,
          "watchers_count": 0
        },
        "sha": "[sha]",
        "user": {
          "avatar_url": "https://avatars2.githubusercontent.com/u/1045274?v=4",
          "events_url": "https://api.github.com/users/colbyfayock/events{/privacy}",
          "followers_url": "https://api.github.com/users/colbyfayock/followers",
          "following_url": "https://api.github.com/users/colbyfayock/following{/other_user}",
          "gists_url": "https://api.github.com/users/colbyfayock/gists{/gist_id}",
          "gravatar_id": "",
          "html_url": "https://github.com/colbyfayock",
          "id": 1045274,
          "login": "colbyfayock",
          "node_id": "[node id]",
          "organizations_url": "https://api.github.com/users/colbyfayock/orgs",
          "received_events_url": "https://api.github.com/users/colbyfayock/received_events",
          "repos_url": "https://api.github.com/users/colbyfayock/repos",
          "site_admin": false,
          "starred_url": "https://api.github.com/users/colbyfayock/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/colbyfayock/subscriptions",
          "type": "User",
          "url": "https://api.github.com/users/colbyfayock"
        }
      },
      "body": "",
      "changed_files": 1,
      "closed_at": null,
      "comments": 0,
      "11": 18,
      "comments_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues/4/comments",
      "commits": 1,
      "commits_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/pulls/4/commits",
      "created_at": "2020-05-31 T15:18:30 Z",
      "deletions": 1,
      "diff_url": "https://github.com/colbyfayock/demo-github-actions/pull/4.diff",
      "draft": false,
      "head": {
        "label": "colbyfayock:colbyfayock-patch-2",
        "ref": "colbyfayock-patch-2",
        "repo": {
          "archive_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/{archive_format}{/ref}",
          "archived": false,
          "assignees_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/assignees{/user}",
          "blobs_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/blobs{/sha}",
          "branches_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/branches{/branch}",
          "clone_url": "https://github.com/colbyfayock/demo-github-actions.git",
          "collaborators_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/collaborators{/collaborator}",
          "comments_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/comments{/number}",
          "commits_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/commits{/sha}",
          "compare_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/compare/{base}...{head}",
          "contents_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/contents/{+path}",
          "contributors_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/contributors",
          "created_at": "2020-05-30 T04:08:32 Z",
          "default_branch": "master",
          "deployments_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/deployments",
          "description": null,
          "disabled": false,
          "downloads_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/downloads",
          "events_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/events",
          "fork": false,
          "forks": 0,
          "forks_count": 0,
          "forks_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/forks",
          "full_name": "colbyfayock/demo-github-actions",
          "git_commits_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/commits{/sha}",
          "git_refs_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/refs{/sha}",
          "git_tags_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/tags{/sha}",
          "git_url": "git://github.com/colbyfayock/demo-github-actions.git",
          "has_downloads": true,
          "has_issues": true,
          "has_pages": false,
          "has_projects": true,
          "has_wiki": true,
          "homepage": null,
          "hooks_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/hooks",
          "html_url": "https://github.com/colbyfayock/demo-github-actions",
          "id": 268006728,
          "issue_comment_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues/comments{/number}",
          "issue_events_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues/events{/number}",
          "issues_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues{/number}",
          "keys_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/keys{/key_id}",
          "labels_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/labels{/name}",
          "language": "JavaScript",
          "languages_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/languages",
          "license": {
            "key": "mit",
            "name": "MIT License",
            "node_id": "[node ID]",
            "spdx_id": "MIT",
            "url": "https://api.github.com/licenses/mit"
          },
          "merges_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/merges",
          "milestones_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/milestones{/number}",
          "mirror_url": null,
          "name": "demo-github-actions",
          "node_id": "[node id]",
          "notifications_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/notifications{?since,all,participating}",
          "open_issues": 2,
          "open_issues_count": 2,
          "owner": {
            "avatar_url": "https://avatars2.githubusercontent.com/u/1045274?v=4",
            "events_url": "https://api.github.com/users/colbyfayock/events{/privacy}",
            "followers_url": "https://api.github.com/users/colbyfayock/followers",
            "11": "18",
            "following_url": "https://api.github.com/users/colbyfayock/following{/other_user}",
            "gists_url": "https://api.github.com/users/colbyfayock/gists{/gist_id}",
            "gravatar_id": "",
            "html_url": "https://github.com/colbyfayock",
            "id": "1045274",
            "login": "colbyfayock",
            "node_id": "[node id]",
            "organizations_url": "https://api.github.com/users/colbyfayock/orgs",
            "received_events_url": "https://api.github.com/users/colbyfayock/received_events",
            "repos_url": "https://api.github.com/users/colbyfayock/repos",
            "site_admin": false,
            "starred_url": "https://api.github.com/users/colbyfayock/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/colbyfayock/subscriptions",
            "type": "User",
            "url": "https://api.github.com/users/colbyfayock"
          },
          "private": false,
          "pulls_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/pulls{/number}",
          "pushed_at": "2020-05-31 T15:18:27 Z",
          "releases_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/releases{/id}",
          "size": 52,
          "ssh_url": "[email protected]:colbyfayock/demo-github-actions.git",
          "stargazers_count": 0,
          "stargazers_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/stargazers",
          "statuses_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/statuses/{sha}",
          "subscribers_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/subscribers",
          "subscription_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/subscription",
          "svn_url": "https://github.com/colbyfayock/demo-github-actions",
          "tags_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/tags",
          "teams_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/teams",
          "trees_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/trees{/sha}",
          "updated_at": "2020-05-31 T15:18:10 Z",
          "url": "https://api.github.com/repos/colbyfayock/demo-github-actions",
          "watchers": 0,
          "watchers_count": 0
        },
        "sha": "[sha]",
        "user": {
          "avatar_url": "https://avatars2.githubusercontent.com/u/1045274?v=4",
          "events_url": "https://api.github.com/users/colbyfayock/events{/privacy}",
          "followers_url": "https://api.github.com/users/colbyfayock/followers",
          "following_url": "https://api.github.com/users/colbyfayock/following{/other_user}",
          "gists_url": "https://api.github.com/users/colbyfayock/gists{/gist_id}",
          "gravatar_id": "",
          "html_url": "https://github.com/colbyfayock",
          "id": 1045274,
          "login": "colbyfayock",
          "node_id": "[node id]",
          "organizations_url": "https://api.github.com/users/colbyfayock/orgs",
          "received_events_url": "https://api.github.com/users/colbyfayock/received_events",
          "repos_url": "https://api.github.com/users/colbyfayock/repos",
          "site_admin": false,
          "starred_url": "https://api.github.com/users/colbyfayock/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/colbyfayock/subscriptions",
          "type": "User",
          "url": "https://api.github.com/users/colbyfayock"
        }
      },
      "html_url": "https://github.com/colbyfayock/demo-github-actions/pull/4",
      "id": 425626799,
      "issue_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues/4",
      "labels": [],
      "locked": false,
      "maintainer_can_modify": false,
      "merge_commit_sha": null,
      "mergeable": null,
      "mergeable_state": "unknown",
      "merged": false,
      "merged_at": null,
      "merged_by": null,
      "milestone": null,
      "node_id": "[node id]",
      "number": 4,
      "patch_url": "https://github.com/colbyfayock/demo-github-actions/pull/4.patch",
      "rebaseable": null,
      "requested_reviewers": [],
      "requested_teams": [],
      "review_comment_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/pulls/comments{/number}",
      "review_comments": 0,
      "review_comments_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/pulls/4/comments",
      "state": "open",
      "statuses_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/statuses/[sha]",
      "title": "Update README.md",
      "updated_at": "2020-05-31 T15:18:30 Z",
      "url": "https://api.github.com/repos/colbyfayock/demo-github-actions/pulls/4",
      "user": {
        "11": 18,
        "avatar_url": "https://avatars2.githubusercontent.com/u/1045274?v=4",
        "events_url": "https://api.github.com/users/colbyfayock/events{/privacy}",
        "followers_url": "https://api.github.com/users/colbyfayock/followers",
        "following_url": "https://api.github.com/users/colbyfayock/following{/other_user}",
        "gists_url": "https://api.github.com/users/colbyfayock/gists{/gist_id}",
        "gravatar_id": "",
        "html_url": "https://github.com/colbyfayock",
        "id": 1045274,
        "login": "colbyfayock",
        "node_id": "[node id]",
        "organizations_url": "https://api.github.com/users/colbyfayock/orgs",
        "received_events_url": "https://api.github.com/users/colbyfayock/received_events",
        "repos_url": "https://api.github.com/users/colbyfayock/repos",
        "site_admin": false,
        "starred_url": "https://api.github.com/users/colbyfayock/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/colbyfayock/subscriptions",
        "type": "User",
        "url": "https://api.github.com/users/colbyfayock"
      }
    },
    "repository": {
      "archive_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/{archive_format}{/ref}",
      "archived": false,
      "assignees_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/assignees{/user}",
      "blobs_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/blobs{/sha}",
      "branches_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/branches{/branch}",
      "clone_url": "https://github.com/colbyfayock/demo-github-actions.git",
      "collaborators_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/collaborators{/collaborator}",
      "comments_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/comments{/number}",
      "commits_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/commits{/sha}",
      "compare_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/compare/{base}...{head}",
      "contents_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/contents/{+path}",
      "contributors_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/contributors",
      "created_at": "2020-05-30 T04:08:32 Z",
      "default_branch": "master",
      "deployments_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/deployments",
      "description": null,
      "disabled": false,
      "downloads_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/downloads",
      "events_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/events",
      "fork": false,
      "forks": 0,
      "forks_count": 0,
      "forks_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/forks",
      "full_name": "colbyfayock/demo-github-actions",
      "git_commits_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/commits{/sha}",
      "git_refs_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/refs{/sha}",
      "git_tags_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/git/tags{/sha}",
      "git_url": "git://github.com/colbyfayock/demo-github-actions.git",
      "has_downloads": true,
      "has_issues": true,
      "has_pages": false,
      "has_projects": true,
      "has_wiki": true,
      "homepage": null,
      "hooks_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/hooks",
      "html_url": "https://github.com/colbyfayock/demo-github-actions",
      "id": 268006728,
      "issue_comment_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues/comments{/number}",
      "issue_events_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues/events{/number}",
      "issues_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/issues{/number}",
      "keys_url": "https://api.github.com/repos/colbyfayock/demo-github-actions/keys{/key_id}",
      "labels_url…
🌐
Graphite
graphite.com › guides › how-to-use-github-actions-to-trigger-notifications-during-reviews
How to use GitHub Actions to trigger notifications during reviews
GitHub Actions is a powerful automation tool that allows developers to create workflows triggered by events in their GitHub repository. One common use case is to set up notifications for pull request (PR) reviews, especially when approvals occur.
🌐
GitHub
docs.github.com › en › rest › using-the-rest-api › issue-event-types
Issue event types - GitHub Docs
Because pull requests are issues, issue and pull request numbers do not overlap in a repository. For example, if you open your first issue in a repository, the number will be 1. If you then open a pull request, the number will be 2. Each event type specifies if the event occurs in pull request, issues, or both.
🌐
Graphite
graphite.com › guides › github-actions-on-pull-requests
Using GitHub Actions on pull requests
on: pull_request: This specifies that the workflow should trigger on pull request events. You can specify further what types of pull request actions trigger the workflow, such as when pull requests are opened, synchronized, reopened, or closed. Reacting to different types of pull request actions: When a pull request is merged, you might want to trigger a deployment or further integration tests. Use the conditional if: github.event.pull_request.merged == true within your job steps to specify actions that should only occur if the pull request has been merged.
Top answer
1 of 1
22

To distinguish the different events, you can always check for github.event_name:

Copyjobs:
  test:
    runs-on: ubuntu-18.04
    if: github.event_name == 'push'

The properties of github.event depend on what kind of event was triggered. They are documented in the "Event Types & Payload" section of the REST API v3 documentation. The section "Webhook events" of the "Events that trigger workflows" documentation contains links to every object in the "Webhook event payload" column.

Example

You have a create event, therefore github.event_name == 'create'. You can access the following properties in your workflow.yml (as described in Event Types & Payload / CreateEvent)

  • ${{ github.event.ref_type }}
  • ${{ github.event.ref }}
  • ${{ github.event.master_branch }}
  • ${{ github.event.description }}

Complete workflow example

This is a single workflow, which runs different jobs depending on whether it was triggered by a push or a tag creation event.

  • Runs tests on pushes and tag creations
  • Packages the application on any tag
  • Deploys the app when the tag starting with v
Copyname: CI

on:
  push:
    branches:
      - master
  create:
    tags:

jobs:

  test:
    runs-on: ubuntu-18.04

    steps:
      - <YOUR TESTSTEPS HERE>

  dist:
    runs-on: ubuntu-18.04
    if: github.event_name == 'create'

    steps:
      - <YOUR BUILDSTEPS HERE>
      - name: Upload artifact
        uses: actions/upload-artifact@v1
        with:
          name: mypackage
          path: dist

  deploy:
    needs: dist
    runs-on: ubuntu-18.04
    if: github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v')
    # This does the same:
    # if: github.event_name == 'create' && github.event.ref_type == 'tag' && startsWith(github.event.ref, 'v')

    steps:
      - name: Download artifact
        uses: actions/download-artifact@v1
        with:
          name: mypackage
      - <YOUR DEPLOY STEPS HERE>

Note that github.ref and github.event.ref differs:

  • github.ref == 'refs/tags/v1.2.5'
  • github.event.ref == 'v1.2.5'
🌐
Medium
medium.com › @sangeetv09 › understanding-more-about-event-triggers-event-filters-and-activity-types-in-github-actions-8bfaec5b101e
Understanding more about Event Triggers, Event Filters and Activity Types in GitHub Actions | by sangeetha arun | Medium
September 9, 2024 - In this article, we will look at some examples of GitHub Actions event triggers, event filters, and activity types. GitHub Actions rely on triggers, which are events that initiate automated workflows.
🌐
GitHub
github.com › actions › github-script › discussions › 419
Get the id from the issue_comment trigger event · actions/github-script · Discussion #419
This is my action: on: issue_comment: types: [created] branches: - develop · jobs: deploy: if: github.event.issue.pull_request && contains(github.event.comment.body, '/deploy') runs-on: ubuntu-latest steps: - name: Checkout PR branch uses: actions/checkout@v3 with: ref: ${{ github.event.issue.pull_request.head.sha }} - uses: actions/github-script@v6 with: script: | github.rest.issues.updateComment({ comment_id: context.comment.id, owner: context.repo.owner, repo: context.repo.repo, body: '${{ github.event.comment.body }} 👋 Thanks for reporting!'
Author   actions
🌐
YouTube
youtube.com › watch
GitHub Actions - Trigger on a Custom Event - YouTube
This video is part 11 in my Introduction to GitHub Actions video series. In this video you are going to learn how to trigger a GitHub Actions workflow using ...
Published   December 12, 2024
🌐
Flightcontrol
flightcontrol.dev › docs › guides › advanced › github-actions
Using GitHub Actions Deployment Events - Flightcontrol
This is used in the action to call the Vercel API. name: Trigger Vercel Build on Flightcontrol Deployment Success on: deployment_status: env: VERCEL_TEAM_ID: "team_4Z98W1jFKBTL8XIe3fvWaeSu" VERCEL_PROJECT_NAME: "frontend-dashboard" FC_PROJECT_ID: "cluagwibz000ka6p9uzas7p26" FC_SERVICE_GIVEN_ID: "backend-api" jobs: trigger-vercel: runs-on: - runs-on=${{ github.run_id }} - runner=2cpu-linux-x64 if: > github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.event.deployment.payload.deployment.projectId == '${{ env.FC_PROJECT_ID }}' && github.event.de
🌐
Medium
medium.com › @ravichandola › github-events-6641bcf5b571
GitHub Events. An event is a specific activity in a… | by Ravi Chandola | Medium
November 10, 2022 - Github events are repository webhooks to specify which events triggered the associated webhook then the workflow would be listen for.
🌐
GitHub
docs.github.com › en › actions › writing-workflows › choosing-when-your-workflow-runs › triggering-a-workflow
Triggering a workflow - GitHub Docs
If you do want to trigger a workflow from within a workflow run, you can use a GitHub App installation access token or a personal access token instead of GITHUB_TOKEN to trigger events that require a token. If you use a GitHub App, you'll need to create a GitHub App and store the app ID and private key as secrets. For more information, see Making authenticated API requests with a GitHub App in a GitHub Actions workflow.