Skip to content

Instantly share code, notes, and snippets.

@melodyogonna
Created October 28, 2021 11:03
Show Gist options
  • Save melodyogonna/576a230186869e58e4ce1e326746fa58 to your computer and use it in GitHub Desktop.
Save melodyogonna/576a230186869e58e4ce1e326746fa58 to your computer and use it in GitHub Desktop.
Setup a CI pipeline for Node JS using Github Actions. Integrate MySQL for integration testing.
name: Node.js CI
on:
pull_request:
branches: [ master, development, testing ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: password
ports:
- 3800:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Setup MySQL
run: mysql --host 127.0.0.1 --port $DB_PORT -uroot -ppassword -e "CREATE DATABASE test_db"
- run: npm install
- name: Prepare testing
run: |
echo "Starting Migration ...."
npm run migration
- run: npm test
env:
DB_TEST_NAME: 'test_db'
DB_TEST_USER: 'root'
DB_TEST_PASSWORD: 'password'
NODE_ENV: 'development'
DB_TEST_HOST: 'localhost'
DB_PORT: 3800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment