Skip to content
This repository was archived by the owner on Aug 14, 2020. It is now read-only.

Commit d44b1c8

Browse files
simplify and fix
1 parent 5ac8c04 commit d44b1c8

File tree

2 files changed

+138
-154
lines changed

2 files changed

+138
-154
lines changed

dist/index.js

Lines changed: 128 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports =
3434
/******/ // the startup function
3535
/******/ function startup() {
3636
/******/ // Load entry module and return exports
37-
/******/ return __webpack_require__(74);
37+
/******/ return __webpack_require__(765);
3838
/******/ };
3939
/******/
4040
/******/ // run startup
@@ -43,93 +43,6 @@ module.exports =
4343
/************************************************************************/
4444
/******/ ({
4545

46-
/***/ 74:
47-
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
48-
49-
const core = __webpack_require__(587)
50-
const exec = __webpack_require__(423)
51-
const path = __webpack_require__(622)
52-
const fs = __webpack_require__(747)
53-
54-
const SCOPE_DSN = 'SCOPE_DSN'
55-
56-
const DEFAULT_ARGUMENTS = [
57-
'--testRunner=@undefinedlabs/scope-agent/jest/testRunner',
58-
'--runner=@undefinedlabs/scope-agent/jest/runner',
59-
'--setupFilesAfterEnv=@undefinedlabs/scope-agent/jest/setupTests',
60-
'--runInBand',
61-
]
62-
63-
const DEFAULT_COMMAND = 'npm test'
64-
65-
const NPM_INSTALL_COMMAND = 'npm install --save-dev @undefinedlabs/scope-agent'
66-
const YARN_INSTALL_COMMAND = 'yarn add --dev @undefinedlabs/scope-agent'
67-
68-
const isYarnRepo = (cwd = process.cwd()) => {
69-
console.log('current directory', cwd)
70-
console.log('yarn lock position', __webpack_require__.ab + "scope-for-javascript-action/" + cwd + '/yarn.lock')
71-
return fs.existsSync(__webpack_require__.ab + "scope-for-javascript-action/" + cwd + '/yarn.lock')
72-
}
73-
74-
async function run() {
75-
try {
76-
const command = core.getInput('command') || DEFAULT_COMMAND
77-
const dsn = core.getInput('dsn') || process.env[SCOPE_DSN]
78-
79-
if (!dsn) {
80-
throw Error('Cannot find the Scope DSN')
81-
}
82-
83-
let apiEndpoint, apiKey
84-
try {
85-
const { username, origin } = new URL(dsn)
86-
apiEndpoint = origin
87-
apiKey = username
88-
} catch (e) {}
89-
90-
if (!apiEndpoint || !apiKey) {
91-
throw Error('SCOPE_DSN does not have the correct format')
92-
}
93-
94-
console.log(`Command: ${command}`)
95-
if (dsn) {
96-
console.log(`DSN has been set.`)
97-
}
98-
99-
const isYarn = isYarnRepo()
100-
101-
console.log(`Project is using ${isYarn ? 'yarn' : 'npm'}`)
102-
103-
await exec.exec(isYarn ? YARN_INSTALL_COMMAND : NPM_INSTALL_COMMAND, null, {
104-
ignoreReturnCode: true,
105-
})
106-
107-
return ExecScopeRun(command, apiEndpoint, apiKey, isYarn)
108-
} catch (error) {
109-
core.setFailed(error.message)
110-
}
111-
}
112-
113-
function ExecScopeRun(command = DEFAULT_COMMAND, apiEndpoint, apiKey, isYarn) {
114-
return exec.exec(
115-
`CI=true ${command}`,
116-
isYarn ? DEFAULT_ARGUMENTS : ['--', ...DEFAULT_ARGUMENTS],
117-
{
118-
env: {
119-
...process.env,
120-
SCOPE_API_ENDPOINT: apiEndpoint,
121-
SCOPE_APIKEY: apiKey,
122-
SCOPE_AUTO_INSTRUMENT: true,
123-
},
124-
}
125-
)
126-
}
127-
128-
run()
129-
130-
131-
/***/ }),
132-
13346
/***/ 87:
13447
/***/ (function(module) {
13548

@@ -144,51 +57,7 @@ module.exports = require("child_process");
14457

14558
/***/ }),
14659

