Skip to content

Commit

Permalink
fix: add NPM deployment with release notes and fix flow issues (#24)
Browse files Browse the repository at this point in the history
Add deployment to NPM and ping to Jenkins after with release notes.
fix flow issues to complete the cycle as we have on other NPM packages.
Solve FEC-9495, FEC-10064.
  • Loading branch information
Yuvalke authored Jun 28, 2020
1 parent 0aae5ee commit fd6ded4
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 46 deletions.
93 changes: 78 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,88 @@

conditions: v1
sudo: required
dist: trusty
dist: xenial
language: node_js
node_js:
- "node"
- "node"

addons:
chrome: stable

services:
- xvfb
cache:
yarn: true
directories:
- node_modules
- node_modules

before_install:
- export CHROME_BIN=/usr/bin/google-chrome
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sudo apt-get update
- sudo apt-get install -y libappindicator1 fonts-liberation
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- sudo dpkg -i google-chrome*.deb
- export DISPLAY=:99.0
- chmod +x ./scripts/travis.sh

script: ./scripts/travis.sh

stages:
- Tests
- Release canary
- Release

script:
- npm run eslint
- npm run flow
- npm run test
jobs:
fast_finish: true
include:
# https://docs.travis-ci.com/user/build-stages/deploy-github-releases/
- stage: Release
name: "Releasing a new version"
if: tag IS present
env: TRAVIS_MODE=release
deploy:
- provider: releases
api_key: $GH_TOKEN
file_glob: true
file: dist/*
prerelease: true
skip_cleanup: true
on:
branch: master
tags: true
- provider: npm
api_key: $NPM_TOKEN
email: $NPM_EMAIL
skip_cleanup: true
on:
tags: true
branch: master
after_deploy:
- currentVersion=$(npx -c 'echo "$npm_package_version"')
- chmod +x ./scripts/after_deploy.sh
- ./scripts/after_deploy.sh "cast-receiver" "$currentVersion" "$JENKINS_TAG_TOKEN"
# publish canary package if on master
- stage: Release canary
if: (branch = master) AND (type != pull_request) AND commit_message !~ /^chore\(release\)/
env: TRAVIS_MODE=releaseCanary
deploy:
provider: npm
api_key: $NPM_TOKEN
email: $NPM_EMAIL
skip_cleanup: true
tag: canary
on:
tags: false
branch: master
after_deploy:
- currentVersion=$(npx -c 'echo "$npm_package_version"')
- echo $currentVersion
- chmod +x ./scripts/after_deploy.sh
- ./scripts/after_deploy.sh "cast-receiver" "$currentVersion" "$JENKINS_CANARY_TOKEN"
# Required tests
- stage: Tests
if: (branch = master) OR (tag IS present) OR (type = pull_request)
name: "Running lint"
env: TRAVIS_MODE=lint
- stage: Tests
if: (branch = master) OR (tag IS present) OR (type = pull_request)
name: "Running Flow type check"
env: TRAVIS_MODE=flow
- stage: Tests
if: (branch = master) OR (tag IS present) OR (type = pull_request)
name: "Running unit tests"
env: TRAVIS_MODE=unitTests
4 changes: 4 additions & 0 deletions flow-typed/receiver-options-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
* }
*}
*/

import {PKMediaSourceOptionsObject, PKStreamPriorityObject} from '@playkit-js/playkit-js';
import {ProviderOptionsObject} from 'playkit-js-providers';

type _KPReceiverOptionsObject = {
provider: ProviderOptionsObject,
playback?: {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
}
},
"devDependencies": {
"@playkit-js/playkit-js": "^0.58.1",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-eslint": "^7.1.1",
Expand Down Expand Up @@ -74,6 +75,7 @@
"lint-staged": "^7.1.2",
"mocha": "^3.2.0",
"mocha-cli": "^1.0.1",
"playkit-js-providers": "https://github.com/kaltura/playkit-js-providers.git#v2.20.5",
"pre-push": "^0.1.1",
"prettier": "^1.13.2",
"sinon": "^2.0.0",
Expand Down
2 changes: 2 additions & 0 deletions scripts/after_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
curl -k -d "{'name':$1, 'version':$2, 'source':'npm'}" -H "Content-Type: application/json" -X POST https://jenkins.ovp.kaltura.com/generic-webhook-trigger/invoke?token=$3
1 change: 1 addition & 0 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ];
else
echo "Unknown travis mode: ${TRAVIS_MODE}" 1>&2
exit 1
fi
47 changes: 17 additions & 30 deletions src/receiver-ads-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReceiverAdsManager {
_ad: ?Ad;
_adBreak: ?AdBreak;
_adIsPlaying: boolean;
_adCanSkipTriggered: false;
_adCanSkipTriggered: boolean = false;
_adLifecycleEventHandlers: {[event: string]: Function};
_adTrackingEventHandlers: {[event: string]: Function};
_playerEventHandlers: {[event: string]: Function};
Expand All @@ -28,7 +28,6 @@ class ReceiverAdsManager {
this._context = cast.framework.CastReceiverContext.getInstance();
this._playerManager = this._context.getPlayerManager();
this._player = player;
this._bindMethods();
this._attachListeners();
}

Expand All @@ -42,36 +41,22 @@ class ReceiverAdsManager {
return !!this._adBreak;
}

_bindMethods(): void {
this._onPlayerLoadComplete = this._onPlayerLoadComplete.bind(this);
this._onBreakStarted = this._onBreakStarted.bind(this);
this._onBreakEnded = this._onBreakEnded.bind(this);
this._onBreakClipLoading = this._onBreakClipLoading.bind(this);
this._onBreakClipStarted = this._onBreakClipStarted.bind(this);
this._onBreakClipEnded = this._onBreakClipEnded.bind(this);
this._onAdPaused = this._onAdPaused.bind(this);
this._onAdResumed = this._onAdResumed.bind(this);
this._onAdProgress = this._onAdProgress.bind(this);
this._onMuteChange = this._onMuteChange.bind(this);
this._onVolumeChange = this._onVolumeChange.bind(this);
}

_attachListeners(): void {
this._adLifecycleEventHandlers = {
[cast.framework.events.EventType.PLAYER_LOAD_COMPLETE]: this._onPlayerLoadComplete,
[cast.framework.events.EventType.BREAK_STARTED]: this._onBreakStarted,
[cast.framework.events.EventType.BREAK_ENDED]: this._onBreakEnded,
[cast.framework.events.EventType.BREAK_CLIP_LOADING]: this._onBreakClipLoading,
[cast.framework.events.EventType.BREAK_CLIP_STARTED]: this._onBreakClipStarted,
[cast.framework.events.EventType.BREAK_CLIP_ENDED]: this._onBreakClipEnded
[cast.framework.events.EventType.PLAYER_LOAD_COMPLETE]: this._onPlayerLoadComplete.bind(this),
[cast.framework.events.EventType.BREAK_STARTED]: this._onBreakStarted.bind(this),
[cast.framework.events.EventType.BREAK_ENDED]: this._onBreakEnded.bind(this),
[cast.framework.events.EventType.BREAK_CLIP_LOADING]: this._onBreakClipLoading.bind(this),
[cast.framework.events.EventType.BREAK_CLIP_STARTED]: this._onBreakClipStarted.bind(this),
[cast.framework.events.EventType.BREAK_CLIP_ENDED]: this._onBreakClipEnded.bind(this)
};
this._adTrackingEventHandlers = {
[cast.framework.events.EventType.PAUSE]: this._onAdPaused,
[cast.framework.events.EventType.PLAY]: this._onAdResumed
[cast.framework.events.EventType.PAUSE]: this._onAdPaused.bind(this),
[cast.framework.events.EventType.PLAY]: this._onAdResumed.bind(this)
};
this._playerEventHandlers = {
[EventType.MUTE_CHANGE]: this._onMuteChange,
[EventType.VOLUME_CHANGE]: this._onVolumeChange
[EventType.MUTE_CHANGE]: this._onMuteChange.bind(this),
[EventType.VOLUME_CHANGE]: this._onVolumeChange.bind(this)
};
Object.keys(this._adLifecycleEventHandlers).forEach(event => this._playerManager.addEventListener(event, this._adLifecycleEventHandlers[event]));
}
Expand Down Expand Up @@ -155,7 +140,7 @@ class ReceiverAdsManager {
this._timePercentEvent.AD_REACHED_75_PERCENT = true;
this._sendEventAndCustomMessage(this._player.Event.AD_THIRD_QUARTILE);
}
if (!this._adCanSkipTriggered && this._ad.skippable) {
if (!this._adCanSkipTriggered && this._ad && this._ad.skippable) {
if (adCurrentTime >= this._ad.skipOffset) {
this._sendEventAndCustomMessage(this._player.Event.AD_CAN_SKIP);
this._adCanSkipTriggered = true;
Expand Down Expand Up @@ -183,14 +168,16 @@ class ReceiverAdsManager {
if (toggle) {
Object.keys(this._adTrackingEventHandlers).forEach(event => this._playerManager.addEventListener(event, this._adTrackingEventHandlers[event]));
Object.keys(this._playerEventHandlers).forEach(event => this._player.addEventListener(event, this._playerEventHandlers[event]));
this._adProgressIntervalId = setInterval(this._onAdProgress, 300);
this._adProgressIntervalId = setInterval(this._onAdProgress.bind(this), 300);
} else {
Object.keys(this._adTrackingEventHandlers).forEach(event =>
this._playerManager.removeEventListener(event, this._adTrackingEventHandlers[event])
);
Object.keys(this._playerEventHandlers).forEach(event => this._player.removeEventListener(event, this._playerEventHandlers[event]));
clearInterval(this._adProgressIntervalId);
this._adProgressIntervalId = null;
if (this._adProgressIntervalId) {
clearInterval(this._adProgressIntervalId);
this._adProgressIntervalId = null;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/receiver-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class ReceiverManager {
}
}

_maybeCreateVmapAdsRequest(media: Object): Object {
_maybeCreateVmapAdsRequest(media: Object): void {
if (media.customData && media.customData.vmapAdsRequest) {
media.vmapAdsRequest = media.customData.vmapAdsRequest;
}
Expand Down
8 changes: 8 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
"flowtype/no-types-missing-file-annotation": "off",
"require-jsdoc": "off",
"valid-jsdoc": "off",
"mocha-no-only/mocha-no-only": ["error"]
}
}
5 changes: 5 additions & 0 deletions test/setup/karma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import prepareTestEnvironment from './prepare-test-environment';
import loadSpecs from './load-specs';

prepareTestEnvironment();
loadSpecs();
13 changes: 13 additions & 0 deletions test/setup/load-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @returns {void}
*/
export function loadSpecs() {
const context = require.context('../src/', true, /\.spec\.js$/);
for (const key of context.keys()) {
describe(key, () => {
context(key);
});
}
}

export default loadSpecs;
17 changes: 17 additions & 0 deletions test/setup/prepare-test-environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import chai from 'chai';
import sinonChai from 'sinon-chai';
import sinon from 'sinon/pkg/sinon';

/**
* @returns {void}
*/
export function prepareTestEnvironment() {
chai.should();
chai.use(sinonChai);
global.chai = chai;
global.expect = chai.expect;
global.should = chai.should;
global.sinon = sinon;
}

export default prepareTestEnvironment;
5 changes: 5 additions & 0 deletions test/src/cast-player.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('Cast Player', () => {
it('', function(done) {
done();
});
});
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
version "1.1.0"
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.0.tgz#50c1e2260ac0ed9439a181de3725a0168d59c48a"

"@playkit-js/playkit-js@^0.58.1":
version "0.58.1"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js/-/playkit-js-0.58.1.tgz#480ef32c39c005728ce0b1a5fa58478e73ec3c0c"
integrity sha512-1wpaeJDhIP/vmPlWL+XXxes8edKKuSE3Xjs1z44gFkvkWqdmStt5UjZSQQxJ/6ZMv6tGSHKLvo4J/4AlDA1Z6w==
dependencies:
js-logger "^1.3.0"
ua-parser-js "^0.7.13"

"@samverschueren/stream-to-observable@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
Expand Down Expand Up @@ -7015,6 +7023,12 @@ pkg-up@^1.0.0:
version "0.1.5"
resolved "https://github.com/kaltura/playkit-js-ott-analytics.git#45e4603035aced93bba5c3fb5507b7a80e2802b7"

"playkit-js-providers@https://github.com/kaltura/playkit-js-providers.git#v2.20.5":
version "2.20.5"
resolved "https://github.com/kaltura/playkit-js-providers.git#1e1eb5f6fceaf5e19fac27fc881231a439b33df8"
dependencies:
js-logger "^1.3.0"

"playkit-js-providers@https://github.com/kaltura/playkit-js-providers.git#v2.7.1":
version "2.7.1"
resolved "https://github.com/kaltura/playkit-js-providers.git#c8ab75495159053b15ac5235c4970926d62e75d7"
Expand Down

0 comments on commit fd6ded4

Please sign in to comment.