0% found this document useful (0 votes)
4 views3 pages

CI/CD with GitHub Actions for Node.js

This document outlines the creation of a CI/CD pipeline using GitHub Actions for a basic Node.js project. It details the steps to set up the project, implement testing with Jest, and configure the GitHub Actions workflow to automate testing on code changes. The experiment demonstrates the importance of continuous integration and automated testing in maintaining code quality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

CI/CD with GitHub Actions for Node.js

This document outlines the creation of a CI/CD pipeline using GitHub Actions for a basic Node.js project. It details the steps to set up the project, implement testing with Jest, and configure the GitHub Actions workflow to automate testing on code changes. The experiment demonstrates the importance of continuous integration and automated testing in maintaining code quality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Roll No:160122733163 Week-6 Date:10/10/2025

Aim:
CI/CD pipeline using GitHub Actions with a Basic [Link] Project
Description:
Continuous Integration (CI) is a development practice where developers frequently merge
code changes into a central repository, and automated builds and tests are run. GitHub
Actions provides a platform to define CI/CD workflows directly in a GitHub repository.
In this experiment, we use a basic [Link] project with a simple function sayHello(name)
and a Jest test to verify its correctness. We create a workflow file (.github/workflows/[Link])
that defines the steps for the pipeline:
1. Trigger: The workflow runs automatically on every push or pull request to the main
branch.
2. Checkout code: The pipeline fetches the latest code from the repository.
3. Set up [Link]: The workflow installs [Link] in a virtual environment.
4. Install dependencies: The pipeline installs project dependencies using npm ci.
5. Run tests: Jest runs the test file to verify that the function works correctly. Console
output is displayed in the workflow logs.
6. Result: The workflow passes if tests succeed and fails if any test fails, providing
immediate feedback on code quality.
This experiment demonstrates the basics of CI/CD, shows how automated testing works, and
ensures code changes do not break existing functionality. GitHub Actions logs provide a clear
view of the pipeline execution and console outputs.
Steps for CI/CD using GitHub Actions ([Link] Project)
Step 1: Create a [Link] project
mkdir my_node_app
cd my_node_app
npm init -y
Explanation:
• mkdir creates a new project folder.
• npm init -y initializes [Link] project and creates [Link] (stores project info,
scripts, and dependencies).

Step 2: Add project files


• Create [Link]:
function sayHello(name) {
return `Hello, ${name}!`;
}
[Link] = sayHello;
• Create [Link]:
const sayHello = require('./index');
test('says hello to name', () => {
[Link](sayHello('Rasagna'));
expect(sayHello('Rasagna')).toBe('Hello, Rasagna!');
});
Explanation:
• [Link] contains the function we want to test.
• [Link] is a test file using Jest that checks if the function works and prints output.

Step 3: Install Jest


npm install --save-dev jest

Page No. Signature of the Faculty………………………...


Roll No:160122733163 Week-6 Date:10/10/2025

Explanation:
• Jest is a testing framework.
• --save-dev installs it as a development dependency.
Step 4: Update [Link] test script
"scripts": {
"test": "jest"
}
Explanation:This allows you to run npm test to execute Jest tests automatically.
Step 5: Add a .gitignore file
Create .gitignore and add:
node_modules/
.env
build/
Explanation:Prevents unnecessary files like node_modules or environment files from being
pushed to GitHub.
Step 6: Add GitHub Actions workflow
• Create folder .github/workflows/
• Inside it, create [Link]:
Code in [Link]:
name: [Link] CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up [Link]
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
Explanation:Workflow triggers on push or pull request to [Link]: checkout code, install
[Link], install dependencies, run tests.
Step 7: Commit and push to GitHub
git add .
git commit -m "Add project files and GitHub Actions workflow"
git push origin main
Explanation:Pushes your project along with workflow to [Link] runs
automatically after push.
Step 8: View GitHub Actions logs
• Go to GitHub → Actions tab → click latest workflow → click build job → expand
Run tests step.
• You will see:

Page No. Signature of the Faculty………………………...


Roll No:160122733163 Week-6 Date:10/10/2025

Hello, Rasagna!
PASS ./[Link]
Explanation:Console output from [Link]() is [Link] results show whether your
function works correctly.
Output:

Conclusion:
The CI/CD pipeline using GitHub Actions automatically runs tests on every push, ensuring
code [Link] workflow successfully executed the [Link] tests and displayed console
outputs in the [Link] experiment demonstrates the basics of automated testing and
continuous integration for software projects.

Page No. Signature of the Faculty………………………...

You might also like