From 46a3b3b3bfd1fbd602e95ed699eed4c5835b3a28 Mon Sep 17 00:00:00 2001 From: gikuser Date: Thu, 25 Dec 2025 10:37:01 +0500 Subject: [PATCH 01/10] Test push --- testfile.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 testfile.txt diff --git a/testfile.txt b/testfile.txt new file mode 100644 index 00000000..91a377d8 --- /dev/null +++ b/testfile.txt @@ -0,0 +1 @@ +this is a new file, made for testing my auth. \ No newline at end of file From 795f5ae558e9df44e1b75f994844ac9e26b80143 Mon Sep 17 00:00:00 2001 From: gikuser Date: Thu, 25 Dec 2025 10:53:14 +0500 Subject: [PATCH 02/10] Fix README.md --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 722f18b8..ff2297f3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ # ReactNodeTesting Sample React and Node/Express project to demonstrate usage of React Test Library and Jest test frameworks. -Article for this can be found here - https://medium.com/@eljamaki01/testing-a-react-node-express-app-with-react-test-library-and-jest-2ac910812c41 \ No newline at end of file +Article for this can be found here - https://medium.com/@eljamaki01/testing-a-react-node-express-app-with-react-test-library-and-jest-2ac910812c41 + + +### To run this thing, you need to first verify that the system has node and npm installed: + +node -v +npm -v + +### After verifying that, run: + +npm install + +### Then run the following to build and serve the application: + +npm run build-react +npm start \ No newline at end of file From b7f2cc2da0b83f721fa2ab3c4cd4d0699d8f2721 Mon Sep 17 00:00:00 2001 From: gikuser Date: Thu, 25 Dec 2025 11:11:09 +0500 Subject: [PATCH 03/10] trying to add a commit to main branch --- del.me | 1 + 1 file changed, 1 insertion(+) create mode 100644 del.me diff --git a/del.me b/del.me new file mode 100644 index 00000000..c9b02efc --- /dev/null +++ b/del.me @@ -0,0 +1 @@ +this wont be pushed \ No newline at end of file From e399f402fbbbe41cf8a011871c27b04e7f9c75ce Mon Sep 17 00:00:00 2001 From: gikuser Date: Thu, 25 Dec 2025 11:18:09 +0500 Subject: [PATCH 04/10] This commit will be blocked --- del.me | 1 - 1 file changed, 1 deletion(-) delete mode 100644 del.me diff --git a/del.me b/del.me deleted file mode 100644 index c9b02efc..00000000 --- a/del.me +++ /dev/null @@ -1 +0,0 @@ -this wont be pushed \ No newline at end of file From 5afe131a7d4e1763fefddc819369087939126ea1 Mon Sep 17 00:00:00 2001 From: gikuser Date: Thu, 25 Dec 2025 14:17:33 +0500 Subject: [PATCH 05/10] Add deploy workflow --- .github/workflows/deploy-testing.yml | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/deploy-testing.yml diff --git a/.github/workflows/deploy-testing.yml b/.github/workflows/deploy-testing.yml new file mode 100644 index 00000000..a77d1608 --- /dev/null +++ b/.github/workflows/deploy-testing.yml @@ -0,0 +1,47 @@ +name: Deploy to Testing + +on: + pull_request: + branches: + - main + workflow_dispatch: # Manual trigger button + +jobs: + build-test-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install dependencies + run: npm install + + - name: Build React app + run: npm run build-react + + - name: Run Unit Tests + run: npm test || true # Continue even if no tests + + - name: Lint code + run: npm run lint || echo "No lint configured" + + - name: Deploy to Testing EC2 + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{ secrets.TESTING_EC2_IP }} + username: ubuntu + key: ${{ secrets.EC2_SSH_KEY }} + port: 22 + script: | + cd ~/react-node-testing || git clone https://github.com/${{ github.repository }} ~/react-node-testing + cd ~/react-node-testing + git pull + npm install + npm run build-react + pm2 restart react-node-app || pm2 start npm --name "react-node-app" -- start From 7987f4b78bc524f155105d5d0aa5fb3cb2370486 Mon Sep 17 00:00:00 2001 From: Abdullah-Noor557 Date: Thu, 25 Dec 2025 14:31:34 +0500 Subject: [PATCH 06/10] Updated Workflows --- .github/workflows/deploy-staging.yml | 64 +++++++++++++ .github/workflows/deploy-testing.yml | 130 ++++++++++++++++++--------- 2 files changed, 154 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 00000000..9b8ac7d9 --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,64 @@ +name: Deploy to Staging Environment + +on: + push: + branches: [ main ] + workflow_dispatch: + +jobs: + deploy-staging: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install Dependencies + run: npm install + + - name: Run Tests + run: npm test + + - name: Build React App + run: npm run build-react + + - name: Copy Files to Staging Server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.HOST_STAGING }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.EC2_SSH_KEY }} + source: "./*" + target: "/home/ubuntu/app" + + - name: Start Application on Staging + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST_STAGING }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + cd /home/ubuntu/app + npm install --production + pm2 restart all || pm2 start index.js --name "react-node-app" + pm2 save + + - name: Send Success Email + if: success() + uses: dawidd6/action-send-mail@v3 + with: + server_address: smtp.gmail.com + server_port: 465 + username: ${{ secrets.MAIL_USERNAME }} + password: ${{ secrets.MAIL_PASSWORD }} + subject: Deployment to STAGING Successful + body: | + Changes have been merged to main and deployed to Staging. + Access it here: http://${{ secrets.HOST_STAGING }}:3000 + to: ${{ secrets.QA_EMAIL }} + from: DevOps Automation \ No newline at end of file diff --git a/.github/workflows/deploy-testing.yml b/.github/workflows/deploy-testing.yml index a77d1608..5f798936 100644 --- a/.github/workflows/deploy-testing.yml +++ b/.github/workflows/deploy-testing.yml @@ -1,47 +1,97 @@ -name: Deploy to Testing +name: Deploy to Testing Environment on: pull_request: - branches: - - main - workflow_dispatch: # Manual trigger button + branches: [ main ] + workflow_dispatch: # Allows manual button trigger jobs: - build-test-deploy: + build-and-test: runs-on: ubuntu-latest - + steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: 20 - - - name: Install dependencies - run: npm install - - - name: Build React app - run: npm run build-react - - - name: Run Unit Tests - run: npm test || true # Continue even if no tests - - - name: Lint code - run: npm run lint || echo "No lint configured" - - - name: Deploy to Testing EC2 - uses: appleboy/ssh-action@v0.1.8 - with: - host: ${{ secrets.TESTING_EC2_IP }} - username: ubuntu - key: ${{ secrets.EC2_SSH_KEY }} - port: 22 - script: | - cd ~/react-node-testing || git clone https://github.com/${{ github.repository }} ~/react-node-testing - cd ~/react-node-testing - git pull - npm install - npm run build-react - pm2 restart react-node-app || pm2 start npm --name "react-node-app" -- start + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install Dependencies + run: npm install + + - name: Run Linting (Check Code Quality) + # Assuming you don't have a specific lint script setup yet, we echo. + # Ideally: run: npm run lint + run: echo "Linting code..." + + - name: Run Unit Tests + # Ensure you have a test script in package.json + run: npm test + + - name: Build React App + run: npm run build-react + + - name: Deploy to AWS Testing Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST_TESTING }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + # Pull latest code or copy files. Here we clone/pull strategy + # Note: Since this is a PR, we might be deploying a specific branch. + # For simplicity in this assignment, we will rsync the artifacts built above. + rm -rf ~/app/* + mkdir -p ~/app + + - name: Copy Files to Server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.HOST_TESTING }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.EC2_SSH_KEY }} + source: "./*" + target: "/home/ubuntu/app" + + - name: Start Application on Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST_TESTING }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + cd /home/ubuntu/app + npm install --production + # Restart app using PM2 + pm2 restart all || pm2 start index.js --name "react-node-app" + pm2 save + + - name: Send Success Email + if: success() + uses: dawidd6/action-send-mail@v3 + with: + server_address: smtp.gmail.com + server_port: 465 + username: ${{ secrets.MAIL_USERNAME }} + password: ${{ secrets.MAIL_PASSWORD }} + subject: Deployment to Testing Successful + body: | + The Pull Request has been deployed to the Testing Environment. + Access it here: http://${{ secrets.HOST_TESTING }}:3000 + to: ${{ secrets.QA_EMAIL }} + from: DevOps Automation + + - name: Send Failure Email + if: failure() + uses: dawidd6/action-send-mail@v3 + with: + server_address: smtp.gmail.com + server_port: 465 + username: ${{ secrets.MAIL_USERNAME }} + password: ${{ secrets.MAIL_PASSWORD }} + subject: Deployment Failed + body: The workflow failed during the Pull Request check. Please check GitHub Actions logs. + to: ${{ secrets.QA_EMAIL }} + from: DevOps Automation \ No newline at end of file From 54223a37763c199bae85d1f8a8e58f4c1bdc9e96 Mon Sep 17 00:00:00 2001 From: gikuser Date: Thu, 25 Dec 2025 14:34:07 +0500 Subject: [PATCH 07/10] Adjust workflow --- .github/workflows/deploy-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-testing.yml b/.github/workflows/deploy-testing.yml index a77d1608..143821f9 100644 --- a/.github/workflows/deploy-testing.yml +++ b/.github/workflows/deploy-testing.yml @@ -44,4 +44,4 @@ jobs: git pull npm install npm run build-react - pm2 restart react-node-app || pm2 start npm --name "react-node-app" -- start + From d4c52dada532d80371f943cb55f1aa83560bb146 Mon Sep 17 00:00:00 2001 From: Abdullah-Noor557 Date: Thu, 25 Dec 2025 14:53:16 +0500 Subject: [PATCH 08/10] Update deploy-testing.yml --- .github/workflows/deploy-testing.yml | 69 ++++++---------------------- 1 file changed, 14 insertions(+), 55 deletions(-) diff --git a/.github/workflows/deploy-testing.yml b/.github/workflows/deploy-testing.yml index 5f798936..56abfaf7 100644 --- a/.github/workflows/deploy-testing.yml +++ b/.github/workflows/deploy-testing.yml @@ -3,7 +3,7 @@ name: Deploy to Testing Environment on: pull_request: branches: [ main ] - workflow_dispatch: # Allows manual button trigger + workflow_dispatch: # Allows manual trigger button jobs: build-and-test: @@ -21,77 +21,36 @@ jobs: - name: Install Dependencies run: npm install - - name: Run Linting (Check Code Quality) - # Assuming you don't have a specific lint script setup yet, we echo. - # Ideally: run: npm run lint - run: echo "Linting code..." + - name: Run Linting (Code Analysis) + # If you don't have a specific lint command, this placeholder ensures the step exists + run: echo "Linting code analysis..." - name: Run Unit Tests - # Ensure you have a test script in package.json + # runs the test script defined in package.json run: npm test - name: Build React App run: npm run build-react - - name: Deploy to AWS Testing Server - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.HOST_TESTING }} - username: ${{ secrets.USERNAME }} - key: ${{ secrets.EC2_SSH_KEY }} - script: | - # Pull latest code or copy files. Here we clone/pull strategy - # Note: Since this is a PR, we might be deploying a specific branch. - # For simplicity in this assignment, we will rsync the artifacts built above. - rm -rf ~/app/* - mkdir -p ~/app - - - name: Copy Files to Server + - name: Deploy Files to Testing Server uses: appleboy/scp-action@master with: - host: ${{ secrets.HOST_TESTING }} - username: ${{ secrets.USERNAME }} + host: ${{ secrets.TESTING_EC2_IP }} + username: ubuntu key: ${{ secrets.EC2_SSH_KEY }} source: "./*" target: "/home/ubuntu/app" - - name: Start Application on Server + - name: Start Application on Testing Server uses: appleboy/ssh-action@master with: - host: ${{ secrets.HOST_TESTING }} - username: ${{ secrets.USERNAME }} + host: ${{ secrets.TESTING_EC2_IP }} + username: ubuntu key: ${{ secrets.EC2_SSH_KEY }} script: | cd /home/ubuntu/app + # Install production dependencies npm install --production - # Restart app using PM2 + # Restart the app using PM2 (or start if not running) pm2 restart all || pm2 start index.js --name "react-node-app" - pm2 save - - - name: Send Success Email - if: success() - uses: dawidd6/action-send-mail@v3 - with: - server_address: smtp.gmail.com - server_port: 465 - username: ${{ secrets.MAIL_USERNAME }} - password: ${{ secrets.MAIL_PASSWORD }} - subject: Deployment to Testing Successful - body: | - The Pull Request has been deployed to the Testing Environment. - Access it here: http://${{ secrets.HOST_TESTING }}:3000 - to: ${{ secrets.QA_EMAIL }} - from: DevOps Automation - - - name: Send Failure Email - if: failure() - uses: dawidd6/action-send-mail@v3 - with: - server_address: smtp.gmail.com - server_port: 465 - username: ${{ secrets.MAIL_USERNAME }} - password: ${{ secrets.MAIL_PASSWORD }} - subject: Deployment Failed - body: The workflow failed during the Pull Request check. Please check GitHub Actions logs. - to: ${{ secrets.QA_EMAIL }} - from: DevOps Automation \ No newline at end of file + pm2 save \ No newline at end of file From d5b104d9966aaef177e606896c094dbfb9b00346 Mon Sep 17 00:00:00 2001 From: Abdullah-Noor557 Date: Thu, 25 Dec 2025 14:53:34 +0500 Subject: [PATCH 09/10] Delete deploy-staging.yml --- .github/workflows/deploy-staging.yml | 64 ---------------------------- 1 file changed, 64 deletions(-) delete mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml deleted file mode 100644 index 9b8ac7d9..00000000 --- a/.github/workflows/deploy-staging.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: Deploy to Staging Environment - -on: - push: - branches: [ main ] - workflow_dispatch: - -jobs: - deploy-staging: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '18' - - - name: Install Dependencies - run: npm install - - - name: Run Tests - run: npm test - - - name: Build React App - run: npm run build-react - - - name: Copy Files to Staging Server - uses: appleboy/scp-action@master - with: - host: ${{ secrets.HOST_STAGING }} - username: ${{ secrets.USERNAME }} - key: ${{ secrets.EC2_SSH_KEY }} - source: "./*" - target: "/home/ubuntu/app" - - - name: Start Application on Staging - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.HOST_STAGING }} - username: ${{ secrets.USERNAME }} - key: ${{ secrets.EC2_SSH_KEY }} - script: | - cd /home/ubuntu/app - npm install --production - pm2 restart all || pm2 start index.js --name "react-node-app" - pm2 save - - - name: Send Success Email - if: success() - uses: dawidd6/action-send-mail@v3 - with: - server_address: smtp.gmail.com - server_port: 465 - username: ${{ secrets.MAIL_USERNAME }} - password: ${{ secrets.MAIL_PASSWORD }} - subject: Deployment to STAGING Successful - body: | - Changes have been merged to main and deployed to Staging. - Access it here: http://${{ secrets.HOST_STAGING }}:3000 - to: ${{ secrets.QA_EMAIL }} - from: DevOps Automation \ No newline at end of file From 4a22d5d961eb674f810d76a55bb463d0b7793ccc Mon Sep 17 00:00:00 2001 From: Abdullah-Noor557 Date: Thu, 25 Dec 2025 15:01:49 +0500 Subject: [PATCH 10/10] Create deploy-staging.yml --- .github/workflows/deploy-staging.yml | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 00000000..13ddc759 --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,56 @@ +name: Deploy to Staging Environment + +on: + push: + branches: [ main ] + workflow_dispatch: # Allows manual trigger button + +jobs: + deploy-staging: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install Dependencies + run: npm install + + - name: Run Linting (Code Analysis) + # Placeholder for linting logic + run: echo "Linting code analysis..." + + - name: Run Unit Tests + # Ensures code is verified before deploying to Staging + run: npm test + + - name: Build React App + run: npm run build-react + + - name: Deploy Files to Staging Server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.STAGING_EC2_IP }} + username: ubuntu + key: ${{ secrets.EC2_SSH_KEY }} + source: "./*" + target: "/home/ubuntu/app" + + - name: Start Application on Staging Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.STAGING_EC2_IP }} + username: ubuntu + key: ${{ secrets.EC2_SSH_KEY }} + script: | + cd /home/ubuntu/app + # Install production dependencies + npm install --production + # Restart the app using PM2 (or start if not running) + pm2 restart all || pm2 start index.js --name "react-node-app" + pm2 save \ No newline at end of file