Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
138 lines (111 loc) · 3.94 KB
/
Copy pathindex.js
File metadata and controls
138 lines (111 loc) · 3.94 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* eslint-disable comma-dangle */
/* eslint-disable max-len, max-lines-per-function */
// eslint-disable-next-line strict
"use strict";
const path = require("path");
const { execSync } = require("child_process");
const BasePlugin = require("ember-cli-deploy-plugin");
const packageJson = require("./package.json");
// Dynamically resolve `sentry-cli` location
const sentryCliPackagePath = require.resolve("@sentry/cli/package.json");
const { dir: sentryCliDirectory } = path.parse(sentryCliPackagePath);
const sentryCliRelativeBinLocation =
require(sentryCliPackagePath).bin["sentry-cli"];
const sentryCliAbsoluteBinLocation = path.join(
sentryCliDirectory,
sentryCliRelativeBinLocation
);
module.exports = {
name: packageJson.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;
},
url: "",
injectDebugIds: true,
},
requiredConfig: ["appName", "orgName", "authToken"],
didBuild() {
if (!this.readConfig("injectDebugIds")) {
this.log("SENTRY: Debug ID injection disabled, skipping...");
return;
}
const assetsDir = this.readConfig("assetsDir");
this.log("SENTRY: Injecting Debug IDs...");
this.sentryCliExec("sourcemaps", `inject "${assetsDir}"`);
this.log("SENTRY: Debug IDs injected!");
},
didPrepare() {
const releaseName = `${this.readConfig("appName")}@${this.readConfig(
"revisionKey"
)}`;
const assetsDir = this.readConfig("assetsDir");
this.log("SENTRY: Creating release...");
this.sentryCliExec("releases", `new "${releaseName}"`);
this.log("SENTRY: Assigning commits...");
this.sentryCliExec(
"releases",
`set-commits "${releaseName}" --auto --ignore-missing`
);
this.log("SENTRY: Uploading source maps...");
this.sentryCliExec(
"sourcemaps",
`upload --release "${releaseName}" ${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(
"deploys",
`new --release "${releaseName}" -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, subCommand) {
const authToken = this.readConfig("authToken");
const orgName = this.readConfig("orgName");
const appName = this.readConfig("appName");
const url = this.readConfig("url");
return this._exec(
[
sentryCliAbsoluteBinLocation,
url ? `--url ${url}` : null,
`--auth-token ${authToken}`,
command,
`--org ${orgName}`,
`--project ${appName}`,
subCommand,
]
.filter(Boolean)
.join(" ")
);
},
_exec(command = "") {
return execSync(command, { cwd: this.project.root });
},
});
return new DeployPlugin();
},
};