Original link: https://qzkyl.ml/posts/15016.html
GitHub Actions is an automation tool provided by GitHub that helps developers automate workflows such as building, testing, and deploying. Among them, the manual trigger mode is a very common trigger mode, which can manually trigger the workflow when needed.
trigger method
GitHub Actions supports a variety of trigger methods, including:
- push: Triggered when code is pushed to the GitHub repository;
- pull_request: Triggered when a Pull Request is submitted;
- issues: Triggered when new issues appear in the project;
- schedule: triggered according to the scheduled schedule;
- repository_dispatch: triggered by API;
- workflow_dispatch: manually triggered.
Among them, workflow_dispatch is a special trigger method, which can manually trigger the workflow through the GitHub website or API.
Instructions
1. Push trigger
Push triggering is the default triggering method of Github Actions. Whenever new code is pushed to the specified branch in the code base, the execution of Workflow will be triggered. We can enable Push triggering by specifying on.push
in the Workflow file, for example:
1 |
name: CI |
In the above example, when there is new code push in main
branch in the code base, the execution of Workflow will be triggered.
2. Pull Request trigger
In addition to Push triggers, Github Actions also supports Pull Request triggers. When a new Pull Request is submitted, the execution of Workflow can be automatically triggered. We can enable Pull Request triggering by specifying on.pull_request
in the Workflow file, for example:
1 |
name: CI |
In the above example, when a new Pull Request is submitted in main
branch of the code base, the execution of Workflow will be triggered.
3. Issues triggered
The Issues trigger mode is to trigger the execution of Workflow when new issues appear in the GitHub project. We can enable Issues triggering by specifying on.issues in the Workflow file, for example:
1 |
name: CI |
In the above example, when there are new issues or reopened issues in the GitHub project, the execution of Workflow will be triggered.
It should be noted that if you need to use the Issues trigger method, you need to specify the corresponding issues type in the Workflow file, such as opened (new), reopened (reopened), closed (closed) and so on. At the same time, you need to enable the Issues option in the GitHub repository to make the issues trigger method take effect.
4. Timing trigger
Github Actions also supports timing triggering, which can automatically trigger the execution of Workflow according to a certain time interval. We can enable timing triggers by specifying on.schedule
in the Workflow file, for example:
1 |
name: CI |
In the above example, the execution of Workflow will be automatically triggered at 0:00 every day.
5. External trigger
Github Actions also supports external triggering, which can trigger the execution of Workflow by calling the REST API of Github Actions. We can enable external triggering by specifying on.repository_dispatch
in the Workflow file, for example:
1 |
name: CI |
In the above example, when an event of build
type is sent by calling the REST API of Github Actions, the execution of Workflow will be triggered.
A custom event can be sent using the following curl
command:
1 |
curl -X POST \ |
Values that need to be replaced:
-
OWNER
– The owner username of the project -
REPO
– the warehouse name where the Github Action needs to be triggered -
YOUR_TOKEN
– Personal access token with repo permissions -
KEYWORDS
– custom webhook event name, can be any value, this name will be displayed in the Actions list, see below for more information.
You can also set the running conditions for each step. In the running conditions, github.event.action
is equal to the trigger keyword. By judging whether the given value is the same as github.event.action
, it is judged whether the step needs to be executed. For example, in the following example, this step will only be executed when the trigger keyword is helloworld
.
1 |
steps : |
6. Manual trigger
Github Actions also supports manual triggering, which can manually trigger the execution of Workflow on Github. We can enable manual triggering by specifying on.workflow_dispatch
in the Workflow file, for example:
1 |
name: CI |
In the above example, the execution of Workflow can be manually triggered on Github. It should be noted that the manual trigger method needs to be triggered manually on Github, and cannot be triggered by code push or other automated methods.
To manually trigger the execution of Workflow on Github, you can follow the steps below:
- Open the Github project page and click the Actions tab at the top.
- In the Workflows list on the left, select the Workflow that needs to be manually triggered.
- Click the Run workflow button on the right side of the page, enter the required parameters, and then click the Run workflow button to manually trigger the execution of Workflow.
The above are all the trigger methods supported by Github Actions. According to the needs of the project, you can choose the appropriate trigger method to automate the process.
This article is transferred from: https://qzkyl.ml/posts/15016.html
This site is only for collection, and the copyright belongs to the original author.