Skip to content

Commit

Permalink
feat: handle semantic release errors and output additional sentry errors
Browse files Browse the repository at this point in the history
  • Loading branch information
seibert-io committed Oct 20, 2021
1 parent 1e2a2fd commit c675ff9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Create a plugin by creating a plugin package providing a class as it's default e
## Package development

### Creating a release
- Make and commit changes to branch `develop`
- Make and commit changes to branch `develop`, run `npm run build`
- Merge `develop` into `master` or cherry-pick changes to release
- Make sure a Github token has been exported to the shell you execute the next command in via `export GH_TOKEN=xxx`
- Execute `npm run release-util release create` on branch `master`
27 changes: 18 additions & 9 deletions dist/commands/release/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function executeSemanticRelease(dryRun) {
function createRelease(dryRun) {
if (dryRun === void 0) { dryRun = false; }
return __awaiter(this, void 0, void 0, function () {
var checks, _a, _b, releaseCreated, _c, _d;
var checks, _a, _b, releaseCreated, _c, _d, error_1;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
Expand All @@ -97,25 +97,34 @@ function createRelease(dryRun) {
if (checks.includes(false)) {
log(chalk_1["default"].white('Release Prevented by plugin'));
}
return [4 /*yield*/, executeSemanticRelease(dryRun)];
_e.label = 3;
case 3:
_e.trys.push([3, 8, , 9]);
return [4 /*yield*/, executeSemanticRelease(dryRun)];
case 4:
releaseCreated = _e.sent();
if (!releaseCreated) return [3 /*break*/, 6];
if (!releaseCreated) return [3 /*break*/, 7];
_d = (_c = Promise).all;
return [4 /*yield*/, getPlugins_1["default"]()];
case 4: return [4 /*yield*/, _d.apply(_c, [(_e.sent()).map(function (plugin) {
case 5: return [4 /*yield*/, _d.apply(_c, [(_e.sent()).map(function (plugin) {
return plugin.afterCreateRelease(dryRun);
})])];
case 5:
case 6:
_e.sent();
log(chalk_1["default"].greenBright('Finished'));
process.exit();
return [3 /*break*/, 7];
case 6:
_e.label = 7;
case 7: return [3 /*break*/, 9];
case 8:
error_1 = _e.sent();
console.error(error_1);
log('Failed');
process.exit(1);
return [3 /*break*/, 9];
case 9:
log('Finished');
process.exit(0);
_e.label = 7;
case 7: return [2 /*return*/];
return [2 /*return*/];
}
});
});
Expand Down
4 changes: 4 additions & 0 deletions dist/plugins/sentry-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ var SentryPlugin = /** @class */ (function (_super) {
if (!process.env.SENTRY_AUTH_TOKEN) {
throw new Error('Please set environment variable SENTRY_AUTH_TOKEN');
}
if (!process.env.SENTRY_DSN) {
throw new Error('Please set environment variable SENTRY_DSN');
}
if (!process.env.SENTRY_ORG) {
throw new Error('Please set environment variable SENTRY_ORG');
}
if (!process.env.SENTRY_PROJECT) {
throw new Error('Please set environment variable SENTRY_PROJECT');
}
shell.env.SENTRY_DSN = process.env.SENTRY_DSN || '';
shell.env.SENTRY_AUTH_TOKEN = process.env.SENTRY_AUTH_TOKEN || '';
shell.env.SENTRY_ORG = process.env.SENTRY_ORG || '';
sentryProject = process.env.SENTRY_PROJECT || '';
Expand Down
37 changes: 21 additions & 16 deletions src/commands/release/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,26 @@ export default async function createRelease(dryRun: boolean = false): Promise<vo
}

// (changelog, version bump, git commit)
const releaseCreated: boolean = await executeSemanticRelease(dryRun);

if (releaseCreated) {
await Promise.all(
(await getPlugins()).map(
(plugin: Plugin): Promise<void> => {
return plugin.afterCreateRelease(dryRun);
}
)
);

log(chalk.greenBright('Finished'));
process.exit();
} else {
log('Finished');
process.exit(0);
try {
const releaseCreated: boolean = await executeSemanticRelease(dryRun);

if (releaseCreated) {
await Promise.all(
(await getPlugins()).map(
(plugin: Plugin): Promise<void> => {
return plugin.afterCreateRelease(dryRun);
}
)
);

log(chalk.greenBright('Finished'));
process.exit();
}
} catch (error) {
console.error(error);
log('Failed');
process.exit(1);
}
log('Finished');
process.exit(0);
}
5 changes: 5 additions & 0 deletions src/plugins/sentry-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export default class SentryPlugin extends Plugin {
throw new Error('Please set environment variable SENTRY_AUTH_TOKEN');
}

if (!process.env.SENTRY_DSN) {
throw new Error('Please set environment variable SENTRY_DSN');
}

if (!process.env.SENTRY_ORG) {
throw new Error('Please set environment variable SENTRY_ORG');
}
Expand All @@ -78,6 +82,7 @@ export default class SentryPlugin extends Plugin {
throw new Error('Please set environment variable SENTRY_PROJECT');
}

shell.env.SENTRY_DSN = process.env.SENTRY_DSN || '';
shell.env.SENTRY_AUTH_TOKEN = process.env.SENTRY_AUTH_TOKEN || '';
shell.env.SENTRY_ORG = process.env.SENTRY_ORG || '';

Expand Down

0 comments on commit c675ff9

Please sign in to comment.