diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000000..23cc61e5ef7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,32 @@ +name: CI test + +on: [push] + +jobs: + build: + + runs-on: ubuntu-16.04 + + strategy: + matrix: + node-version: [10.x, 12.x] + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm install + - name: Install MongoDB + run: | + wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add - + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list + sudo apt-get update + sudo apt-get install -y mongodb-org + sudo apt-get install -y --allow-downgrades mongodb-org=3.6.14 mongodb-org-server=3.6.14 mongodb-org-shell=3.6.14 mongodb-org-mongos=3.6.14 mongodb-org-tools=3.6.14 + - name: Start MongoDB + run: sudo systemctl start mongod + - name: Run tests + run: npm run-script test-ci diff --git a/.gitignore b/.gitignore index 5f82d7929f7..1cf7ab06f2f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,8 @@ bundle/bundle.out.js .idea/ *.iml my.env +my.*.env -*.env static/bower_components/ .*.sw? .DS_Store diff --git a/ci.test.env b/ci.test.env new file mode 100644 index 00000000000..c57e5eeb0c4 --- /dev/null +++ b/ci.test.env @@ -0,0 +1,7 @@ +CUSTOMCONNSTR_mongo=mongodb://127.0.0.1:27017/testdb +API_SECRET=abcdefghij123 +HOSTNAME=localhost +INSECURE_USE_HTTP=true +PORT=1337 +NODE_ENV=production +CI=true \ No newline at end of file diff --git a/lib/api3/index.js b/lib/api3/index.js index 70fb6a4d59e..d188a5ee537 100644 --- a/lib/api3/index.js +++ b/lib/api3/index.js @@ -59,6 +59,7 @@ function configure (env, ctx) { app.set('version', env.version); app.set('apiVersion', apiConst.API3_VERSION); app.set('units', env.DISPLAY_UNITS); + app.set('ci', process.env['CI'] ? true: false); app.set('enabledCollections', ['devicestatus', 'entries', 'food', 'profile', 'settings', 'treatments']); self.setENVTruthy('API3_SECURITY_ENABLE', apiConst.API3_SECURITY_ENABLE); @@ -73,7 +74,7 @@ function configure (env, ctx) { app.get('/version', require('./specific/version')(app, ctx, env)); - if (app.get('env') === 'development') { // for development and testing purposes only + if (app.get('env') === 'development' || app.get('ci')) { // for development and testing purposes only app.get('/test', async function test (req, res) { try { diff --git a/package.json b/package.json index 346e67c6251..25a96043401 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ }, "scripts": { "start": "node server.js", - "test": "env-cmd ./test.env mocha --exit tests/*.test.js", + "test": "env-cmd ./my.test.env mocha --exit tests/*.test.js", + "test-ci": "env-cmd ./ci.test.env mocha --exit tests/*.test.js", "env": "env", "postinstall": "webpack --mode production --config webpack.config.js && npm run-script update-buster", "bundle": "webpack --mode production --config webpack.config.js && npm run-script update-buster", diff --git a/tests/fail.test.js b/tests/fail.test.js new file mode 100644 index 00000000000..eefda445b3d --- /dev/null +++ b/tests/fail.test.js @@ -0,0 +1,14 @@ +'use strict'; + +require('should'); + +// This test is included just so we have an easy to template to intentionally cause +// builds to fail + +describe('fail', function ( ) { + + it('should not fail', function () { + true.should.equal(true); + }); + +});