147-
/***/ 423:
148-
/***/ (function(__unusedmodule, exports, __webpack_require__) {
149-
150-
"use strict";
151-
152-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
153-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
154-
return new (P || (P = Promise))(function (resolve, reject) {
155-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
156-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
157-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
158-
step((generator = generator.apply(thisArg, _arguments || [])).next());
159-
});
160-
};
161-
Object.defineProperty(exports, "__esModule", { value: true });
162-
const tr = __webpack_require__(855);
163-
/**
164-
* Exec a command.
165-
* Output will be streamed to the live console.
166-
* Returns promise with return code
167-
*
168-
* @param commandLine command to execute (can include additional args). Must be correctly escaped.
169-
* @param args optional arguments for tool. Escaping is handled by the lib.
170-
* @param options optional exec options. See ExecOptions
171-
* @returns Promise<number> exit code
172-
*/
173-
function exec(commandLine, args, options) {
174-
return __awaiter(this, void 0, void 0, function* () {
175-
const commandArgs = tr.argStringToArray(commandLine);
176-
if (commandArgs.length === 0) {
177-
throw new Error(`Parameter 'commandLine' cannot be null or empty.`);
178-
}
179-
// Path to tool to execute should be first arg
180-
const toolPath = commandArgs[0];
181-
args = commandArgs.slice(1).concat(args || []);
182-
const runner = new tr.ToolRunner(toolPath, args, options);
183-
return runner.exec();
184-
});
185-
}
186-
exports.exec = exec;
187-
//# sourceMappingURL=exec.js.map
188-
189-
/***/ }),
190-
191-
/***/ 438:
60+
/***/ 337:
19261
/***/ (function(__unusedmodule, exports, __webpack_require__) {
19362

19463
"use strict";
@@ -261,7 +130,7 @@ function escape(s) {
261130

262131
/***/ }),
263132

264-
/***/ 587:
133+
/***/ 586:
265134
/***/ (function(__unusedmodule, exports, __webpack_require__) {
266135

267136
"use strict";
@@ -276,7 +145,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
276145
});
277146
};
278147
Object.defineProperty(exports, "__esModule", { value: true });
279-
const command_1 = __webpack_require__(438);
148+
const command_1 = __webpack_require__(337);
280149
const os = __webpack_require__(87);
281150
const path = __webpack_require__(622);
282151
/**
@@ -484,7 +353,130 @@ module.exports = require("fs");
484353

485354
/***/ }),
486355

