Skip to content

Commit b072b0e

Browse files
committed
add fix for artifact debug package.json change
1 parent ea45eae commit b072b0e

File tree

5 files changed

+77
-163
lines changed

5 files changed

+77
-163
lines changed

browserstack-report-action/dist/index.js

Lines changed: 40 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -41299,7 +41299,7 @@ async function run() {
4129941299
pollingInterval
4130041300
);
4130141301

41302-
await ReportProcessor.processReport(reportData, buildName);
41302+
await ReportProcessor.processReport(reportData);
4130341303
} catch (error) {
4130441304
core.setFailed(`Action failed: ${error.message}`);
4130541305
}
@@ -41766,10 +41766,10 @@ module.exports = new MockReportService(); // Export singleton instance
4176641766

4176741767

4176841768
const core = __nccwpck_require__(7484);
41769-
const ArtifactManager = __nccwpck_require__(197);
41769+
const UploadFileForArtifact = __nccwpck_require__(8751);
4177041770

4177141771
class ReportProcessor {
41772-
static async processReport(reportData, buildName) {
41772+
static async processReport(reportData) {
4177341773
try {
4177441774
const summary = core.summary;
4177541775
await summary.addHeading('BrowserStack Test Report');
@@ -41783,10 +41783,10 @@ class ReportProcessor {
4178341783
summary.write();
4178441784
if(reportData?.report?.rich_html) {
4178541785
const report = `<!DOCTYPE html> <html><head><style>${reportData?.report?.rich_css}</style></head> ${reportData?.report?.rich_html}</html>`;
41786-
await ArtifactManager.saveReportAsArtifact(report, buildName);
41786+
await UploadFileForArtifact.saveReportInFile(report);
4178741787
}
4178841788
} catch (error) {
41789-
await core.info(`Error processing report: ${JSON.stringify(error)}`);
41789+
core.info(`Error processing report: ${JSON.stringify(error)}`);
4179041790
await core.summary
4179141791
.addRaw('❌ Error processing report')
4179241792
.write();
@@ -41904,7 +41904,31 @@ module.exports = ReportService;
4190441904

4190541905
/***/ }),
4190641906

41907-
/***/ 197:
41907+
/***/ 933:
41908+
/***/ ((module) => {
41909+
41910+
"use strict";
41911+
41912+
41913+
class TimeoutManager {
41914+
constructor(timeoutSeconds) {
41915+
this.timeoutMs = timeoutSeconds * 1000;
41916+
this.startTime = Date.now();
41917+
}
41918+
41919+
check() {
41920+
if (Date.now() - this.startTime >= this.timeoutMs) {
41921+
throw new Error(`Operation timed out after ${this.timeoutMs / 1000} seconds`);
41922+
}
41923+
}
41924+
}
41925+
41926+
module.exports = TimeoutManager;
41927+
41928+
41929+
/***/ }),
41930+
41931+
/***/ 8751:
4190841932
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
4190941933

4191041934
"use strict";
@@ -41915,98 +41939,31 @@ const path = __nccwpck_require__(6928);
4191541939
const core = __nccwpck_require__(7484);
4191641940
const artifact = __nccwpck_require__(7884);
4191741941

41918-
class ArtifactManager {
41919-
static async saveReportAsArtifact(report, buildName) {
41942+
class UploadFileForArtifact {
41943+
static async saveReportAsArtifact(report) {
4192041944
if (!report) {
4192141945
core.debug('No HTML content available to save as artifact');
4192241946
return '';
4192341947
}
4192441948

4192541949
try {
41950+
const pathName = "browserstack-reports-atifact"
41951+
const fileName = `bstack-report.html`;
4192641952
// Create artifacts directory
41927-
const artifactDir = path.join(process.cwd(), 'browserstack-artifacts');
41928-
fs.mkdirSync("browserstack-artifacts", { recursive: true });
41929-
41930-
// Create HTML file
41931-
const fileName = `report.html`;
41932-
const filePath = path.join(artifactDir, fileName);
41953+
fs.mkdirSync(pathName, { recursive: true });
41954+
//save path in a env variable
41955+
core.exportVariable('BROWSERSTACK_REPORT_PATH', pathName);
4193341956

4193441957
// Write content
41935-
fs.writeFileSync(`browserstack-artifacts/${fileName}`, report);
41936-
const fileStat = fs.statSync(filePath);
41937-
const content = fs.readFileSync(`browserstack-artifacts/${fileName}`, 'utf8');
41938-
core.info(`Successfully read file: ${filePath} (${content.length} bytes)`);
41939-
core.exportVariable('BROWSERSTACK_REPORT_PATH', filePath);
41940-
core.setOutput('fileStat', fileStat);
41941-
core.setOutput('report_file_path', filePath);
41942-
core.setOutput('report_dir', artifactDir);
41943-
41944-
const dirContents = fs.readdirSync(artifactDir);
41945-
core.info(`Directory contents of ${artifactDir}: ${dirContents.join(', ')}`);
41946-
41947-
// Upload as artifact
41948-
let artifactClient;
41949-
if (typeof artifact.create === 'function') {
41950-
artifactClient = artifact.create();
41951-
core.info('Created artifact client using create() function');
41952-
} else if (typeof artifact.default === 'function') {
41953-
artifactClient = artifact.default();
41954-
core.info('Created artifact client using default() function');
41955-
} else if (typeof artifact === 'function') {
41956-
artifactClient = artifact();
41957-
core.info('Created artifact client using artifact as function');
41958-
} else {
41959-
// Just save the file locally and return
41960-
core.warning('Artifact API not available. Report saved locally only.');
41961-
return `File saved locally at: ${filePath}`;
41962-
}
41963-
const artifactName = `browserstack_results`;
41964-
const uploadResult = await artifactClient.uploadArtifact(
41965-
artifactName,
41966-
[filePath],
41967-
artifactDir,
41968-
{ continueOnError: true }
41969-
);
41970-
41971-
if (uploadResult.failedItems.length > 0) {
41972-
core.warning(`Failed to upload artifacts: ${uploadResult.failedItems.join(', ')}`);
41973-
return '';
41974-
}
41975-
41976-
core.info(`Report saved as artifact: ${artifactName}`);
41977-
return `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}/artifacts/${uploadResult.artifactId}`;
41958+
fs.writeFileSync(path.join(pathName,fileName), report);
4197841959
} catch (error) {
41979-
core.warning(`Failed to save artifact: ${error.message}`);
41960+
core.warning(`Failed to save file: ${error.message}`);
4198041961
return '';
4198141962
}
4198241963
}
4198341964
}
4198441965

41985-
module.exports = ArtifactManager;
41986-
41987-
41988-
/***/ }),
41989-
41990-
/***/ 933:
41991-
/***/ ((module) => {
41992-
41993-
"use strict";
41994-
41995-
41996-
class TimeoutManager {
41997-
constructor(timeoutSeconds) {
41998-
this.timeoutMs = timeoutSeconds * 1000;
41999-
this.startTime = Date.now();
42000-
}
42001-
42002-
check() {
42003-
if (Date.now() - this.startTime >= this.timeoutMs) {
42004-
throw new Error(`Operation timed out after ${this.timeoutMs / 1000} seconds`);
42005-
}
42006-
}
42007-
}
42008-
42009-
module.exports = TimeoutManager;
41966+
module.exports = UploadFileForArtifact;
4201041967

4201141968

4201241969
/***/ }),

browserstack-report-action/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function run() {
4444
pollingInterval
4545
);
4646

47-
await ReportProcessor.processReport(reportData, buildName);
47+
await ReportProcessor.processReport(reportData);
4848
} catch (error) {
4949
core.setFailed(`Action failed: ${error.message}`);
5050
}

browserstack-report-action/src/services/ReportProcessor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

33
const core = require('@actions/core');
4-
const ArtifactManager = require('../utils/ArtifactManager');
4+
const UploadFileForArtifact = require('../utils/UploadFileForArtifact');
55

66
class ReportProcessor {
7-
static async processReport(reportData, buildName) {
7+
static async processReport(reportData) {
88
try {
99
const summary = core.summary;
1010
await summary.addHeading('BrowserStack Test Report');
@@ -18,10 +18,10 @@ class ReportProcessor {
1818
summary.write();
1919
if(reportData?.report?.rich_html) {
2020
const report = `<!DOCTYPE html> <html><head><style>${reportData?.report?.rich_css}</style></head> ${reportData?.report?.rich_html}</html>`;
21-
await ArtifactManager.saveReportAsArtifact(report, buildName);
21+
await UploadFileForArtifact.saveReportInFile(report);
2222
}
2323
} catch (error) {
24-
await core.info(`Error processing report: ${JSON.stringify(error)}`);
24+
core.info(`Error processing report: ${JSON.stringify(error)}`);
2525
await core.summary
2626
.addRaw('❌ Error processing report')
2727
.write();

browserstack-report-action/src/utils/ArtifactManager.js

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const core = require('@actions/core');
6+
const artifact = require('@actions/artifact');
7+
8+
class UploadFileForArtifact {
9+
static async saveReportAsArtifact(report) {
10+
if (!report) {
11+
core.debug('No HTML content available to save as artifact');
12+
return '';
13+
}
14+
15+
try {
16+
const pathName = "browserstack-reports-atifact"
17+
const fileName = `bstack-report.html`;
18+
// Create artifacts directory
19+
fs.mkdirSync(pathName, { recursive: true });
20+
//save path in a env variable
21+
core.exportVariable('BROWSERSTACK_REPORT_PATH', pathName);
22+
23+
// Write content
24+
fs.writeFileSync(path.join(pathName,fileName), report);
25+
} catch (error) {
26+
core.warning(`Failed to save file: ${error.message}`);
27+
return '';
28+
}
29+
}
30+
}
31+
32+
module.exports = UploadFileForArtifact;

0 commit comments

Comments
 (0)