Manual Workflows in GitHub Actions
1. Introduction
Manual Workflows in GitHub Actions allow developers to run jobs on-demand. This can be particularly useful for tasks that do not need to run automatically on a trigger but instead should be executed at the discretion of the user.
2. Key Concepts
- **Workflow**: A configurable automated process made up of one or more jobs.
- **Job**: A set of steps that execute on the same runner.
- **Step**: An individual task that can run commands, scripts, or actions.
- **Action**: A reusable piece of code that can be used in workflows.
- **Manual Trigger**: The ability to start a workflow manually, typically through the GitHub UI, rather than automatically.
3. Creating a Manual Workflow
To create a manual workflow, you will use the `workflow_dispatch` event in your YAML configuration file.
name: Manual Workflow Example
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run a script
run: echo "This is a manual workflow!"
In this example:
- We define a workflow called "Manual Workflow Example".
- We specify that it can be triggered manually with `workflow_dispatch`.
- A job named "build" runs on the latest Ubuntu runner.
- The steps include checking out the code and running a simple echo command.
4. Best Practices
Here are some best practices for using manual workflows:
- Use descriptive names for your workflows and jobs to clarify their purpose.
- Document each step within the workflow to enhance readability and maintainability.
- Limit the number of manual workflows to avoid clutter in the GitHub UI.
- Test workflows thoroughly to ensure they perform as expected before relying on them.
- Utilize inputs for workflows to make them more flexible and user-friendly.
5. FAQ
What is a manual trigger in GitHub Actions?
A manual trigger allows users to start a workflow on-demand rather than automatically based on events like pushes or pull requests.
Can I provide inputs to my manual workflows?
Yes, you can define inputs in your workflow file that users can provide when triggering the workflow.
Can manual workflows run in parallel with other workflows?
Yes, manual workflows can run in parallel with other workflows unless explicitly configured to depend on each other.
6. Flowchart Example
graph TD;
A[Start] --> B{Is manual trigger needed?};
B -- Yes --> C[Run Workflow];
B -- No --> D[Skip Workflow];
C --> E[Complete];
D --> E;