487-
/***/ 855:
356+
/***/ 765:
357+
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
358+
359+
const core = __webpack_require__(586)
360+
const exec = __webpack_require__(831)
361+
const fs = __webpack_require__(747)
362+
363+
const SCOPE_DSN = 'SCOPE_DSN'
364+
365+
const DEFAULT_ARGUMENTS = [
366+
'--testRunner=@undefinedlabs/scope-agent/jest/testRunner',
367+
'--runner=@undefinedlabs/scope-agent/jest/runner',
368+
'--setupFilesAfterEnv=@undefinedlabs/scope-agent/jest/setupTests',
369+
'--runInBand',
370+
]
371+
372+
const DEFAULT_COMMAND = 'npm test'
373+
374+
const NPM_INSTALL_COMMAND = 'npm install --save-dev @undefinedlabs/scope-agent'
375+
const YARN_INSTALL_COMMAND = 'yarn add --dev @undefinedlabs/scope-agent'
376+
377+
const isYarnRepo = () => fs.existsSync('yarn.lock')
378+
379+
async function run() {
380+
try {
381+
const command = core.getInput('command') || DEFAULT_COMMAND
382+
const dsn = core.getInput('dsn') || process.env[SCOPE_DSN]
383+
384+
if (!dsn) {
385+
throw Error('Cannot find the Scope DSN')
386+
}
387+
388+
let apiEndpoint, apiKey
389+
try {
390+
const { username, origin } = new URL(dsn)
391+
apiEndpoint = origin
392+
apiKey = username
393+
} catch (e) {}
394+
395+
if (!apiEndpoint || !apiKey) {
396+
throw Error('SCOPE_DSN does not have the correct format')
397+
}
398+
399+
console.log(`Command: ${command}`)
400+
if (dsn) {
401+
console.log(`DSN has been set.`)
402+
}
403+
404+
const isYarn = isYarnRepo()
405+
406+
console.log(`Project is using ${isYarn ? 'yarn' : 'npm'}`)
407+
408+
await exec.exec(isYarn ? YARN_INSTALL_COMMAND : NPM_INSTALL_COMMAND, null, {
409+
ignoreReturnCode: true,
410+
})
411+
412+
return ExecScopeRun(command, apiEndpoint, apiKey, isYarn)
413+
} catch (error) {
414+
core.setFailed(error.message)
415+
}
416+
}
417+
418+
function ExecScopeRun(command = DEFAULT_COMMAND, apiEndpoint, apiKey, isYarn) {
419+
return exec.exec(command, isYarn ? DEFAULT_ARGUMENTS : ['--', ...DEFAULT_ARGUMENTS], {
420+
env: {
421+
...process.env,
422+
SCOPE_API_ENDPOINT: apiEndpoint,
423+
SCOPE_APIKEY: apiKey,
424+
SCOPE_AUTO_INSTRUMENT: true,
425+
CI: true,
426+
},
427+
})
428+
}
429+
430+
run()
431+
432+
433+
/***/ }),
434+
435+
/***/ 831:
436+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
437+
438+
"use strict";
439+
440+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
441+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
442+
return new (P || (P = Promise))(function (resolve, reject) {
443+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
444+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
445+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
446+
step((generator = generator.apply(thisArg, _arguments || [])).next());
447+
});
448+
};
449+
Object.defineProperty(exports, "__esModule", { value: true });
450+
const tr = __webpack_require__(963);
451+
/**
452+
* Exec a command.
453+
* Output will be streamed to the live console.
454+
* Returns promise with return code
455+
*
456+
* @param commandLine command to execute (can include additional args). Must be correctly escaped.
457+
* @param args optional arguments for tool. Escaping is handled by the lib.
458+
* @param options optional exec options. See ExecOptions
459+
* @returns Promise<number> exit code
460+
*/
461+
function exec(commandLine, args, options) {
462+
return __awaiter(this, void 0, void 0, function* () {
463+
const commandArgs = tr.argStringToArray(commandLine);
464+
if (commandArgs.length === 0) {
465+
throw new Error(`Parameter 'commandLine' cannot be null or empty.`);
466+
}
467+
// Path to tool to execute should be first arg
468+
const toolPath = commandArgs[0];
469+
args = commandArgs.slice(1).concat(args || []);
470+
const runner = new tr.ToolRunner(toolPath, args, options);
471+
return runner.exec();
472+
});
473+
}
474+
exports.exec = exec;
475+
//# sourceMappingURL=exec.js.map
476+
477+
/***/ }),
478+
479+
/***/ 963:
488480
/***/ (function(__unusedmodule, exports, __webpack_require__) {
489481

490482
"use strict";

src/index.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const core = require('@actions/core')
22
const exec = require('@actions/exec')
3-
const path = require('path')
43
const fs = require('fs')
54

65
const SCOPE_DSN = 'SCOPE_DSN'
@@ -17,11 +16,7 @@ const DEFAULT_COMMAND = 'npm test'
1716
const NPM_INSTALL_COMMAND = 'npm install --save-dev @undefinedlabs/scope-agent'
1817
const YARN_INSTALL_COMMAND = 'yarn add --dev @undefinedlabs/scope-agent'
1918

20-
const isYarnRepo = (cwd = process.cwd()) => {
21-
console.log('current directory', cwd)
22-
console.log('yarn lock position', path.resolve(cwd, 'yarn.lock'))
23-
return fs.existsSync(path.resolve(cwd, 'yarn.lock'))
24-
}
19+
const isYarnRepo = () => fs.existsSync('yarn.lock')
2520

2621
async function run() {
2722
try {
@@ -63,18 +58,15 @@ async function run() {
6358
}
6459

6560
function ExecScopeRun(command = DEFAULT_COMMAND, apiEndpoint, apiKey, isYarn) {
66-
return exec.exec(
67-
`CI=true ${command}`,
68-
isYarn ? DEFAULT_ARGUMENTS : ['--', ...DEFAULT_ARGUMENTS],
69-
{
70-
env: {
71-
...process.env,
72-
SCOPE_API_ENDPOINT: apiEndpoint,
73-
SCOPE_APIKEY: apiKey,
74-
SCOPE_AUTO_INSTRUMENT: true,
75-
},
76-
}
77-
)
61+
return exec.exec(command, isYarn ? DEFAULT_ARGUMENTS : ['--', ...DEFAULT_ARGUMENTS], {
62+
env: {
63+
...process.env,
64+
SCOPE_API_ENDPOINT: apiEndpoint,
65+
SCOPE_APIKEY: apiKey,
66+
SCOPE_AUTO_INSTRUMENT: true,
67+
CI: true,
68+
},
69+
})
7870
}
7971

8072
run()

0 commit comments

Comments
 (0)