This project is a Node.js application for parsing CSV files, complete with a CI/CD pipeline using GitHub Actions. CI/CD updates can be check on https://csv-parser.digitools.today
- About the Project
- Prerequisites
- Installation
- Usage
- Running the Application
- CI/CD Pipeline
- Deploying to Server
- Contributing
- License
Provide a brief description of the project, its purpose, and what it does. Mention key features and technologies used.
Before you begin, ensure you have met the following requirements:
- Node.js (version 20.x recommended)
- npm (Node Package Manager)
- PM2 (for process management)
- SSH access to the deployment server
- Git
To install this project, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/yourrepository.git cd yourrepository
-
Install dependencies:
npm install
Describe how to use the project, including examples of common use cases.
To run the application, follow these steps:
-
Build the project:
npm run build
-
Create the
uploads
directory:mkdir -p dist/uploads
-
Start the application using PM2:
pm2 start npm --name "csv-parser" -- start
The project includes a GitHub Actions workflow for continuous integration and deployment. The workflow:
- Runs tests on every push and pull request to the
master
branch. - Deploys the application to a remote server after passing tests.
The workflow is defined in .github/workflows/ci-cd.yml
:
name: Node.js CSV Parser CI/CD
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci --force
- run: npm run build --if-present
- name: Create uploads folder
run: mkdir -p dist/uploads
- run: npm test
- name: Add remote host to known_hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -p ${{ secrets.SiGiRi_SSH_PORT }} ${{ secrets.SiGiRi_SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to Server
env:
SSH_PRIVATE_KEY: ${{ secrets.SiGiRi_SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SiGiRi_SSH_HOST }}
SSH_USER: ${{ secrets.SiGiRi_SSH_USER }}
SSH_PORT: ${{ secrets.SiGiRi_SSH_PORT }}
run: |
echo "$SSH_PRIVATE_KEY" > private_key
chmod 600 private_key
rsync -avz -e "ssh -i private_key -p $SSH_PORT" --exclude node_modules ./ $SSH_USER@$SSH_HOST:/home/ubuntu/csv-parser
ssh -i private_key -p $SSH_PORT $SSH_USER@$SSH_HOST << 'EOF'
cd /home/ubuntu/csv-parser
npm install --production
mkdir -p uploads
pm2 restart csv-parser || pm2 start npm --name "csv-parser" -- start
exit
EOF
shell: bash
To deploy the application manually, follow these steps:
-
Ensure SSH access to the server.
-
Run the build process and create the
uploads
folder:npm run build mkdir -p dist/uploads
-
Deploy the code to the server:
rsync -avz -e "ssh -p [SSH_PORT]" --exclude node_modules ./ [SSH_USER]@[SSH_HOST]:/home/ubuntu/csv-parser
-
SSH into the server and start the application using PM2:
ssh -p [SSH_PORT] [SSH_USER]@[SSH_HOST] cd /home/ubuntu/csv-parser npm install --production pm2 restart csv-parser || pm2 start npm --name "csv-parser" -- start exit
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
This project is licensed under the MIT License.