Skip to content

Commit

Permalink
chore: notification about release (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
imrekq authored and pimenovoleg committed Oct 23, 2019
1 parent ec4a91d commit 95369aa
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 182 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"node-sass": "^4.11.0",
"postcss-loader": "^3.0.0",
"raw-loader": "^0.5.1",
"request": "^2.88.0",
"resolve-bin": "^0.4.0",
"resolve-url-loader": "^2.3.1",
"rollup": "^0.56.5",
Expand Down
54 changes: 54 additions & 0 deletions tools/release/notify-release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as request from 'request';
import * as dotenv from 'dotenv';
import { extractReleaseNotes } from './extract-release-notes';
import { join } from "path";
import { CHANGELOG_FILE_NAME } from './stage-release';
import chalk from 'chalk';


export function notify(tag, version) {
if (!verifyNotificationPossibility()) {
return;
}

const result = dotenv.config();

const url = result.parsed.MATTERMOST_ENDPOINT_URL;
const channel = result.parsed.MATTERMOST_CHANNEL;

const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };

const body = `payload={
"channel": "${channel}",
"username": "Wall-e",
"short": false,
"text": " #### [![Mosaic Logo](https://i.ibb.co/fQNPgv6/logo-png-200.png =32x32)osaic](https://github.com/positive-js/mosaic/tree/${tag}) was published.
${prepareChangeLog(version)}"
}`;

request.post({
url,
headers,
body
}, (error, response) => {
if (error || response.statusCode !== 200) {
console.error(chalk.red(` ✘ Could not post notification in Mattermost.`));
return;
}

console.info(chalk.green(` ✓ Notification is posted in Mattermost.`));
});
}

export function verifyNotificationPossibility() {
const result = dotenv.config();

return !result.error && result.parsed.MATTERMOST_ENDPOINT_URL && result.parsed.MATTERMOST_CHANNEL;
}

function prepareChangeLog(version) {
const changelogPath = join(join(__dirname, '../../'), CHANGELOG_FILE_NAME);
const extractedReleaseNotes = extractReleaseNotes(changelogPath, version);

return extractedReleaseNotes.releaseNotes.replace(/"/g, '\\\"')
}
20 changes: 20 additions & 0 deletions tools/release/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { checkReleasePackage } from './release-output/check-packages';
import { releasePackages } from './release-output/release-packages';
import { CHANGELOG_FILE_NAME } from './stage-release';
import { parseVersionName, Version } from './version-name/parse-version';
import { notify, verifyNotificationPossibility } from './notify-release';


/** Maximum allowed tries to authenticate NPM. */
Expand Down Expand Up @@ -75,6 +76,10 @@ class PublishReleaseTask extends BaseReleaseTask {
// publish branch is sufficient as unstaged changes are not specific to Git branches.
this.verifyNoUncommittedChanges();

if (!verifyNotificationPossibility()) {
await this.promptPublishReleaseWithoutNotification();
}

// Branch that will be used to build the output for the release of the current version.
const publishBranch = this.switchToPublishBranch(newVersion);

Expand Down Expand Up @@ -143,6 +148,8 @@ class PublishReleaseTask extends BaseReleaseTask {

console.info(chalk.yellow(` ⚠ Please draft a new release of the version on Github.`));
console.info(chalk.yellow(` ${newReleaseUrl}`));

notify(npmDistTag, newVersionName);
}

/**
Expand Down Expand Up @@ -213,6 +220,19 @@ class PublishReleaseTask extends BaseReleaseTask {
}
}

/**
* Prompts the user whether he is sure that the script should continue publishing
* the release to NPM.
*/
private async promptPublishReleaseWithoutNotification() {
if (!await this.promptConfirm(
'File .env not found or invalid. Are you sure that you want to release without notification')) {
console.log();
console.log(chalk.yellow('Aborting publish...'));
process.exit(0);
}
}

/**
* Checks whether NPM is currently authenticated. If not, the user will be prompted to enter
* the NPM credentials that are necessary to publish the release. We achieve this by basically
Expand Down
Loading

0 comments on commit 95369aa

Please sign in to comment.