Skip to content

Commit

Permalink
GitHub actions build (#5168)
Browse files Browse the repository at this point in the history
* Run tests using GitHub Actions

* Node 10

* Test CI fails

* Use npm to run tests

* Fix package json to run tests

* Enable v3 TEST api for both development env and CI

* Run CI on both Node 10 and 12

* Allow downgrading Mongo
  • Loading branch information
sulkaharo committed Nov 10, 2019
1 parent 9877a51 commit 5bc6799
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ bundle/bundle.out.js
.idea/
*.iml
my.env
my.*.env

*.env
static/bower_components/
.*.sw?
.DS_Store
Expand Down
7 changes: 7 additions & 0 deletions ci.test.env
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion lib/api3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions tests/fail.test.js
Original file line number Diff line number Diff line change
@@ -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);
});

});

0 comments on commit 5bc6799

Please sign in to comment.