How to trigger a step manually with GitHub Actions
Manual triggering of workflows in GitHub Actions can be achieved through several methods, primarily using the event. Below, I will detail how to set up and use this feature.1. Update the workflow file to enable manual triggeringFirst, you need to add the event to your workflow file to enable manual triggering. This can be done by editing the YAML workflow file located in your repository's directory. For example, if you have a workflow file named , you can modify it as follows:In the above example, has been added under the key. This means the workflow can now be triggered automatically when pushing to the main branch or manually initiated.2. Manually trigger the workflow via GitHub UIAfter updating and committing the workflow file to your repository, you can manually trigger the workflow through the GitHub UI.Follow these steps:Log in to your GitHub account and navigate to the repository containing the workflow.Click the 'Actions' tab to enter the GitHub Actions interface.On the left, you will see different workflows; select the one you want to manually trigger.At the top of the workflow, you will see a 'Run workflow' button; click it.If needed, select a branch, then click 'Run workflow' to trigger the workflow.3. Use additional input optionsThe event also supports defining input parameters, allowing you to provide additional options when manually triggering the workflow. For example:With this setup, when you trigger the workflow via the GitHub UI, you will be prompted to fill in additional options such as the log level and environment name.SummaryBy adding the event to your workflow file and using the GitHub UI, you can manually trigger GitHub Actions workflows. This method is useful for scenarios requiring manual control or running workflows under specific conditions, such as deploying to production without code commits.1. Using eventGitHub allows you to manually trigger workflows by using the event in your workflow file. First, you need to specify as the trigger event. For example:On the main page of your GitHub repository, click the 'Actions' tab above the repository name, select the workflow you want to manually trigger, and you will see a 'Run workflow' button on the right. Click this button, select a branch, and fill in any required input parameters (if the workflow has defined inputs), then click 'Run workflow' to trigger execution.2. Using eventAnother method is using the event, which allows external events to trigger GitHub Actions. First, add as the trigger event in your workflow file:Then, you can trigger the workflow using the GitHub API by sending a POST request to the following URL:You need to provide a valid GitHub token and include the event type and client payload in the request, for example:SummaryManual triggering of GitHub Actions provides flexibility, allowing developers to start workflows as needed. By configuring or events, developers can easily run CI/CD pipelines without code changes. This is particularly useful when additional control over workflow execution is required, such as deploying to production or running specific tests.Manual triggering of GitHub Actions workflows can be achieved through several methods. I will detail two common approaches: using workflowdispatch and repositorydispatch events.1. Using eventis a straightforward method that allows users to manually run workflows from the GitHub repository's Actions tab or via the GitHub API. To use this method, you need to explicitly declare in your workflow file.Step 1: Add to your workflow file (typically located in directory as a YAML file). For example:Step 2: Commit and push the changes to your repository.Step 3: On the GitHub repository page, click the 'Actions' tab, select the relevant workflow from the left, and click the 'Run workflow' button in the top-right corner. Select a branch and fill in any input parameters (if applicable), then click 'Run workflow' to trigger the workflow.2. Using eventAnother option is using event. This method allows more customization and integration with external systems because it triggers workflows by sending a POST request to the GitHub API.Step 1: Declare as the trigger condition in your workflow file:Step 2: Use curl or another tool to send a POST request to the GitHub API to trigger the workflow. You need to generate a personal access token (with and permissions) and use it in the request:Note: In this request, must match the type defined in your workflow file.SummaryBoth methods provide developers and project maintainers with greater flexibility to manually trigger workflows. With , you can simply trigger workflows from the GitHub UI, while offers API-triggered execution, enabling integration with external systems and automation of workflow execution.