GitHub Actions

Continuous Integration with GitHub Actions

Understanding DevOps Pipeline

In this guide, we’ll design a CI/CD pipeline for a Node.js application using GitHub Actions. Automating each stage ensures consistent builds, rapid feedback, and reliable deployments across development and production clusters.

Pipeline Overview

StageDescription
Source CheckoutPull code from GitHub repository
Unit TestingInstall dependencies, run tests, archive reports
Code CoverageGenerate coverage metrics (errors ignored)
ContainerizationBuild Docker image, smoke test, push to registry
Dev DeploymentApply Kubernetes manifests, expose via Ingress
Dev Integration TestingValidate live endpoint on development cluster
Manual ApprovalPause for reviewer sign-off
Prod DeploymentDeploy to production cluster
Prod Integration TestingVerify the production endpoint

1. Source Checkout

Begin by checking out your repository so that all subsequent jobs have access to your code.

- name: Checkout source code
  uses: actions/checkout@v3

2. Unit Testing

Install dependencies, execute your test suite, and archive the results. The pipeline will fail on any test errors.

npm ci
npm test
# Archive test reports for review

Note

Use npm ci in CI environments for a clean, deterministic install.


3. Code Coverage

Run coverage in parallel with unit tests. We ignore coverage thresholds to avoid pipeline failures but still collect the reports.

npm ci
npm run coverage || echo "Coverage errors ignored"
# Archive coverage reports for metrics

Note

Storing coverage artifacts helps you track trends over time, even if errors are ignored.


4. Containerization

Build your Docker image, perform a quick smoke test inside a container, and push it to your Docker registry.

docker build -t $REGISTRY/$REPO:$TAG .
docker run --rm $REGISTRY/$REPO:$TAG npm test
docker push $REGISTRY/$REPO:$TAG

5. Deploy to Development Cluster

Apply Kubernetes manifests to your development cluster and capture the Ingress hostname.

kubectl apply -f k8s/
DEV_HOST=$(kubectl get ingress app-ingress \
  -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
echo "Development URL: https://$DEV_HOST"

6. Integration Testing on Dev

Verify that the application is live on the development endpoint.

curl -f https://$DEV_HOST/live

7. Manual Approval

Pause the workflow until a reviewer manually approves the release. On rejection, the pipeline stops.

Warning

Ensure that the reviewer has access to both the GitHub repo and any relevant sprint boards before approving.


8. Deploy to Production Cluster

Once approved, deploy the same manifests to your production context.

kubectl apply -f k8s/ --context=prod
PROD_HOST=$(kubectl get ingress app-ingress \
  --context=prod \
  -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
echo "Production URL: https://$PROD_HOST"

9. Post-Deployment Integration Tests

Perform final checks against the production endpoint to validate a successful release.

curl -f https://$PROD_HOST/live

Watch Video

Watch video content

Previous
Run and Test NodeJS App on Local Machine