Manual workflow triggers in Github Actions
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
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.
Related reading
- Manually change the status of a job to successful in kubernetes
- Many kubernetes secrets vs many keys in one k8s secret
- Mesos not offering disk in its offers
- Message broker vs. database and monitoring
- master branch and ''origin/master'' have diverged, how to ''undiverge'' branches''?
- master branch and ''origin/master'' have diverged, how to ''undiverge'' branches''?
- Message bus and Message queue understanding
- Microk8s dashboard using nginx-ingress via http not working Error no matches for kind Ingress in version extensions/v1beta1

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.