Event Triggers in GitHub Actions: push, pull_request u0026 more Quiz Quiz

Dive into the essentials of event triggers in GitHub Actions, exploring push, pull_request, workflow_dispatch, and other key concepts. This quiz helps you grasp how different events initiate workflows, enhancing your automation expertise.

  1. Trigger Types

    Which event trigger starts a workflow when changes are pushed to a repository branch, such as when new code is committed to 'main'?

    1. release
    2. push
    3. pull_request
    4. workflow_run

    Explanation: The 'push' event initiates a workflow whenever changes are committed to a branch. 'pull_request' is triggered by pull request actions, not direct pushes. 'workflow_run' refers to completed workflows and is not tied to code commits. 'release' is activated by release creation or publication, not by code pushes.

  2. Working with Pull Requests

    Suppose a workflow should run only when a pull request is opened or updated, not when code is pushed directly. Which event trigger is most appropriate?

    1. deployment
    2. pull_request
    3. push
    4. issue_comment

    Explanation: 'pull_request' triggers workflows when pull requests are opened, synchronized, or updated. 'push' is for branch commits rather than pull request actions. 'issue_comment' pertains to comments and does not relate to code changes. 'deployment' focuses on deployment events and is unrelated to pull requests.

  3. Manual Workflow Dispatch

    If you want a workflow to be started manually from the workflow interface, which event trigger should you specify in your workflow configuration?

    1. push
    2. workflow_dispatch
    3. manual_trigger
    4. schedule

    Explanation: The 'workflow_dispatch' event enables users to manually initiate a workflow from the interface. 'push' and 'schedule' are automatic triggers; the former occurs on code commits, the latter based on preset times. 'manual_trigger' does not exist as a recognized event trigger in configurations.

  4. Scheduled Events

    Which event trigger would you use to automatically run a workflow at regular intervals, such as every night at midnight?

    1. commit_event
    2. push
    3. pull_request
    4. schedule

    Explanation: 'schedule' uses a cron syntax to automate workflows at set times, perfect for nightly runs. 'pull_request' and 'push' react only to repository activity such as merges or commits. 'commit_event' is not an actual supported event trigger, making it an incorrect choice.

  5. Event Context and Filtering

    To trigger a workflow only when a release is published, which filter would you use with the 'release' event in your workflow configuration?

    1. actions: [created]
    2. types: [published]
    3. tags: [release]
    4. branches: [published]

    Explanation: 'types: [published]' ensures the workflow runs specifically when a release is published. 'branches: [published]' and 'tags: [release]' are invalid or misleading, as releases do not map to branches or tags this way in event filtering. 'actions: [created]' is not a valid filter for the release event context.