fix: make ci yml better and try again #4
This file contains hidden or 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: Node.js CI | |
| on: | |
| push: | |
| branches: [ "master", "main" ] | |
| pull_request: | |
| branches: [ "master", "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| services: | |
| mongodb: | |
| image: mongo:4.4 | |
| ports: | |
| - 27017:27017 | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ROOT_PASSWORD: mysecretpassword | |
| MYSQL_DATABASE: dvws_sqldb | |
| ports: | |
| - 3306:3306 | |
| options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
| strategy: | |
| matrix: | |
| node-version: [20.x, 22.x] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install system dependencies (Linux) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libxml2 libxml2-dev | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Install Dependencies | |
| run: npm install --build-from-source | |
| - name: Seed Database | |
| env: | |
| SQL_LOCAL_CONN_URL: localhost | |
| SQL_USERNAME: root | |
| SQL_PASSWORD: mysecretpassword | |
| MONGO_LOCAL_CONN_URL: mongodb://localhost:27017/node-dvws | |
| run: node startup_script.js | |
| - name: Start Server and Run Tests | |
| env: | |
| EXPRESS_JS_PORT: 3000 | |
| XML_RPC_PORT: 9090 | |
| GRAPHQL_PORT: 4000 | |
| SQL_LOCAL_CONN_URL: localhost | |
| SQL_USERNAME: root | |
| SQL_PASSWORD: mysecretpassword | |
| MONGO_LOCAL_CONN_URL: mongodb://localhost:27017/node-dvws | |
| JWT_SECRET: access | |
| run: | | |
| # Start server in background | |
| node app.js > app.log 2>&1 & | |
| PID=$! | |
| echo "Server started with PID $PID" | |
| # Wait for server to be ready (using wait-on http) | |
| npx wait-on http://127.0.0.1:3000/openAPI-spec.json --timeout 60000 | |
| # Run tests (allow failure so we can print logs) | |
| set +e | |
| npm run test:vulnerabilities | |
| EXIT_CODE=$? | |
| set -e | |
| # Kill server | |
| kill $PID | |
| # Display logs | |
| echo "=== Application Logs ===" | |
| cat app.log | |
| echo "========================" | |
| exit $EXIT_CODE |