-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (73 loc) · 2.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* eslint-disable max-len, max-lines-per-function */
'use strict';
const path = require('path');
const { execSync } = require('child_process');
const BasePlugin = require('ember-cli-deploy-plugin');
module.exports = {
name: require('./package').name,
createDeployPlugin(options) {
const DeployPlugin = BasePlugin.extend({
name: options.name,
defaultConfig: {
assetsDir(context) {
return path.join(context.distDir, 'assets');
},
revisionKey(context) {
return context.revisionData && context.revisionData.revisionKey;
},
environment(context) {
return context.deployTarget;
}
},
requiredConfig: ['appName', 'orgName', 'authToken'],
didPrepare() {
const releaseName = `${this.readConfig('appName')}@${this.readConfig('revisionKey')}`;
const assetsDir = this.readConfig('assetsDir');
this.log('SENTRY: Creating release...');
this.sentryCliExec(`releases new ${releaseName}`);
const ignoreAssigningCommits = this.readConfig('ignoreAssigningCommits');
if (ignoreAssigningCommits) {
this.log('SENTRY: Assigning commits...[IGNORED]');
} else {
this.log('SENTRY: Assigning commits...');
this.sentryCliExec(`releases set-commits --auto ${releaseName}`);
}
this.log('SENTRY: Uploading source maps...');
this.sentryCliExec(`releases files ${releaseName} upload-sourcemaps --rewrite ${assetsDir}`);
this.log('SENTRY: Finalizing release...');
this.sentryCliExec(`releases finalize ${releaseName}`);
this.log('SENTRY: Release published!...');
},
didDeploy() {
const appName = this.readConfig('appName');
const releaseName = `${appName}@${this.readConfig('revisionKey')}`;
const environment = this.readConfig('environment');
this.log('SENTRY: Deploying release...');
this.sentryCliExec(`releases deploys ${releaseName} new -e ${environment}`);
this.log('SENTRY: Deployed!');
},
didFail() {
const appName = this.readConfig('appName');
const releaseName = `${appName}@${this.readConfig('revisionKey')}`;
this.log('SENTRY: Deleting release...');
this.sentryCliExec(`releases delete ${releaseName}`);
this.log('SENTRY: Release deleted!');
},
sentryCliExec(command) {
const authToken = this.readConfig('authToken');
const orgName = this.readConfig('orgName');
const appName = this.readConfig('appName');
return this._exec(
`SENTRY_ORG=${orgName} ` +
`SENTRY_AUTH_TOKEN=${authToken} ` +
`SENTRY_PROJECT=${appName} ` +
`node_modules/.bin/sentry-cli ${command}`
);
},
_exec(command = '') {
return execSync(command, { cwd: this.project.root });
}
});
return new DeployPlugin();
}
};