Skip to content

Commit

Permalink
Demo app deployments - script to post Github status, bundle demo-app,…
Browse files Browse the repository at this point in the history
… update karma config (#2800)

* Bundle and copy demo app on build

* Run npm install

* Update github deploy status

* Update github deploy status config

* Change deploy github config repo to erichdev

* Update deploy github status to get latest commit ID

* Text updates, use assign instead of object destructuring

* Pushing just to trigger build

* One more test push

* Get deploy status from argv

* Forcing build

* Forcing build

* Update karma config

* Refactor deploy based on status

* Bundle and copy demo app on build

* Run npm install

* Update github deploy status

* Update github deploy status config

* Change deploy github config repo to erichdev

* Update deploy github status to get latest commit ID

* Text updates, use assign instead of object destructuring

* Pushing just to trigger build

* One more test push

* Get deploy status from argv

* Forcing build

* Forcing build

* Update karma config

* Refactor deploy based on status

* Update deploy script to correct repo
  • Loading branch information
erichdev authored and dzearing committed Sep 12, 2017
1 parent 5ae36cd commit f332b94
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/office-ui-fabric-react/config/pre-copy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"copyTo": {
"dist": [
"index.html"
],
"dist/sass": [
"node_modules/office-ui-fabric-core/dist/sass/**/*"
],
Expand Down
10 changes: 9 additions & 1 deletion packages/office-ui-fabric-react/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ module.exports = function (config) {

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
singleRun: true,

// on disconnect, makes karma to launch another phantonJs window to restart the testcases
browserDisconnectTolerance: 5,

// these settings help reduce the timeouts to begin with.
browserNoActivityTimeout: 60000,
browserDisconnectTimeout: 30000,
captureTimeout: 60000,
};

config.set(karmaConfig);
Expand Down
25 changes: 21 additions & 4 deletions packages/office-ui-fabric-react/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ const resources = require('../../scripts/tasks/webpack-resources');
const BUNDLE_NAME = 'office-ui-fabric-react';
const IS_PRODUCTION = process.argv.indexOf('--production') > -1;

let entry = {
[BUNDLE_NAME]: './lib/index.js'
};

// In production builds, produce the demo-app bundle.
if (IS_PRODUCTION) {
entry['demo-app'] = './lib/demo/index.js';
}

module.exports = resources.createConfig(
BUNDLE_NAME,
IS_PRODUCTION,
{
entry: {
[BUNDLE_NAME]: './lib/index.js'
},
entry,

output: {
libraryTarget: 'var',
Expand All @@ -24,6 +31,16 @@ module.exports = resources.createConfig(
{
'react-dom': 'ReactDOM'
}
]
],

resolve: {
alias: {
'office-ui-fabric-react/src': path.join(__dirname, 'src'),
'office-ui-fabric-react/lib': path.join(__dirname, 'lib'),
'Props.ts.js': 'Props',
'Example.tsx.js': 'Example'
}
}

}
);
87 changes: 87 additions & 0 deletions scripts/deploy-github-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
let argv = require('yargs').argv;
let GitHubApi = require('github');

const REPO_DETAILS = {
owner: "OfficeDev",
repo: "office-ui-fabric-react",
};

let statusConfig = Object.assign({},
REPO_DETAILS,
{
state: argv.state,
description: "PR deployed. Click \"Details\" to view site",
context: "VSTS: Deploy Demo"
});

let pr = parsePRNumber();

if (!argv.token) {
throw new Error("No token specified. Use --token=<token> to provide a token.");
}

// Authenticate with github.
let github = new GitHubApi({ debug: argv.debug });

github.authenticate({
type: 'token',
token: argv.token
});

getLatestCommitFromPR();

function createStatus(sha) {
setDescription(); // Based on status of build - pending or success

github.repos.createStatus(Object.assign({}, statusConfig, { sha }),
(err, res) => {
if (err) {
throw new Error(`Failed to deploy pull request #${pr}. \n ${err}`);
}

console.log(`Successfully deployed pull request #${pr}`);
});
}


function getLatestCommitFromPR() {
github.pullRequests.get(Object.assign({}, REPO_DETAILS, { number: pr }), onGetLatestCommit);
}

function onGetLatestCommit(err, res) {
if (err)
throw new Error(`Failed to get latest commit. \n ${err}`);

// Extract the head sha from response. See https://developer.github.com/v3/pulls/#get-a-single-pull-request for full response details
if (res.head && res.head.sha)
createStatus(res.head.sha);
}

/*
The PR ID is input in the format 'refs/pull/12/merge'. This function returns just the number.
*/
function parsePRNumber() {
let splitString;

if (argv.prID) {
splitString = argv.prID.split('/');
}

if (!argv.prID || !splitString[2])
throw new Error(`Failed to get PR number. \n ${err}`);

return splitString[2];
}

/*
Set status text that will be posted to Github.
*/
function setDescription() {
if (argv.state === 'pending') {
statusConfig.description = 'Deployment pending.';
}
else if (argv.state === 'success') {
statusConfig.description = 'PR deployed. Click "Details" to view demo app.';
statusConfig.target_url = 'http://odsp-ext.azurewebsites.net/fabric-deploy-test/' + argv.prID;
}
}

0 comments on commit f332b94

Please sign in to comment.