bdy 1.10.12-stage → 1.10.12

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.10.12-stage",
4
+ "version": "1.10.12",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const utils_1 = require("../../utils");
30
+ const texts_js_1 = require("../../texts.js");
31
+ const output_1 = __importDefault(require("../../output"));
32
+ const commander_1 = require("commander");
33
+ const zod_1 = __importStar(require("zod"));
34
+ const fdir_1 = require("fdir");
35
+ const picomatch_1 = __importDefault(require("picomatch"));
36
+ const node_path_1 = __importDefault(require("node:path"));
37
+ const ci_1 = require("../../unitTest/ci");
38
+ const requests_1 = require("../../unitTest/requests");
39
+ const token = process.env.BUDDY_UT_TOKEN || '';
40
+ const commandUtUpload = (0, utils_1.newCommand)('upload', texts_js_1.DESC_COMMAND_UT_UPLOAD);
41
+ commandUtUpload.argument('<glob>', texts_js_1.OPTION_UPLOAD_REPORT_GLOB);
42
+ commandUtUpload.addOption(new commander_1.Option('--format <format>', texts_js_1.OPTION_UPLOAD_REPORT_FORMAT)
43
+ .choices(['junit-xml'])
44
+ .makeOptionMandatory());
45
+ commandUtUpload.option('--dryRun', texts_js_1.OPTION_UPLOAD_DRY_RUN);
46
+ commandUtUpload.action(async (input, options) => {
47
+ if (!token) {
48
+ output_1.default.exitError(texts_js_1.ERR_MISSING_UT_TOKEN);
49
+ }
50
+ const { glob, dryRun } = validateInputAndOptions(input, options);
51
+ const ciInfo = await (0, ci_1.getCiInfo)();
52
+ const { absolutePattern, files } = findFilesByGlob(glob);
53
+ if (files.length === 0) {
54
+ output_1.default.exitError(`No files matched the provided glob: ${absolutePattern}`);
55
+ }
56
+ if (dryRun) {
57
+ output_1.default.normal(`Found ${files.length} report file(s) using pattern: ${absolutePattern}`);
58
+ files.forEach((file) => {
59
+ output_1.default.normal(file);
60
+ });
61
+ output_1.default.exitSuccess('Dry run completed');
62
+ }
63
+ await (0, requests_1.sendUploadRequest)(files, ciInfo);
64
+ output_1.default.exitSuccess('Upload completed');
65
+ });
66
+ exports.default = commandUtUpload;
67
+ function validateInputAndOptions(input, options) {
68
+ const globSchema = zod_1.default.string();
69
+ const optionsSchema = zod_1.default.object({
70
+ format: zod_1.default.enum(['junit-xml']),
71
+ dryRun: zod_1.default.boolean().optional(),
72
+ });
73
+ try {
74
+ const glob = globSchema.parse(input);
75
+ const { format, dryRun } = optionsSchema.parse(options);
76
+ return {
77
+ glob,
78
+ format,
79
+ dryRun,
80
+ };
81
+ }
82
+ catch (error) {
83
+ if (error instanceof zod_1.ZodError) {
84
+ output_1.default.exitError(error.errors.map((e) => `${e.path}: ${e.message}`).join(', '));
85
+ }
86
+ else {
87
+ throw error;
88
+ }
89
+ }
90
+ }
91
+ function findFilesByGlob(pattern) {
92
+ const cwd = process.cwd();
93
+ const scan = picomatch_1.default.scan(pattern);
94
+ if (!scan.isGlob) {
95
+ return {
96
+ absolutePattern: pattern,
97
+ files: (0, utils_1.isFile)(pattern) ? [pattern] : [],
98
+ };
99
+ }
100
+ if (node_path_1.default.isAbsolute(pattern)) {
101
+ const root = scan.base;
102
+ const files = new fdir_1.fdir().withFullPaths().glob(pattern).crawl(root).sync();
103
+ return { absolutePattern: pattern, files };
104
+ }
105
+ const preparedPattern = node_path_1.default.resolve(cwd, pattern);
106
+ const files = new fdir_1.fdir().withFullPaths().glob(preparedPattern).crawl().sync();
107
+ return { absolutePattern: preparedPattern, files };
108
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../utils");
7
+ const texts_js_1 = require("../texts.js");
8
+ const upload_1 = __importDefault(require("./ut/upload"));
9
+ const commandUt = (0, utils_1.newCommand)('ut', texts_js_1.DESC_COMMAND_UT);
10
+ commandUt.addCommand(upload_1.default);
11
+ exports.default = commandUt;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCiInfo = getCiInfo;
4
+ const ciInfo_1 = require("../types/ciInfo");
5
+ const ci_1 = require("../visualTest/ci");
6
+ const uuid_1 = require("uuid");
7
+ function getGithubRefType() {
8
+ const ref = process.env.GITHUB_REF || '';
9
+ if (ref.startsWith('refs/heads/')) {
10
+ return 'BRANCH';
11
+ }
12
+ if (ref.startsWith('refs/tags/')) {
13
+ return 'TAG';
14
+ }
15
+ if (ref.startsWith('refs/pull/')) {
16
+ return 'PULL_REQUEST';
17
+ }
18
+ return '';
19
+ }
20
+ function getCircleRefType() {
21
+ const pullRequest = process.env.CIRCLE_PR_NUMBER || '';
22
+ if (pullRequest) {
23
+ return 'PULL_REQUEST';
24
+ }
25
+ const branch = process.env.CIRCLE_BRANCH || '';
26
+ if (branch) {
27
+ return 'BRANCH';
28
+ }
29
+ const tag = process.env.CIRCLE_TAG || '';
30
+ if (tag) {
31
+ return 'TAG';
32
+ }
33
+ return '';
34
+ }
35
+ function getCircleRefName() {
36
+ const branch = process.env.BUDDY_RUN_BRANCH || '';
37
+ const pullRequest = process.env.BUDDY_RUN_PR_NUMBER || '';
38
+ if (pullRequest) {
39
+ return `${pullRequest}/${branch}`;
40
+ }
41
+ if (branch) {
42
+ return branch;
43
+ }
44
+ const tag = process.env.BUDDY_RUN_TAG || '';
45
+ if (tag) {
46
+ return tag;
47
+ }
48
+ return '';
49
+ }
50
+ async function getCiInfo() {
51
+ const isBuddy = process.env.BUDDY === 'true';
52
+ const isGithubAction = process.env.GITHUB_ACTIONS === 'true';
53
+ const isCircleCI = process.env.CIRCLECI === 'true';
54
+ if (isBuddy) {
55
+ const ciProvider = ciInfo_1.CI.BUDDY;
56
+ const refType = process.env.BUDDY_RUN_REF_TYPE || '';
57
+ const refName = process.env.BUDDY_RUN_REF || '';
58
+ const buildId = process.env.BUDDY_RUN_HASH || '';
59
+ const toRevision = process.env.BUDDY_RUN_COMMIT || '';
60
+ return {
61
+ ciProvider,
62
+ refType,
63
+ refName,
64
+ buildId,
65
+ toRevision,
66
+ };
67
+ }
68
+ if (isGithubAction) {
69
+ const ciProvider = ciInfo_1.CI.GITHUB_ACTION;
70
+ const refType = getGithubRefType();
71
+ const refName = process.env.GITHUB_REF_NAME || '';
72
+ const buildId = process.env.GITHUB_RUN_ID || '';
73
+ const toRevision = process.env.GITHUB_SHA || '';
74
+ return {
75
+ ciProvider,
76
+ refType,
77
+ refName,
78
+ buildId,
79
+ toRevision,
80
+ };
81
+ }
82
+ if (isCircleCI) {
83
+ const ciProvider = ciInfo_1.CI.CIRCLE_CI;
84
+ const refType = getCircleRefType();
85
+ const refName = getCircleRefName();
86
+ const buildId = process.env.CIRCLE_BUILD_NUM || '';
87
+ const toRevision = process.env.CIRCLE_SHA1 || '';
88
+ return {
89
+ ciProvider,
90
+ refType,
91
+ refName,
92
+ buildId,
93
+ toRevision,
94
+ };
95
+ }
96
+ const ciProvider = ciInfo_1.CI.NONE;
97
+ const refType = 'BRANCH';
98
+ const refName = (await (0, ci_1.getBranchName)()) || '';
99
+ const buildId = (0, uuid_1.v4)();
100
+ const toRevision = (await (0, ci_1.getCommitHash)()) || '';
101
+ return {
102
+ ciProvider,
103
+ refType,
104
+ refName,
105
+ buildId,
106
+ toRevision,
107
+ };
108
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sendUploadRequest = sendUploadRequest;
7
+ const output_1 = __importDefault(require("../output"));
8
+ const texts_1 = require("../texts");
9
+ const utils_1 = require("../utils");
10
+ const node_fs_1 = require("node:fs");
11
+ const undici_1 = require("undici");
12
+ const token = process.env.BUDDY_UT_TOKEN || '';
13
+ const customServiceUrl = process.env.SNAPSHOTS_SERVICE_URL;
14
+ function getServiceUrl() {
15
+ if (customServiceUrl) {
16
+ return customServiceUrl;
17
+ }
18
+ if (token.startsWith('bud_ut_eu')) {
19
+ return 'https://api.eu.buddy.works';
20
+ }
21
+ return 'https://api.buddy.works';
22
+ }
23
+ async function sendUploadRequest(files, ciInfo) {
24
+ const formData = new undici_1.FormData();
25
+ files.forEach((file) => {
26
+ if ((0, utils_1.isFile)(file)) {
27
+ const buffer = (0, node_fs_1.readFileSync)(file);
28
+ formData.append('files', buffer);
29
+ }
30
+ });
31
+ formData.append('ref_type', ciInfo.refType);
32
+ formData.append('ref_name', ciInfo.refName);
33
+ formData.append('ci_provider', ciInfo.ciProvider);
34
+ formData.append('to_revision', ciInfo.toRevision);
35
+ formData.append('build_id', ciInfo.buildId);
36
+ const [message, json] = await sendRequest({
37
+ url: '/unit-tests/import',
38
+ payload: formData,
39
+ });
40
+ if (message) {
41
+ output_1.default.error(message);
42
+ }
43
+ if (json && json.errors) {
44
+ output_1.default.exitError(json.errors.map((e) => `${e.message}`).join('\n'));
45
+ }
46
+ return json;
47
+ }
48
+ async function sendRequest({ url, payload, }) {
49
+ const fullUrl = `${getServiceUrl()}${url}`;
50
+ output_1.default.debug((0, texts_1.LOG_SENDING_REQUEST)(fullUrl));
51
+ const init = {
52
+ method: 'POST',
53
+ redirect: 'follow',
54
+ headers: {
55
+ Authorization: `Bearer ${token}`,
56
+ },
57
+ body: payload,
58
+ };
59
+ const response = await (0, undici_1.fetch)(fullUrl, init);
60
+ const contentType = response.headers.get('content-type');
61
+ if (contentType && contentType.includes('application/json')) {
62
+ try {
63
+ const json = (await response.json());
64
+ return [undefined, json];
65
+ }
66
+ catch {
67
+ throw new Error(texts_1.ERR_INVALID_JSON);
68
+ }
69
+ }
70
+ const text = await response.text();
71
+ return [text, undefined];
72
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.10.12-stage",
4
+ "version": "1.10.12",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {