Adding CI/CD to Your Project#
Note
There are many tools available to create a CI/CD pipeline. This guide will demonstrate the use of GitHub Actions.
GitHub Actions#
Key Terms |
Meaning |
---|---|
Workflows |
Automated procedure that can be triggered by some event. Written in YAML. |
Events |
An activity that triggers a workflow to be executed. For example, pushes to main branch. |
Jobs |
Set of steps that execute on the same runner. Multiple jobs run in parallel. |
Steps |
Individual task that runs command within a job. Executes shell commands or actions. Multiple steps run sequentially. |
Actions |
Standalone commands that are combined into steps. There are actions published by the Github community which you can use as well. |
Runner |
The server that the workflows run within. |
Create Your First Workflow#
Create a directory from the root of your repository called .github/workflows.
Create a new file for your workflow. You can name this anything, but it must be a YAML file. For example, ci-cd.yaml.
Add the following example workflow and modify/add steps as required.
name**:** learn-github-actions\
on**:** **\[**push**\]**\
jobs**:**\
check-bats-version**:**\
runs-on**:** ubuntu-latest\
steps**:**\
**-** uses**:** actions/checkout@v2\
**-** uses**:** actions/setup-node@v2\
with**:**\
node-version**:** \'14\'\
**-** run**:** npm install -g bats\
**-** run**:** bats -v
The steps above were obtained from the GitHub Actions documentation.
Understanding the Workflow Syntax#
Viewing Your Workflow Execution#
Once your workflow is triggered, you should be able to see its execution under the Actions tab in your GitHub repository. If any step fails, GitHub will clearly indicate the step that failed and show any logs that can be useful to understand why it has failed.
Steps to Include in Your Pipeline#
Build your application
Install necessary dependencies
Perform any formatting/linting checks
Test your application
Unit testing
Integration testing
Extra Resources
To build your first project using GitHub Actions, you can take GitHub’s free course.