Building a CI/CD System with GitHub Actions
Dr. Svetlin Nakov
September 2022
Intro to Continuous Integration (CI), Continuous Delivery (CD), Continuous Deployment (CD), and CI/CD Pipelines
Intro to GitHub Actions
Building CI workflow
Building CD workflow
Live Demo: Build CI System for JS and .NET Apps
1. Continuous Integration (CI), Continuous Delivery (CD),
Continuous Deployment, CI/CD Pipelines, GitHub Actions
Building a CI/CD System with GitHub Actions
1
Software University
https://softuni.bg
Svetlin Nakov, PhD
Co-Founder and Innovations
Manager @ SoftUni
https://nakov.com
2. 2
Software engineer, tech trainer, entrepreneur
author of 16 books
nakov.com
4 successful tech education initiatives
National Academy for Software
Development (NASD)
Telerik Software Academy
SoftUni (Software University)
Private IT High School "SoftUni Svetlina"
About Svetlin Nakov
3. 3
Intro to Continuous Integration (CI),
Continuous Delivery (CD),
Continuous Deployment (CD),
and CI/CD Pipelines
Intro to GitHub Actions
Building CI workflow
Building CD workflow
Live Demo: Build CI System for JS and .NET Apps
Contents
5. CI/CD pipeline
Continuously integrate
and release new features
Continuous integration (CI)
Write code, test and integrate it in the product
Continuous delivery (CD)
Continuously release new features
QAs maintain and monitor the CI/CD pipeline
CI/CD Pipeline
5
6. Continuous integration (CI)
Integrating the code from different developers frequently
(several times a day)
Automated building, and testing the software
Typically, after each Git push in the main branch
Allows finding integration problems and bugs early
Continuously maintain software quality
Continuous Integration (CI)
7. Continuous delivery (CD)
Keeping your codebase deployable at any point
CD continuously verifies that
Software builds correctly
Passes automated tests
Has all the necessary configuration and assets for
deployment in production
Continuous Delivery (CD)
8. Continuous deployment (CD)
Continuous automated deployment of the software
E.g. after each git push
Deployment is typically done to a testing environment
Example: https://dev.myproduct.com
Sometimes directly to the production servers
Continuous Deployment (CD)
9. CI/CD pipeline == CI + CD
Continuously integrate, test
and release new features
On git push, the CI/CD pipeline does automatically:
Build the software (compile, package, sign, etc.)
Run the automated tests (unit, integration)
Deploy on the testing environment + run E2E tests
Or only prepare for deployment
Or deploy directly on production
CI/CD Pipeline
11. GitHub Actions
Cloud-based software workflow automation
environment (CI/CD on the GitHub cloud)
Allows creating CI/CD pipelines to build, test and
deploy software projects, directly from a GitHub repo
https://github.com/features/actions
Free for public repos + 2000 mins per month
for private repos with the free plan
GitHub Actions
11
12. Events execute workflows
(one or several jobs, running in parallel)
Workflows hold jobs
(e. g. build, check security, deploy)
Jobs hold steps (e. g. "checkout the
code", "install .NET", "run tests", …)
Steps hold actions
(commands like `dotnet test`)
GitHub Actions: Concepts
event
workflow
job
job
step 1
action 1
action 2
step 2
action
12
13. CI Workflow in GitHub Actions
Building a CI System for Existing JS App
13
14. We have a JS App (with integration tests):
Code: https://github.com/nakov/MVC-app-integration-tests-example-mocha
Live: https://nakov-mvc-node-app.herokuapp.com
Sample JS App: Students Registry
14
15. Clone the app repo
Restore the Node packages:
Run the Mocha integration tests
Build and Run Locally (by Hand)
git clone https://github.com/nakov/MVC-app-integration-
tests-example-mocha
npm install
npm test
15
16. Let's implement a CI/CD
pipeline in GitHub Actions
Build & test workflow
Runs on push
Deploy workflow
Runs manually
CI/CD Pipeline in GitHub Actions
16
17. name: Build and Test
on: [push]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: npm ci
- run: npm test
GitHub Actions: Build & Test Workflow
mocha-tests.yml
Auto run on each "push"
Install Node.js
Install dependencies and build the app
Run the automated tests
Clone the repo
17
18. name: Deploy to Heroku
on: [workflow_dispatch]
jobs:
deploy-to-heroku:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: akhileshns/heroku-deploy@v3.6.8
with:
heroku_app_name: "some-app-name"
heroku_email: ${{secrets.HEROKU_EMAIL}}
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
GitHub Actions: Manual Deploy Workflow
deploy.yml
Run the workflow
manually
Clone the repo
Deploy in
Heroku
18
20. Live Demo
CI Workflow for JS App
in GitHub Actions
https://github.com/nakov/MVC-app-
integration-tests-example-mocha/actions
20
21. .NET MVC App + REST API + Desktop App + Android App
CI System for More Complex System
21
22. We have a .NET Web app (with tests):
Continuous Integration for .NET Apps
Code: https://github.com/nakov/Eventures
22
23. GitHub Actions: Build & Test Workflow
name: Build and Test
on: [push]
jobs:
WebApp-tests:
# Buld and run tests for the Eventures Web App …
WebApi-tests:
# Buld and run tests for the Eventures Web API …
DesktopApp-tests:
# Buld and run tests for the Eventures Desktop App …
AndroidApp-tests:
# Buld and run tests for the Eventures Android App …
dotnet-build.yml
23
Continuous integration (CI) is the practice of frequent integration,
together with automated building and automated testing of the software
after each push in the master branch.
This ensures that the new code integrates correctly with the existing code:
compiles without errors and passes all existing automated tests.
Continuous integration (CI), together with automated testing
allows developers to find the bugs early
and to continuously maintain the quality of the software.
Continuous Delivery (CD) is the practice of keeping your codebase deployable at any point.
This means to continuously verify that the software builds correctly,
passes the automated tests
and have all the configuration necessary to push it into production.
Continuous delivery (CD)
allows to integrate, deploy and release new features continuously
in short release cycles with a lot of automation.
Continuous Deployment (CD) is the practice of automatically deploy the software to a testing or production environment after each significant change (e.g. after "git push" in the master branch).
Continuous integration and continuous delivery (the so-called CI/CD pipeline)
is a practice in modern software development,
where the code is integrated, tested and deployed continuously
and automatically after each significant change in the code.