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 diff --git a/.github/workflows/deploy-testing.yml b/.github/workflows/deploy-testing.yml new file mode 100644 index 00000000..3e4b2b2e --- /dev/null +++ b/.github/workflows/deploy-testing.yml @@ -0,0 +1,56 @@ +name: Deploy to Testing Environment + +on: + pull_request: + branches: [ main ] + workflow_dispatch: # Allows manual trigger button + +jobs: + 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: '18' + + - name: Install Dependencies + run: npm install + + - 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 + # runs the test script defined in package.json + run: npm test + + - name: Build React App + run: npm run build-react + + - name: Deploy Files to Testing Server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.TESTING_EC2_IP }} + username: ubuntu + key: ${{ secrets.EC2_SSH_KEY }} + source: "./*" + target: "/home/ubuntu/app" + + - name: Start Application on Testing Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.TESTING_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 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 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