Skip to content

Commit

Permalink
Merge branch 'add-deployment' into dev
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Krug <[email protected]>
  • Loading branch information
michikrug committed Apr 8, 2021
2 parents 33ada5c + 0aa7186 commit 56cfd48
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 35 deletions.
20 changes: 20 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name-template: '$RESOLVED_VERSION'
tag-template: '$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
labels:
- 'maintenance'
- 'dependencies'
template: |
## Changes
$CHANGES
14 changes: 5 additions & 9 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ name: CI/CD
on:
push:
branches: [ main ]
tags: [ v* ]
tags: [ "*" ]
pull_request:
branches: [ main ]
release:
types: [ published ]

jobs:
unit-testing:
Expand Down Expand Up @@ -36,12 +38,6 @@ jobs:
name: coverage
path: coverage/

- name: Comment Test Coverage
if: ${{ github.event_name == 'pull_request' }}
uses: romeovs/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

code-analysis:
name: Code Analysis
runs-on: ubuntu-latest
Expand All @@ -59,7 +55,7 @@ jobs:
uses: github/codeql-action/analyze@v1

deployment:
if: startsWith(github.ref, 'refs/tags/v')
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
name: Install and Deploy
runs-on: ubuntu-latest
needs: [unit-testing, code-analysis]
Expand All @@ -81,7 +77,7 @@ jobs:
uses: google-github-actions/deploy-cloud-functions@main
with:
credentials: ${{ secrets.GCP_SA_KEY }}
name: openhab-google-assistant
name: ${{ github.event_name == 'release' && 'openhabGoogleAssistant_prod' || 'openhabGoogleAssistant_test' }}
runtime: nodejs12
source_dir: ./functions
entry_point: openhabGoogleAssistant
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Draft Release

on:
push:
tags: [ "*" ]

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Draft Release
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions functions/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
*
**/
module.exports = {
//userpass: '[email protected]:Password1',
host: '<YOUR-CLOUD-HOST>',
port: 443,
path: '/YOUR/REST/ENDPOINT'
//userpass: process.env.OH_USERPASS || '[email protected]:Password1',
host: process.env.OH_HOST || '<YOUR-CLOUD-HOST>',
port: process.env.OH_PORT || 443,
path: process.env.OH_PATH || '/YOUR/REST/ENDPOINT'
};
4 changes: 3 additions & 1 deletion functions/devices/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Camera extends DefaultDevice {
static getAttributes(item) {
const config = this.getConfig(item);
return {
cameraStreamSupportedProtocols: (config.protocols || 'hls,dash').split(',').map((s) => s.trim()),
cameraStreamSupportedProtocols: (config.protocols || 'hls,dash,smooth_stream,progressive_mp4')
.split(',')
.map((s) => s.trim()),
cameraStreamNeedAuthToken: config.token ? true : false,
cameraStreamNeedDrmEncryption: false
};
Expand Down
25 changes: 12 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@
"test": "jest --silent --coverage",
"test-ci": "jest --silent --coverage --ci",
"lint": "eslint --ext .js --cache .",
"fix": "eslint --fix --ext .js --cache ."
"fix": "eslint --fix --ext .js --cache .",
"release-major": "npm version major -m \":bookmark: Release (major): %s\"",
"release-minor": "npm version minor -m \":bookmark: Release (minor): %s\"",
"release-patch": "npm version patch -m \":bookmark: Release (patch): %s\""
},
"jest": {
"setupFiles": [
"./tests/setenv.js"
]
},
"license": "EPL-2.0",
"bugs": {
"url": "https://github.com/openhab/openhab-google-assistant/issues"
},
"homepage": "https://github.com/openhab/openhab-google-assistant",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions testServer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const openhabGA = require('./functions/index.js');

app.use(bodyParser.json());
app.use(express.json());

app.use('/', (req, res) => {
openhabGA.openhabGoogleAssistant(req, res);
});

app.listen(3000, () => {
console.log('Server is listening on port 3000');
const port = process.env.OH_SERVER_PORT || 3000;
app.listen(port, () => {
console.log('Server is listening on port %s', port);
});
8 changes: 7 additions & 1 deletion tests/config.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const Config = require('../functions/config.js');

describe('Config', () => {
test('Config all properties', () => {
test('All properties available', () => {
expect(Object.keys(Config)).toStrictEqual(['host', 'port', 'path']);
});

test('Properties used from ENV', () => {
expect(Config.host).toBe('test.host');
expect(Config.port).toBe('1234');
expect(Config.path).toBe('/test/items');
});
});
2 changes: 1 addition & 1 deletion tests/devices/camera.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Camera Device', () => {
}
};
expect(Device.getAttributes(item)).toStrictEqual({
cameraStreamSupportedProtocols: ['hls', 'dash'],
cameraStreamSupportedProtocols: ['hls', 'dash', 'smooth_stream', 'progressive_mp4'],
cameraStreamNeedAuthToken: false,
cameraStreamNeedDrmEncryption: false
});
Expand Down
3 changes: 3 additions & 0 deletions tests/setenv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.env.OH_HOST = 'test.host';
process.env.OH_PORT = '1234';
process.env.OH_PATH = '/test/items';

0 comments on commit 56cfd48

Please sign in to comment.