Master GitHub Actions with hands-on labs and exercises. Learn how to automate workflows, run tests, deploy applications, and more using GitHub's powerful automation platform. This repository has everything you need to get started with continuous integration and continuous deployment.
In this lab, you will create a scheduled workflow that runs at regular intervals using a cron expression. The workflow will also support manual triggering and will run when specific changes are pushed. This will help you understand how to configure workflows with schedules and additional triggers.
Estimated Duration: 20-30 minutes
Copy the content of the starter file:
name: Intro - Scheduled Workflow
.github/workflows
and name it intro-scheduled-workflow.yml
.main
branch.intro-scheduled-workflow.yml
file.Add the following on
section to define the workflow triggers:
on:
workflow_dispatch:
schedule:
- cron: '*/5 * * * *' # Every 5 minutes
push:
paths:
- '.github/workflows/intro-scheduled-workflow.yml'
main
branch.workflow_dispatch
trigger.intro-scheduled-workflow.yml
file again.Add the following jobs
section to define the tasks the workflow will perform:
jobs:
execute:
runs-on: ubuntu-latest
steps:
- name: Display current date and time
run: echo "The current date and time is $(date)"
main
branch.The intro-scheduled-workflow.yml
workflow includes the following sections:
The workflow is named Intro - Scheduled Workflow
.
on
)workflow_dispatch
:
schedule
:
*/5 * * * *
.push
:
.github/workflows/intro-scheduled-workflow.yml
.jobs.execute
)runs-on
:
ubuntu-latest
GitHub-hosted runner.Steps:
date
command.To test the workflow, you can:
.github/workflows/intro-scheduled-workflow.yml
and commit the changes to the main
branch.Monitor the workflow’s progress in the Actions tab.
date
command.To schedule the workflow at a different frequency, update the cron
value in the schedule
section. For example:
0 * * * *
0 0 * * *
0 9 * * 1
Commit the updated workflow to the main
branch.
Test the new schedule by observing the next run.
In this lab, you:
This lab demonstrated how to use scheduled workflows in GitHub Actions and customize triggers for automation.