-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demo app deployments - script to post Github status, bundle demo-app,…
… 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
Showing
4 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/**/*" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |