Configure CI / CD with Github (part 2): Trigger a work flow

Tram Ho

Events trigger

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.” .

Or you can also use multiple events with different configurations.

Steps to take for an event to trigger a workflow run:

  1. An event occurred on your reponsotory and the result returned with an SHA commit link and Git ref.
  2. 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.
  3. 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.

Scheduled trigger

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:

The Cron syntax has 5 fields separated by a space, each representing a unit of time.

You can also use operators in each field:

OperatordescriptionFor example
*All values* * * * * Runs every minute of all days.
,Value in list2.10 4,5 * * * run 2, 10, 4, 5 minutes in every hour.
Value range0 4-6 * * * every 0 minutes at 4 to 6 hours of the day.
/The value leap20/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.

Reference source:

Share the news now

Source : Viblo