Getting started with CI/CD using GitHub Actions
What is CI/CD?
Continuous integration (CI) is a development practice that requires frequently committing code to a shared repository. Each commit is then automatically verified and tested to detect integration errors and failed tests as quickly as possible.
Continuous Delivery (CD) is an extension of continuous integration. It allows developers to safely experiment, fix bugs or include new features in production.
The goal is to ensure code is always in a deployable state, ready to go live.
What is GitHub Actions?
GitHub Actions is a CI/CD platform that allows you to automate your test, build, and deployment pipeline. It allows the creation of workflows based on a vast range of events, such as pull requests, commits, issues, and more.
Workflows
A workflow is an orchestrated and automated process that will run one or more jobs based on a defined event.
Workflows are defined by a YAML file and should be placed in the .github/workflows
folder in your repository.
Multiple workflows can be configured in a repository each with a designed set of tasks to carry out based on what event.
Events, Jobs & Runners
An event is a specific activity in a repository that triggers a workflow. Events can be commits, pull requests, and issues among others.
Jobs are a series of steps in a workflow that will be executed sequentially by the same runner.
A runner is a server that executes your workflows. Each workflow is executed in a newly provided virtual machine and can be configured with the desired operating system, such as Linux, Windows, and macOS.
Workflow demo project
You can set up actions on a new or existing Github project.
To create a Workflow, go to the Actions tabs.
Select the simple workflow and click Configure
Click Commit changes and Congratulations for successfully configured actions in your repository.
Breaking down the workflow file
name
- The name of the workflow.
on
- Events and Event rules that will trigger the workflows.
push
- action should be triggered on any push action in the repository.
branches: ['main']
- push and pull requests only on the main branch.
jobs
- Jobs that will be executed in the workflow.
hello
- the name of a job to be executed.
runs-on: ubuntu-latest
- the name of the operating system to carry out the job
steps
- sequence of tasks to be executed.
uses
- important for every action, if fetches your latest commit or the specific branch, tag, or pull request code for use within the workflow.
name
- the name of the task.
run
- This can be a single or series of commands to execute.
You can inspect your workflow, in the Action tab.
Click on the job you've created to further inspect.