Manual workflow triggers in Github Actions
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
GitHub Actions is a powerful platform that allows developers to automate, customize, and enhance their workflows directly in the GitHub environment. One of the notable features of GitHub Actions is the ability to run workflows manually. This is achieved through a feature known as workflow_dispatch.
Understanding workflow_dispatch
The workflow_dispatch event is a special trigger that allows users to manually execute a workflow from the GitHub user interface. This feature is particularly useful for running tasks that do not require automatic execution, such as generating reports, running tests on demand, or deploying to specific environments after verification.
Configuring a Manual Trigger
To set up a manual workflow trigger, you need to define it in your repository's workflow YAML file. Below is a basic example:
In this example, the on: workflow_dispatch section specifies that the workflow should only be triggered manually. There are no automatic triggers (like push or pull_request), meaning it won't run unless a user explicitly starts it from the GitHub interface.
Advanced Use of Inputs
One powerful aspect of workflow_dispatch is the support for inputs. These inputs allow users to specify parameters when they trigger a workflow. For example, you might let users choose a specific testing environment or branch.
When a user triggers this workflow, they will be prompted to select or enter their desired environment, enhancing flexibility and control over how and where workflows run.
Workflow Dispatch via API
In addition to using the GitHub UI, workflows can also be triggered programmatically using the GitHub API, which is useful for integrating with external systems.
Below is an example of triggering a workflow using GitHub's REST API with curl:
Remember to replace YOUR_GITHUB_TOKEN, OWNER, REPO, and WORKFLOW_ID with appropriate values.
Best Practices for Manual Triggers
- Security: Use inputs to let users specify necessary parameters, but validate these inputs within your jobs. Be cautious with sensitive operations.
- Documentation: Document the purpose and usage of manually triggered workflows so your team knows when and how to use them.
- Conditional Execution: Use guards (
ifstatements) in your jobs to prevent unnecessary steps based on the provided inputs. - Access Control: Ensure that only authorized personnel can trigger sensitive workflows by using repository settings and permissions.
Summary Table
| Feature | Description | Example Usage |
workflow_dispatch | Allows manual triggering of workflows | On-demand tests, reports, or deployments |
| Inputs | Enables parameterization of workflows | Specify environments, branches, or configurations |
| API Triggering | Run workflows programmatically via API | Automated systems, third-party integrations |
| Best Practices | Security, documentation, conditional execution, access control | Parameter validation, role-based permissions, and clear docs |
By taking full advantage of workflow_dispatch in GitHub Actions, development teams can create more flexible, controlled, and efficient CI/CD pipelines tailored to their specific workflow needs.

