@percy/env 1.0.0-beta.76 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -9
- package/dist/dotenv.js +0 -77
- package/dist/environment.js +0 -367
- package/dist/index.js +0 -25
- package/dist/utils.js +0 -68
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/env",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,12 +10,18 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=14"
|
|
15
|
+
},
|
|
14
16
|
"files": [
|
|
15
|
-
"dist"
|
|
17
|
+
"./dist"
|
|
16
18
|
],
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/index.js",
|
|
23
|
+
"./utils": "./dist/utils.js",
|
|
24
|
+
"./test/helpers": "./test/helpers.js"
|
|
19
25
|
},
|
|
20
26
|
"scripts": {
|
|
21
27
|
"build": "node ../../scripts/build",
|
|
@@ -23,8 +29,5 @@
|
|
|
23
29
|
"test": "node ../../scripts/test",
|
|
24
30
|
"test:coverage": "yarn test --coverage"
|
|
25
31
|
},
|
|
26
|
-
"
|
|
27
|
-
"mock-require": "^3.0.3"
|
|
28
|
-
},
|
|
29
|
-
"gitHead": "445af68d8e270e2a35fc74e26422ed5d3c91d2ae"
|
|
32
|
+
"gitHead": "6df509421a60144e4f9f5d59dc57a5675372a0b2"
|
|
30
33
|
}
|
package/dist/dotenv.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.load = load;
|
|
7
|
-
|
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
// Heavily inspired by dotenv-rails
|
|
13
|
-
// https://github.com/bkeepers/dotenv
|
|
14
|
-
// matches each valid line of a dotenv file
|
|
15
|
-
const LINE_REG = new RegExp([// key with optional export
|
|
16
|
-
'^\\s*(?:export\\s+)?(?<key>[\\w.]+)', // separator
|
|
17
|
-
'(?:\\s*=\\s*?|:\\s+?)(?:', // single quoted value or
|
|
18
|
-
'\\s*(?<squote>\')(?<sval>(?:\\\\\'|[^\'])*)\'|', // double quoted value or
|
|
19
|
-
'\\s*(?<dquote>")(?<dval>(?:\\\\"|[^"])*)"|', // unquoted value
|
|
20
|
-
'(?<uval>[^#\\r\\n]+))?', // optional comment
|
|
21
|
-
'\\s*(?:#.*)?$'].join(''), 'gm'); // interpolate variable substitutions
|
|
22
|
-
|
|
23
|
-
const INTERPOLATE_REG = /(.?)(\${?([a-zA-Z0-9_]+)?}?)/g; // expand newlines
|
|
24
|
-
|
|
25
|
-
const EXPAND_CRLF_REG = /\\(?:(r)|n)/g; // unescape characters
|
|
26
|
-
|
|
27
|
-
const UNESC_CHAR_REG = /\\([^$])/g;
|
|
28
|
-
|
|
29
|
-
function load() {
|
|
30
|
-
// don't load dotenv files when disabled
|
|
31
|
-
if (process.env.PERCY_DISABLE_DOTENV) return;
|
|
32
|
-
let {
|
|
33
|
-
NODE_ENV
|
|
34
|
-
} = process.env; // dotenv filepaths ordered by priority
|
|
35
|
-
|
|
36
|
-
let paths = [NODE_ENV && `.env.${NODE_ENV}.local`, NODE_ENV !== 'test' && '.env.local', NODE_ENV && `.env.${NODE_ENV}`, '.env']; // load each dotenv file synchronously
|
|
37
|
-
|
|
38
|
-
for (let path of paths) {
|
|
39
|
-
try {
|
|
40
|
-
let src = _fs.default.readFileSync(path, {
|
|
41
|
-
encoding: 'utf-8'
|
|
42
|
-
}); // iterate over each matching line
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (let {
|
|
46
|
-
groups: match
|
|
47
|
-
} of src.matchAll(LINE_REG)) {
|
|
48
|
-
var _ref, _ref2, _match$sval;
|
|
49
|
-
|
|
50
|
-
let value = (_ref = (_ref2 = (_match$sval = match.sval) !== null && _match$sval !== void 0 ? _match$sval : match.dval) !== null && _ref2 !== void 0 ? _ref2 : match.uval) !== null && _ref !== void 0 ? _ref : ''; // if double quoted, expand newlines
|
|
51
|
-
|
|
52
|
-
if (match.dquote) {
|
|
53
|
-
value = value.replace(EXPAND_CRLF_REG, (_, r) => r ? '\r' : '\n');
|
|
54
|
-
} // unescape characters
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
value = value.replace(UNESC_CHAR_REG, '$1'); // if not single quoted, interpolate substitutions
|
|
58
|
-
|
|
59
|
-
if (!match.squote) {
|
|
60
|
-
value = value.replace(INTERPOLATE_REG, (_, pre, ref, key) => {
|
|
61
|
-
var _process$env$key;
|
|
62
|
-
|
|
63
|
-
if (pre === '\\') return ref; // escaped reference
|
|
64
|
-
|
|
65
|
-
return pre + ((_process$env$key = process.env[key]) !== null && _process$env$key !== void 0 ? _process$env$key : '');
|
|
66
|
-
});
|
|
67
|
-
} // set process.env if not already
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!Object.prototype.hasOwnProperty.call(process.env, match.key)) {
|
|
71
|
-
process.env[match.key] = value;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} catch (e) {// silent error
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
package/dist/environment.js
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.PercyEnv = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
class PercyEnv {
|
|
11
|
-
constructor(vars = process.env) {
|
|
12
|
-
this.vars = vars;
|
|
13
|
-
} // used for getter switch statements
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
get ci() {
|
|
17
|
-
if (this.vars.TRAVIS_BUILD_ID) {
|
|
18
|
-
return 'travis';
|
|
19
|
-
} else if (this.vars.JENKINS_URL && this.vars.ghprbPullId) {
|
|
20
|
-
return 'jenkins-prb';
|
|
21
|
-
} else if (this.vars.JENKINS_URL) {
|
|
22
|
-
return 'jenkins';
|
|
23
|
-
} else if (this.vars.CIRCLECI) {
|
|
24
|
-
return 'circle';
|
|
25
|
-
} else if (this.vars.CI_NAME === 'codeship') {
|
|
26
|
-
return 'codeship';
|
|
27
|
-
} else if (this.vars.DRONE === 'true') {
|
|
28
|
-
return 'drone';
|
|
29
|
-
} else if (this.vars.SEMAPHORE === 'true') {
|
|
30
|
-
return 'semaphore';
|
|
31
|
-
} else if (this.vars.BUILDKITE === 'true') {
|
|
32
|
-
return 'buildkite';
|
|
33
|
-
} else if (this.vars.HEROKU_TEST_RUN_ID) {
|
|
34
|
-
return 'heroku';
|
|
35
|
-
} else if (this.vars.GITLAB_CI === 'true') {
|
|
36
|
-
return 'gitlab';
|
|
37
|
-
} else if (this.vars.TF_BUILD === 'True') {
|
|
38
|
-
return 'azure';
|
|
39
|
-
} else if (this.vars.APPVEYOR === 'True' || this.vars.APPVEYOR === 'true') {
|
|
40
|
-
return 'appveyor';
|
|
41
|
-
} else if (this.vars.PROBO_ENVIRONMENT === 'TRUE') {
|
|
42
|
-
return 'probo';
|
|
43
|
-
} else if (this.vars.BITBUCKET_BUILD_NUMBER) {
|
|
44
|
-
return 'bitbucket';
|
|
45
|
-
} else if (this.vars.GITHUB_ACTIONS === 'true') {
|
|
46
|
-
return 'github';
|
|
47
|
-
} else if (this.vars.NETLIFY === 'true') {
|
|
48
|
-
return 'netlify';
|
|
49
|
-
} else if (this.vars.CI) {
|
|
50
|
-
return 'CI/unknown';
|
|
51
|
-
} else {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
} // environment info reported in user-agents
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
get info() {
|
|
58
|
-
switch (this.ci) {
|
|
59
|
-
case 'github':
|
|
60
|
-
return this.vars.PERCY_GITHUB_ACTION ? `github/${this.vars.PERCY_GITHUB_ACTION}` : this.ci;
|
|
61
|
-
|
|
62
|
-
case 'gitlab':
|
|
63
|
-
return `gitlab/${this.vars.CI_SERVER_VERSION}`;
|
|
64
|
-
|
|
65
|
-
case 'semaphore':
|
|
66
|
-
return this.vars.SEMAPHORE_GIT_SHA ? 'semaphore/2.0' : 'semaphore';
|
|
67
|
-
|
|
68
|
-
default:
|
|
69
|
-
return this.ci;
|
|
70
|
-
}
|
|
71
|
-
} // current commit sha
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
get commit() {
|
|
75
|
-
if (this.vars.PERCY_COMMIT) {
|
|
76
|
-
return this.vars.PERCY_COMMIT;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let commit = (() => {
|
|
80
|
-
var _github$pull_request;
|
|
81
|
-
|
|
82
|
-
switch (this.ci) {
|
|
83
|
-
case 'travis':
|
|
84
|
-
return this.vars.TRAVIS_COMMIT;
|
|
85
|
-
|
|
86
|
-
case 'jenkins-prb':
|
|
87
|
-
return this.vars.ghprbActualCommit || this.vars.GIT_COMMIT;
|
|
88
|
-
|
|
89
|
-
case 'jenkins':
|
|
90
|
-
return (0, _utils.getJenkinsSha)() || this.vars.GIT_COMMIT;
|
|
91
|
-
|
|
92
|
-
case 'circle':
|
|
93
|
-
return this.vars.CIRCLE_SHA1;
|
|
94
|
-
|
|
95
|
-
case 'codeship':
|
|
96
|
-
return this.vars.CI_COMMIT_ID;
|
|
97
|
-
|
|
98
|
-
case 'drone':
|
|
99
|
-
return this.vars.DRONE_COMMIT;
|
|
100
|
-
|
|
101
|
-
case 'semaphore':
|
|
102
|
-
return this.vars.REVISION || this.vars.SEMAPHORE_GIT_PR_SHA || this.vars.SEMAPHORE_GIT_SHA;
|
|
103
|
-
|
|
104
|
-
case 'buildkite':
|
|
105
|
-
return this.vars.BUILDKITE_COMMIT !== 'HEAD' && this.vars.BUILDKITE_COMMIT;
|
|
106
|
-
|
|
107
|
-
case 'heroku':
|
|
108
|
-
return this.vars.HEROKU_TEST_RUN_COMMIT_VERSION;
|
|
109
|
-
|
|
110
|
-
case 'gitlab':
|
|
111
|
-
return this.vars.CI_COMMIT_SHA;
|
|
112
|
-
|
|
113
|
-
case 'azure':
|
|
114
|
-
return this.vars.SYSTEM_PULLREQUEST_SOURCECOMMITID || this.vars.BUILD_SOURCEVERSION;
|
|
115
|
-
|
|
116
|
-
case 'appveyor':
|
|
117
|
-
return this.vars.APPVEYOR_PULL_REQUEST_HEAD_COMMIT || this.vars.APPVEYOR_REPO_COMMIT;
|
|
118
|
-
|
|
119
|
-
case 'probo':
|
|
120
|
-
case 'netlify':
|
|
121
|
-
return this.vars.COMMIT_REF;
|
|
122
|
-
|
|
123
|
-
case 'bitbucket':
|
|
124
|
-
return this.vars.BITBUCKET_COMMIT;
|
|
125
|
-
|
|
126
|
-
case 'github':
|
|
127
|
-
return ((_github$pull_request = (0, _utils.github)(this.vars).pull_request) === null || _github$pull_request === void 0 ? void 0 : _github$pull_request.head.sha) || this.vars.GITHUB_SHA;
|
|
128
|
-
}
|
|
129
|
-
})();
|
|
130
|
-
|
|
131
|
-
return commit || null;
|
|
132
|
-
} // current branch name
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
get branch() {
|
|
136
|
-
if (this.vars.PERCY_BRANCH) {
|
|
137
|
-
return this.vars.PERCY_BRANCH;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let branch = (() => {
|
|
141
|
-
var _github$pull_request2;
|
|
142
|
-
|
|
143
|
-
switch (this.ci) {
|
|
144
|
-
case 'travis':
|
|
145
|
-
return this.pullRequest && this.vars.TRAVIS_PULL_REQUEST_BRANCH || this.vars.TRAVIS_BRANCH;
|
|
146
|
-
|
|
147
|
-
case 'jenkins-prb':
|
|
148
|
-
return this.vars.ghprbSourceBranch;
|
|
149
|
-
|
|
150
|
-
case 'jenkins':
|
|
151
|
-
return this.vars.CHANGE_BRANCH || this.vars.GIT_BRANCH;
|
|
152
|
-
|
|
153
|
-
case 'circle':
|
|
154
|
-
return this.vars.CIRCLE_BRANCH;
|
|
155
|
-
|
|
156
|
-
case 'codeship':
|
|
157
|
-
return this.vars.CI_BRANCH;
|
|
158
|
-
|
|
159
|
-
case 'drone':
|
|
160
|
-
return this.vars.DRONE_BRANCH;
|
|
161
|
-
|
|
162
|
-
case 'semaphore':
|
|
163
|
-
return this.vars.BRANCH_NAME || this.vars.SEMAPHORE_GIT_PR_BRANCH || this.vars.SEMAPHORE_GIT_BRANCH;
|
|
164
|
-
|
|
165
|
-
case 'buildkite':
|
|
166
|
-
return this.vars.BUILDKITE_BRANCH;
|
|
167
|
-
|
|
168
|
-
case 'heroku':
|
|
169
|
-
return this.vars.HEROKU_TEST_RUN_BRANCH;
|
|
170
|
-
|
|
171
|
-
case 'gitlab':
|
|
172
|
-
return this.vars.CI_COMMIT_REF_NAME;
|
|
173
|
-
|
|
174
|
-
case 'azure':
|
|
175
|
-
return this.vars.SYSTEM_PULLREQUEST_SOURCEBRANCH || this.vars.BUILD_SOURCEBRANCHNAME;
|
|
176
|
-
|
|
177
|
-
case 'appveyor':
|
|
178
|
-
return this.vars.APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH || this.vars.APPVEYOR_REPO_BRANCH;
|
|
179
|
-
|
|
180
|
-
case 'probo':
|
|
181
|
-
return this.vars.BRANCH_NAME;
|
|
182
|
-
|
|
183
|
-
case 'bitbucket':
|
|
184
|
-
return this.vars.BITBUCKET_BRANCH;
|
|
185
|
-
|
|
186
|
-
case 'github':
|
|
187
|
-
return ((_github$pull_request2 = (0, _utils.github)(this.vars).pull_request) === null || _github$pull_request2 === void 0 ? void 0 : _github$pull_request2.head.ref) || this.vars.GITHUB_REF;
|
|
188
|
-
|
|
189
|
-
case 'netlify':
|
|
190
|
-
return this.vars.HEAD;
|
|
191
|
-
}
|
|
192
|
-
})();
|
|
193
|
-
|
|
194
|
-
return (branch === null || branch === void 0 ? void 0 : branch.replace(/^refs\/\w+?\//, '')) || null;
|
|
195
|
-
} // pull request number
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
get pullRequest() {
|
|
199
|
-
if (this.vars.PERCY_PULL_REQUEST) {
|
|
200
|
-
return this.vars.PERCY_PULL_REQUEST;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
let pr = (() => {
|
|
204
|
-
var _this$vars$CI_PULL_RE, _this$vars$PULL_REQUE, _github$pull_request3;
|
|
205
|
-
|
|
206
|
-
switch (this.ci) {
|
|
207
|
-
case 'travis':
|
|
208
|
-
return this.vars.TRAVIS_PULL_REQUEST !== 'false' && this.vars.TRAVIS_PULL_REQUEST;
|
|
209
|
-
|
|
210
|
-
case 'jenkins-prb':
|
|
211
|
-
return this.vars.ghprbPullId;
|
|
212
|
-
|
|
213
|
-
case 'jenkins':
|
|
214
|
-
return this.vars.CHANGE_ID;
|
|
215
|
-
|
|
216
|
-
case 'circle':
|
|
217
|
-
return (_this$vars$CI_PULL_RE = this.vars.CI_PULL_REQUESTS) === null || _this$vars$CI_PULL_RE === void 0 ? void 0 : _this$vars$CI_PULL_RE.split('/').slice(-1)[0];
|
|
218
|
-
|
|
219
|
-
case 'drone':
|
|
220
|
-
return this.vars.CI_PULL_REQUEST;
|
|
221
|
-
|
|
222
|
-
case 'semaphore':
|
|
223
|
-
return this.vars.PULL_REQUEST_NUMBER || this.vars.SEMAPHORE_GIT_PR_NUMBER;
|
|
224
|
-
|
|
225
|
-
case 'buildkite':
|
|
226
|
-
return this.vars.BUILDKITE_PULL_REQUEST !== 'false' && this.vars.BUILDKITE_PULL_REQUEST;
|
|
227
|
-
|
|
228
|
-
case 'heroku':
|
|
229
|
-
return this.vars.HEROKU_PR_NUMBER;
|
|
230
|
-
|
|
231
|
-
case 'gitlab':
|
|
232
|
-
return this.vars.CI_MERGE_REQUEST_IID;
|
|
233
|
-
|
|
234
|
-
case 'azure':
|
|
235
|
-
return this.vars.SYSTEM_PULLREQUEST_PULLREQUESTID || this.vars.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER;
|
|
236
|
-
|
|
237
|
-
case 'appveyor':
|
|
238
|
-
return this.vars.APPVEYOR_PULL_REQUEST_NUMBER;
|
|
239
|
-
|
|
240
|
-
case 'probo':
|
|
241
|
-
return (_this$vars$PULL_REQUE = this.vars.PULL_REQUEST_LINK) === null || _this$vars$PULL_REQUE === void 0 ? void 0 : _this$vars$PULL_REQUE.split('/').slice(-1)[0];
|
|
242
|
-
|
|
243
|
-
case 'bitbucket':
|
|
244
|
-
return this.vars.BITBUCKET_PR_ID;
|
|
245
|
-
|
|
246
|
-
case 'netlify':
|
|
247
|
-
return this.vars.PULL_REQUEST !== 'false' && this.vars.REVIEW_ID;
|
|
248
|
-
|
|
249
|
-
case 'github':
|
|
250
|
-
return (_github$pull_request3 = (0, _utils.github)(this.vars).pull_request) === null || _github$pull_request3 === void 0 ? void 0 : _github$pull_request3.number;
|
|
251
|
-
}
|
|
252
|
-
})();
|
|
253
|
-
|
|
254
|
-
return pr || null;
|
|
255
|
-
} // parallel total & nonce
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
get parallel() {
|
|
259
|
-
let total = parseInt(this.vars.PERCY_PARALLEL_TOTAL, 10);
|
|
260
|
-
if (!Number.isInteger(total)) total = null; // no nonce if no total
|
|
261
|
-
|
|
262
|
-
let nonce = total && (() => {
|
|
263
|
-
var _this$vars$BUILD_TAG;
|
|
264
|
-
|
|
265
|
-
if (this.vars.PERCY_PARALLEL_NONCE) {
|
|
266
|
-
return this.vars.PERCY_PARALLEL_NONCE;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
switch (this.ci) {
|
|
270
|
-
case 'travis':
|
|
271
|
-
return this.vars.TRAVIS_BUILD_NUMBER;
|
|
272
|
-
|
|
273
|
-
case 'jenkins-prb':
|
|
274
|
-
return this.vars.BUILD_NUMBER;
|
|
275
|
-
|
|
276
|
-
case 'jenkins':
|
|
277
|
-
return (_this$vars$BUILD_TAG = this.vars.BUILD_TAG) === null || _this$vars$BUILD_TAG === void 0 ? void 0 : _this$vars$BUILD_TAG.split('').reverse().join('').substring(0, 60);
|
|
278
|
-
|
|
279
|
-
case 'circle':
|
|
280
|
-
return this.vars.CIRCLE_WORKFLOW_ID || this.vars.CIRCLE_BUILD_NUM;
|
|
281
|
-
|
|
282
|
-
case 'codeship':
|
|
283
|
-
return this.vars.CI_BUILD_NUMBER || this.vars.CI_BUILD_ID;
|
|
284
|
-
|
|
285
|
-
case 'drone':
|
|
286
|
-
return this.vars.DRONE_BUILD_NUMBER;
|
|
287
|
-
|
|
288
|
-
case 'semaphore':
|
|
289
|
-
return this.vars.SEMAPHORE_WORKFLOW_ID || `${this.vars.SEMAPHORE_BRANCH_ID}/${this.vars.SEMAPHORE_BUILD_NUMBER}`;
|
|
290
|
-
|
|
291
|
-
case 'buildkite':
|
|
292
|
-
return this.vars.BUILDKITE_BUILD_ID;
|
|
293
|
-
|
|
294
|
-
case 'heroku':
|
|
295
|
-
return this.vars.HEROKU_TEST_RUN_ID;
|
|
296
|
-
|
|
297
|
-
case 'gitlab':
|
|
298
|
-
return this.vars.CI_PIPELINE_ID;
|
|
299
|
-
|
|
300
|
-
case 'azure':
|
|
301
|
-
return this.vars.BUILD_BUILDID;
|
|
302
|
-
|
|
303
|
-
case 'appveyor':
|
|
304
|
-
return this.vars.APPVEYOR_BUILD_ID;
|
|
305
|
-
|
|
306
|
-
case 'probo':
|
|
307
|
-
return this.vars.BUILD_ID;
|
|
308
|
-
|
|
309
|
-
case 'bitbucket':
|
|
310
|
-
return this.vars.BITBUCKET_BUILD_NUMBER;
|
|
311
|
-
|
|
312
|
-
case 'github':
|
|
313
|
-
return this.vars.GITHUB_RUN_ID;
|
|
314
|
-
}
|
|
315
|
-
})();
|
|
316
|
-
|
|
317
|
-
return {
|
|
318
|
-
total: total || null,
|
|
319
|
-
nonce: nonce || null
|
|
320
|
-
};
|
|
321
|
-
} // git information for the current commit
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
get git() {
|
|
325
|
-
return (0, _utils.getCommitData)(this.commit, this.branch, this.vars);
|
|
326
|
-
} // manually set build commit and branch targets
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
get target() {
|
|
330
|
-
return {
|
|
331
|
-
commit: this.vars.PERCY_TARGET_COMMIT || null,
|
|
332
|
-
branch: this.vars.PERCY_TARGET_BRANCH || null
|
|
333
|
-
};
|
|
334
|
-
} // build marked as partial
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
get partial() {
|
|
338
|
-
let partial = this.vars.PERCY_PARTIAL_BUILD;
|
|
339
|
-
return !!partial && partial !== '0';
|
|
340
|
-
} // percy token
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
get token() {
|
|
344
|
-
return this.vars.PERCY_TOKEN || null;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
} // cache getters on initial call so subsequent calls are not re-computed
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
exports.PercyEnv = PercyEnv;
|
|
351
|
-
Object.defineProperties(PercyEnv.prototype, Object.entries(Object.getOwnPropertyDescriptors(PercyEnv.prototype)).reduce((proto, [key, {
|
|
352
|
-
get,
|
|
353
|
-
...descr
|
|
354
|
-
}]) => !get ? proto : Object.assign(proto, {
|
|
355
|
-
[key]: Object.assign(descr, {
|
|
356
|
-
get() {
|
|
357
|
-
let value = get.call(this);
|
|
358
|
-
Object.defineProperty(this, key, {
|
|
359
|
-
value
|
|
360
|
-
});
|
|
361
|
-
return value;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
})
|
|
365
|
-
}), {}));
|
|
366
|
-
var _default = PercyEnv;
|
|
367
|
-
exports.default = _default;
|
package/dist/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "PercyEnv", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _environment.PercyEnv;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "default", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _environment.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
var _environment = _interopRequireWildcard(require("./environment"));
|
|
20
|
-
|
|
21
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
|
-
|
|
23
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
|
-
|
|
25
|
-
require('./dotenv').load();
|
package/dist/utils.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getCommitData = getCommitData;
|
|
7
|
-
exports.getJenkinsSha = getJenkinsSha;
|
|
8
|
-
exports.git = git;
|
|
9
|
-
exports.github = github;
|
|
10
|
-
|
|
11
|
-
var _child_process = require("child_process");
|
|
12
|
-
|
|
13
|
-
var _fs = require("fs");
|
|
14
|
-
|
|
15
|
-
const GIT_COMMIT_FORMAT = ['COMMIT_SHA:%H', 'AUTHOR_NAME:%an', 'AUTHOR_EMAIL:%ae', 'COMMITTER_NAME:%cn', 'COMMITTER_EMAIL:%ce', 'COMMITTED_DATE:%ai', // order is important, this must come last because the regex is a multiline match.
|
|
16
|
-
'COMMIT_MESSAGE:%B'].join('%n'); // git show format uses %n for newlines.
|
|
17
|
-
|
|
18
|
-
function git(args) {
|
|
19
|
-
try {
|
|
20
|
-
return (0, _child_process.execSync)(`git ${args}`, {
|
|
21
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
22
|
-
encoding: 'utf-8'
|
|
23
|
-
});
|
|
24
|
-
} catch (e) {
|
|
25
|
-
return '';
|
|
26
|
-
}
|
|
27
|
-
} // get raw commit data
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function getCommitData(sha, branch, vars = {}) {
|
|
31
|
-
let raw = git(`show ${sha || 'HEAD'} --quiet --format=${GIT_COMMIT_FORMAT}`); // prioritize PERCY_GIT_* vars and fallback to GIT_* vars
|
|
32
|
-
|
|
33
|
-
let get = key => {
|
|
34
|
-
var _raw$match;
|
|
35
|
-
|
|
36
|
-
return vars[`PERCY_GIT_${key}`] || ((_raw$match = raw.match(new RegExp(`${key}:(.*)`, 'm'))) === null || _raw$match === void 0 ? void 0 : _raw$match[1]) || vars[`GIT_${key}`] || null;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
sha: (sha === null || sha === void 0 ? void 0 : sha.length) === 40 ? sha : get('COMMIT_SHA'),
|
|
41
|
-
branch: branch || git('rev-parse --abbrev-ref HEAD') || null,
|
|
42
|
-
message: get('COMMIT_MESSAGE'),
|
|
43
|
-
authorName: get('AUTHOR_NAME'),
|
|
44
|
-
authorEmail: get('AUTHOR_EMAIL'),
|
|
45
|
-
committedAt: get('COMMITTED_DATE'),
|
|
46
|
-
committerName: get('COMMITTER_NAME'),
|
|
47
|
-
committerEmail: get('COMMITTER_EMAIL')
|
|
48
|
-
};
|
|
49
|
-
} // the sha needed from Jenkins merge commits is the parent sha
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
function getJenkinsSha() {
|
|
53
|
-
let data = getCommitData();
|
|
54
|
-
return data.authorName === 'Jenkins' && data.authorEmail === 'nobody@nowhere' && data.message.match(/^Merge commit [^\s]+ into HEAD$/) && git('rev-parse HEAD^');
|
|
55
|
-
} // github actions are triggered by webhook events which are saved to the filesystem
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
function github({
|
|
59
|
-
GITHUB_EVENT_PATH
|
|
60
|
-
}) {
|
|
61
|
-
if (!github.payload && GITHUB_EVENT_PATH && (0, _fs.existsSync)(GITHUB_EVENT_PATH)) {
|
|
62
|
-
try {
|
|
63
|
-
github.payload = JSON.parse((0, _fs.readFileSync)(GITHUB_EVENT_PATH, 'utf8'));
|
|
64
|
-
} catch (e) {}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return github.payload || (github.payload = {});
|
|
68
|
-
}
|