CI/CD pipeline with GitHub Actions
Every push runs tests and linting; every merge to main builds an image and deploys automatically.
Intermediateâą 6â10 hoursđĒ 7 stepsGitHub ActionsDockerTests
What you'll learn
- âWorkflows, jobs and steps
- âSecrets and environments
- âBuild caching and deployment strategies
What you'll build
- âLint and test on every pull request
- âStatus badge in README
- âBuild and push a Docker image on main
- âAutomatic deploy with a manual approval option
Step-by-step guide
- 1
First workflow
.github/workflows/ci.yml triggered on push and pull_request; checkout, set up the language, install, test.
- 2
Matrix
Test on two versions (for example Node 20 and 22) with strategy.matrix.
- 3
Cache
Use the setup action's cache option or actions/cache to speed up installs.
- 4
Build image
On main, log in to a registry (GitHub Container Registry) with secrets and build/push with docker/build-push-action.
- 5
Deploy
SSH to a server (key stored in GitHub secrets) and pull + restart, or deploy to a cloud service.
- 6
Protect main
Branch protection: require CI to pass before merging.
- 7
Document
Diagram of the pipeline and a badge in the README.
đ Make it stand out
- +Preview deployments for pull requests
- +Security scanning (dependency audit, CodeQL)
- +Rollback job