Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #45 from jrit/master
Browse files Browse the repository at this point in the history
Slack channel build notifications
  • Loading branch information
jrit committed Jan 28, 2016
2 parents d7b355e + 82c77e4 commit b7b99a4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Changelog

#### 6.1.0 Add Slack channel notifications

This is not included in deployment by default in this release, so to use, after deployment runs:

`grunt notification_slack --env=dev --slacktoken=$SLACK_TOKEN`

In the above replace `dev` with whatever the environment is and set an environment variable with a Slack API Token which you can generate from [the bottom of this page](https://api.slack.com/web).

Setting "notification.slackChannel" for each environment in `env.json` is also required.

#### 6.0.0 [Breaking Changes] Drop bower for browserify; massive refactor

A quick reference to the big changes for v6:
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ Configuration of this plugin relies heavily on 3 files:
```js
module.exports = function ( grunt )
{
"use strict";

// for environment configuration
var env = grunt.option( "env" ) || "local";
grunt.initConfig( {
env: grunt.file.readJSON( "env.json" )[ env ],
envName: env,
version: grunt.option( "gitver" ) || Date.now() // for deployment cache-busting
version: grunt.option( "gitver" ) || Date.now(), // for deployment cache-busting
slackApiToken: grunt.option( "slacktoken" ) // if using slack notifications
} );

var path = require( "path" );
Expand Down Expand Up @@ -92,7 +91,8 @@ Configuration of this plugin relies heavily on 3 files:
"aws.s3Bucket": "yourapp-dev",
"aws.distributionId": "ABCDEFGHIJKLMN",
"notification.emailTo": "[email protected]",
"notification.emailFrom": "[email protected]"
"notification.emailFrom": "[email protected]",
"notification.slackChannel": "channelname"
},
"staging": {
"apiroot": "https://api-staging.yourapp.com",
Expand All @@ -101,7 +101,8 @@ Configuration of this plugin relies heavily on 3 files:
"aws.s3Bucket": "yourapp-staging",
"aws.distributionId": "OPQRSTUVWXYZAB",
"notification.emailTo": [ "[email protected]", "[email protected]" ],
"notification.emailFrom": "[email protected]"
"notification.emailFrom": "[email protected]",
"notification.slackChannel": "channelname"
},
"prod": {
"apiroot": "https://api.yourapp.com",
Expand All @@ -110,7 +111,8 @@ Configuration of this plugin relies heavily on 3 files:
"aws.s3Bucket": "yourapp-prod",
"aws.distributionId": "JKLMNOPQRSTUVW",
"notification.emailTo": [ "[email protected]", "[email protected]" ],
"notification.emailFrom": "[email protected]"
"notification.emailFrom": "[email protected]",
"notification.slackChannel": "channelname"
}
}
```
Expand Down
48 changes: 48 additions & 0 deletions grunt/notification_slack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict";

var Slack = require( "slack-node" );

module.exports = function ( grunt )
{
var envConfig = grunt.config( "env" );
var slackApiToken = grunt.config( "slackApiToken" );
var deployVersion = grunt.config( "version" );
var pkgVersion = grunt.file.readJSON( "package.json" ).version || "";

grunt.registerTask( "notification_slack", "Notify a Slack channel that a deployment is going out", function ()
{
var done = this.async();

var slackChannel = envConfig[ "notification.slackChannel" ];
var host = envConfig.host;

if( !slackChannel || !slackApiToken || !host )
{
grunt.log.ok( "Slack Notification exiting without sending" );
done();
return;
}

var slacker = new Slack( slackApiToken );

slacker.api( "chat.postMessage", {
text: "Build " + pkgVersion + " @" + deployVersion + " for " + host
+ " should be available in about 10 minutes.",
channel: slackChannel,
username: "Release Bot"
},
function ( err, res )
{
if( err )
{
grunt.fail.warn( err, err.stack );
}
else
{
grunt.log.ok( "Slack Notification sent" );
grunt.log.write( JSON.stringify( res ) );
}
done();
} );
} );
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"babel-preset-es2015": "^6.3.13",
"connect-modrewrite": "^0.8.2",
"cssnano": "^3.3.2",
"serve-static": "^1.10.0"
"serve-static": "^1.10.0",
"slack-node": "^0.1.7"
}
}

0 comments on commit b7b99a4

Please sign in to comment.