CI Pipeline with GitHub Actions
What is GitHub Actions?
GitHub Actions is a CI/CD (Continuous Integration / Continuous Deployment) tool built into GitHub. It uses workflows which are specified in .yml files in .github/workflows/ directory of a repository. It lets you automate tasks such as building, testing, and deploying your code for example when pushing code to specified branch, creating a pull request or manually triggering a workflow.
There is a few key elements to workflow. It has to have a name, triggers have to be specified and it must conatin at least one job which includes steps that do certain things e.g. run unit tests.
My implementation of CI workflow
I setup my CI workflow, so it runs whenever I make a push or pull request to the 'main' branch. I can also run it on demand by added 'workflow_dispatch' statement. I added a path to make sure my workflow runs only when there was a code change in specified directory and it doesn't for example when I modify readme file in my repo.
name: Build Portfolio
on:
workflow_dispatch:
push:
branches: [ "main" ]
paths:
- 'Portfolio/**'
pull_request:
branches: [ "main" ]
paths:
- 'Portfolio/**'
There is only one job called 'build' with a few steps in my implementation and I specified Ubuntu to be environment it runs on. The rest of the steps:
- Check out the code from the repository so it can be used in the next steps.
- Install .NET SDK 8.0.x so my project can be built using that version.
- Restore all NuGet packages for my project.
- Build my project.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore