From aa409be42007c72c64c620a2309d1077b180a913 Mon Sep 17 00:00:00 2001 From: Agnes Lin Date: Thu, 18 Feb 2021 11:02:59 -0500 Subject: [PATCH] ci: switch from travis to gh actions Signed-off-by: Agnes Lin --- .github/workflows/continuous-integration.yaml | 43 +++++++++++++++++++ .travis.yml | 21 --------- pretest.js | 4 +- test/init.js | 8 ++-- 4 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/continuous-integration.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml new file mode 100644 index 0000000..420e627 --- /dev/null +++ b/.github/workflows/continuous-integration.yaml @@ -0,0 +1,43 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + node-version: [10, 12, 14, 15] + services: + mysql: + image: mysql:5.7.22 + env: + MYSQL_USER: user + MYSQL_PASSWORD: pass + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: 'testdb' + MYSQL_ROOT_PASSWORD: root + + steps: + - name: Set Up MySQL + run: sudo /etc/init.d/mysql start + + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Create DB and User + run: | + mysql -uroot -proot -e 'CREATE DATABASE testdb;' + mysql -uroot -proot -e "CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pass';" + mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON * . * TO 'user'@'localhost';" + mysql -uroot -proot -e "FLUSH PRIVILEGES" + - run: npm install + - run: npm test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3cbd3b1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: node_js -node_js: - - "10" - - "12" - - "14" -# Xenial build environment comes with MySQL 5.7 -dist: xenial -services: - - mysql -env: - global: - - MYSQL_HOST=localhost - - MYSQL_PORT=3306 - - MYSQL_USER=test - - MYSQL_PASSWORD=test -before_install: - - mysql -u root -e "CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';" - - mysql -e "use mysql; update user set authentication_string=PASSWORD('test') where User='test'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;" - - mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION;FLUSH PRIVILEGES;" - - mysql -e "GRANT SUPER ON *.* TO 'test'@'localhost' IDENTIFIED BY 'test';FLUSH PRIVILEGES;" - diff --git a/pretest.js b/pretest.js index 02e5019..b68d509 100644 --- a/pretest.js +++ b/pretest.js @@ -14,9 +14,9 @@ process.env.MYSQL_HOST = process.env.MYSQL_PORT = process.env.MYSQL_PORT || process.env.MYSQL_PORT || 3306; process.env.MYSQL_USER = - process.env.MYSQL_USER || process.env.MYSQL_USER || 'test'; + process.env.MYSQL_USER || process.env.MYSQL_USER || 'user'; process.env.MYSQL_PASSWORD = - process.env.MYSQL_PASSWORD || process.env.MYSQL_PASSWORD || 'test'; + process.env.MYSQL_PASSWORD || process.env.MYSQL_PASSWORD || 'pass'; const fs = require('fs'); const cp = require('child_process'); diff --git a/test/init.js b/test/init.js index 5f7db03..d729a57 100644 --- a/test/init.js +++ b/test/init.js @@ -12,11 +12,11 @@ let DataSource = juggler.DataSource; const config = require('rc')('loopback', {test: {mysql: {}}}).test.mysql; global.getConfig = function(options) { const dbConf = { - host: process.env.MYSQL_HOST || config.host || 'localhost', + host: process.env.MYSQL_HOST || config.host || '127.0.0.1', port: process.env.MYSQL_PORT || config.port || 3306, - database: process.env.MYSQL_DATABASE || 'myapp_test', - username: process.env.MYSQL_USER || config.username, - password: process.env.MYSQL_PASSWORD || config.password, + database: process.env.MYSQL_DATABASE || 'testdb', + username: process.env.MYSQL_USER || config.username || 'user', + password: process.env.MYSQL_PASSWORD || config.password || 'pass', createDatabase: true, };