Learning syntax of GitHub Workflow: Name, On, Jobs, Runs-on, Steps, Uses, Run
Here’s a detailed breakdown of the standard workflow syntax elements in GitHub Actions.
1. name
Specifies the name of the workflow. This name appears in the GitHub Actions interface under the repository's "Actions" tab.
Optional:
If omitted, GitHub will assign a default name based on the filename.
Example:
xxxxxxxxxx11nameBuild and Test Workflow2. on
Defines the events that trigger the workflow. These can be repository events like push, pull_request, scheduled intervals, or manual triggers.
Examples:
Trigger on a
pushevent to themainbranch:xxxxxxxxxx41on2push3branches4mainTrigger on a pull request:
xxxxxxxxxx41on2pull_request3branches4mainTrigger on a schedule (uses cron syntax):
xxxxxxxxxx31on2schedule3cron"0 0 " # Runs daily at midnightManual trigger:
xxxxxxxxxx21on2workflow_dispatch
3. jobs
Specifies the individual jobs to run in the workflow. Each job is a collection of steps that execute in a specified environment.
Example:
xxxxxxxxxx61jobs2 build3 runs-onubuntu-latest4 steps5nameCheckout code6 usesactions/checkout@v34. runs-on
Specifies the virtual environment (runner) where the job will execute.
Options:
ubuntu-latest: Ubuntu Linuxwindows-latest: Windowsmacos-latest: macOSSelf-hosted runners for custom environments.
Example:
xxxxxxxxxx31jobs2 build3 runs-onubuntu-latest5. steps
Defines the sequence of tasks (steps) within a job. Steps can run actions or custom shell commands.
Example:
xxxxxxxxxx71steps2nameCheckout code3 usesactions/checkout@v34nameInstall dependencies5 runnpm install6nameRun tests7 runnpm test6. uses
Specifies a reusable action to execute within a step. Actions are prebuilt tasks defined by the GitHub community or your repository.
Structure:
owner/repository@version
Example:
xxxxxxxxxx21nameCheckout code2 usesactions/checkout@v37. run
Specifies a shell command or script to execute within a step.
Example:
xxxxxxxxxx61namePrint a message2 runecho "Hello, World!"3nameRun a script4 run5 npm install6 npm testFull Example Combining All Elements
xxxxxxxxxx221nameCI Workflow2on3 push4 branches5main6 pull_request7 branches8main9jobs10 build11 runs-onubuntu-latest12 steps13nameCheckout code14 usesactions/checkout@v315nameSet up Node.js16 usesactions/setup-node@v317 with18 node-version'16'19nameInstall dependencies20 runnpm install21nameRun tests22 runnpm testSummary
This workflow is triggered on pushes or pull requests to the main branch. It runs on an Ubuntu environment, checks out the code, sets up Node.js, installs dependencies, and runs tests.






















Leave a Reply