You can configure workflows to run when an event occurs on GitHub, according to a built-in schedule, or it can be an event that happens outside of GitHub.
Configure for a workflow events
You can configure a workflow to run one or one of the events to be performed via the
on syntax. See also the syntax at “Workflow syntax for GitHub Actions.” .
# Triggered một workflow khi có push code lên một branch bất kì
# của responsotiry
# Triggers một workflow có push code hoặc pull request
on: [push, pull_request]
Or you can also use multiple events with different configurations.
# Trigger một workflow khi push or pull request,
# nhưng chỉ trên main branch
# Cũng trigger khi page_build, cũng như release created events
types: # Cấu hình này không ảnh hưởng đến events page_build ở trên
Steps to take for an event to trigger a workflow run:
- An event occurred on your reponsotory and the result returned with an SHA commit link and Git ref.
- The .github / workflows directory stores yml files for defining workflows. Github will read those files to refer to the SHA commits and Git ref. The yml files contain new events to be considered for execution.
- Workflow files with SHA and Git ref commits are deployed, and a new workflow will run with the triggers when the triggers in the yml file coincide with the event that is being triggered.
To create a schedule we use legal Cup
schedule . A
Scheduled event allows a workflow to be triggered according to a predefined schedule. A
Scheduled may be delayed because the system is loading.
You can create a scheduled trigger running on UTC time using the POSIX cron syntax . A scheduled workkflow executes on the source of the latest commit on the default or base branch. The shortest time to create a scheduled workflows is a minimum of 5 minutes.
A simple trigger schedule example, running run workflows every 15 minutes:
- cron: '*/15 * * * *' // thực hiện trigger mỗi 15 phút
The Cron syntax has 5 fields separated by a space, each representing a unit of time.
┌───────────── phút (0 - 59)
│ ┌───────────── giờ (0 - 23)
│ │ ┌───────────── ngày trong tháng (1 - 31)
│ │ │ ┌───────────── tháng (1 - 12 or JAN-DEC)
│ │ │ │ ┌───────────── ngày trong tuần (0 - 6 or SUN-SAT)
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
* * * * *
You can also use operators in each field:
|*||All values||* * * * * Runs every minute of all days.|
|,||Value in list||2.10 4,5 * * * run 2, 10, 4, 5 minutes in every hour.|
|–||Value range||0 4-6 * * * every 0 minutes at 4 to 6 hours of the day.|
|/||The value leap||20/15 * * * * runs every 15 starting at 20 minutes (20, 35 and 50 minutes) every hour.|
There are also a few other ways to trigger a workflow but I have not used it so I am not monitoring it, you can refer to here.