Skip to content

Commit 24ad8b8

Browse files
committed
input params change
1 parent 1191a0a commit 24ad8b8

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

browserstack-report-action/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ description: 'Fetches a BrowserStack report and displays it in the GitHub Action
33
author: 'GitHub Copilot'
44

55
inputs:
6-
browserstack-username:
6+
username:
77
description: 'Your BrowserStack username.'
88
required: true
9-
browserstack-access-key:
9+
access-key:
1010
description: 'Your BrowserStack access key.'
1111
required: true
1212
build-name:

browserstack-report-action/dist/index.js

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33563,18 +33563,18 @@ function resetPollCount() {
3356333563
*/
3356433564
async function fetchDummyReportAPI(params, auth) {
3356533565
core.info(`Fetching report with params: ${JSON.stringify(params)}`);
33566-
33566+
3356733567
// Create Authorization header
3356833568
const authHeader = Buffer.from(`${auth.username}:${auth.accessKey}`).toString('base64');
33569-
33569+
3357033570
core.info(`Simulating API call with Username: ${auth.username} and Access Key: ****`);
33571-
33571+
3357233572
return new Promise((resolve) => {
3357333573
setTimeout(() => {
3357433574
pollCount += 1;
3357533575
const build_uuid = `12345678jiji0987654321`;
3357633576
const build_integration = (pollCount % 2 === 0) ? constants.INTEGRATION_TYPE.SDK : constants.INTEGRATION_TYPE.NON_SDK;
33577-
33577+
3357833578
const response = {
3357933579
build_uuid,
3358033580
build_integration,
@@ -33601,7 +33601,7 @@ async function fetchDummyReportAPI(params, auth) {
3360133601
<p>Integration: ${build_integration}</p>
3360233602
<p>Timestamp: ${params.build_creation_timestamp}</p>
3360333603
<p>Status: All tests finished.</p>
33604-
<pre>Some test results here...</pre>`
33604+
<pre>Some test results here...</pre>`,
3360533605
};
3360633606
resolve(response);
3360733607
} else {
@@ -33614,7 +33614,7 @@ async function fetchDummyReportAPI(params, auth) {
3361433614
<p>Integration: ${build_integration}</p>
3361533615
<p>Timestamp: ${params.build_creation_timestamp}</p>
3361633616
<p>Status: Build insights and test runs data available.</p>
33617-
<pre>Detailed insights and test results...</pre>`
33617+
<pre>Detailed insights and test results...</pre>`,
3361833618
};
3361933619
resolve(response);
3362033620
}
@@ -33633,9 +33633,24 @@ async function run() {
3363333633
// Get and validate inputs
3363433634
const actionInput = new ActionInput();
3363533635
const inputs = actionInput.getInputs();
33636-
33636+
3363733637
// Destructure inputs
33638-
const { username, accessKey, buildName, userTimeout } = inputs;
33638+
const {
33639+
username, accessKey, buildName, userTimeout,
33640+
} = inputs;
33641+
const timeoutMs = userTimeout * 1000;
33642+
const startTime = Date.now();
33643+
let timeoutReached = false;
33644+
33645+
// Set up timeout tracking
33646+
const checkTimeout = () => {
33647+
const elapsedMs = Date.now() - startTime;
33648+
if (elapsedMs >= timeoutMs) {
33649+
timeoutReached = true;
33650+
return true;
33651+
}
33652+
return false;
33653+
};
3363933654

3364033655
const buildCreationTimestamp = new Date().toISOString();
3364133656
const reportFormat = constants.REPORT_FORMAT.BASIC_HTML;
@@ -33659,15 +33674,15 @@ async function run() {
3365933674
build_creation_timestamp: buildCreationTimestamp,
3366033675
report_format: reportFormat,
3366133676
requesting_ci: requestingCI,
33662-
request_type: 'first',
33677+
request_type: 'FIRST',
3366333678
user_timeout: userTimeout,
3366433679
};
33665-
33680+
3366633681
const auth = {
3366733682
username,
33668-
accessKey
33683+
accessKey,
3366933684
};
33670-
33685+
3367133686
reportData = await fetchDummyReportAPI(initialApiParams, auth);
3367233687
reportStatus = reportData.report_status;
3367333688
pollingIntervalSeconds = reportData.polling_interval || constants.DEFAULT_POLLING_INTERVAL_SECONDS;
@@ -33682,11 +33697,11 @@ async function run() {
3368233697
core.info(`Polling attempt #${retries + 1} (overall attempt ${pollCount})`);
3368333698
const apiParams = {
3368433699
build_name: buildName,
33685-
build_creation_timestamp: buildCreationTimestamp,
33700+
build_created_at: buildCreationTimestamp,
3368633701
report_format: reportFormat,
3368733702
requesting_ci: requestingCI,
3368833703
user_timeout: userTimeout,
33689-
request_type: retries === maxRetries ? 'last' : 'polling',
33704+
request_type: retries === maxRetries ? 'LAST' : 'POLL',
3369033705
};
3369133706
reportData = await fetchDummyReportAPI(apiParams, auth);
3369233707
reportStatus = reportData.report_status;
@@ -33702,27 +33717,32 @@ async function run() {
3370233717
await core.summary.write();
3370333718
return;
3370433719
}
33705-
33706-
core.setFailed('Report status is complete/tests_available, but HTML report content is missing.');
33720+
33721+
core.setFailed('Report status is completed, but HTML report content is missing.');
3370733722
return;
33708-
} else if (reportStatus === constants.REPORT_STATUS.IN_PROGRESS) {
33723+
} if (reportStatus === constants.REPORT_STATUS.IN_PROGRESS) {
3370933724
if (retries < maxRetries) {
3371033725
core.info(`Report is still in progress. Retrying in ${pollingIntervalSeconds} seconds...`);
33711-
await new Promise(resolve => setTimeout(resolve, pollingIntervalSeconds * 10)); // Use 10ms for faster tests
33726+
await new Promise((resolve) => setTimeout(resolve, pollingIntervalSeconds * 10)); // Use 10ms for faster tests
3371233727
} else {
33713-
core.setFailed(`Polling timed out after ${maxRetries} retries. Last status: ${reportStatus}`);
33728+
core.setFailed(`Report Fetching timed out after ${maxRetries} retries. Last status: ${reportStatus}`);
3371433729
return;
3371533730
}
3371633731
} else { // "not_available", "build_not_found", "more_than_one_build_found"
33717-
core.setFailed(`Report generation failed with status: ${reportStatus}. Build UUID: ${reportData.build_uuid || 'N/A'}`);
33732+
if (reportData.report && reportData.report.basic_html) {
33733+
core.summary.addRaw(reportData.report.basic_html);
33734+
await core.summary.write();
33735+
return;
33736+
}
33737+
core.setFailed('Report not found');
3371833738
return;
3371933739
}
3372033740
retries += 1;
3372133741
}
33722-
33742+
3372333743
// If loop finishes without returning, it means maxRetries was hit with last status being in_progress
3372433744
if (reportStatus === constants.REPORT_STATUS.IN_PROGRESS) {
33725-
core.setFailed(`Polling timed out after ${maxRetries} retries. Final status was '${constants.REPORT_STATUS.IN_PROGRESS}'.`);
33745+
core.setFailed(`Report Fetching timed out after ${maxRetries} retries. Final status was '${constants.REPORT_STATUS.IN_PROGRESS}'.`);
3372633746
}
3372733747
} catch (error) {
3372833748
core.setFailed(`Action failed with error: ${error.message}`);

0 commit comments

Comments
 (0)