Create nodejs-server.yml #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test Node.js Server | |
# Run this workflow for every new commit and PR that changes the Node.js server | |
on: | |
push: | |
branches: [ master ] | |
paths: | |
- 'controller/node-js/**' | |
- '.github/workflows/nodejs-server.yml' | |
pull_request: | |
branches: [ master ] | |
paths: | |
- 'controller/node-js/**' | |
- '.github/workflows/nodejs-server.yml' | |
defaults: | |
run: | |
working-directory: ./controller/node-js | |
jobs: | |
# Set the job key for testing the Node.js server | |
nodejs-server: | |
# Name the Job | |
name: Build and Test Node.js Server | |
# Set the type of machine to run on | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '16' # Specify your desired Node.js version | |
- run: node --version | |
- name: Install dependencies | |
run: npm install | |
- name: Start server in background | |
run: nohup npm start & | |
- name: Wait for server to start | |
run: sleep 10 | |
- name: Test server | |
run: | | |
curl -I http://localhost:7071 | |
curl http://localhost:7071 | |
- name: Stop background server | |
if: always() | |
run: | | |
pkill -f "npm start" || echo "Server not running" |