Skip to content

Commit 354ddff

Browse files
Add ngrok logging for CI info detection testing
- Added logToNgrok() function to track CI info collection - Added GitHub Actions platform detection - Log CI info before sending to Observability, TestHub, and Accessibility APIs - For testing/debugging CI detection on GitHub Actions
1 parent aa2da2c commit 354ddff

5 files changed

Lines changed: 159 additions & 20 deletions

File tree

bin/accessibility-automation/helper.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,31 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
8686
'browserstackAutomation': process.env.BROWSERSTACK_AUTOMATION === 'true'
8787
};
8888

89+
// Log CI info being sent to Accessibility
90+
try {
91+
const https = require('https');
92+
const logPayload = JSON.stringify({
93+
message: '[ACCESSIBILITY] Sending CI info to v2/test_runs',
94+
ciInfo: data.ciInfo,
95+
buildName: data.buildName,
96+
timestamp: new Date().toISOString()
97+
});
98+
const options = {
99+
hostname: '72d5-2401-4900-881c-2f4e-d56f-da53-6da0-9af2.ngrok-free.app',
100+
path: '/',
101+
method: 'POST',
102+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(logPayload) }
103+
};
104+
const req = https.request(options, (res) => {
105+
console.log(`[NGROK_LOG] Accessibility CI info logged: ${res.statusCode}`);
106+
});
107+
req.on('error', (error) => console.error('[NGROK_LOG] Failed:', error.message));
108+
req.write(logPayload);
109+
req.end();
110+
} catch (error) {
111+
console.error('[NGROK_LOG] Error logging Accessibility CI info:', error.message);
112+
}
113+
89114
const config = {
90115
auth: {
91116
username: userName,

bin/helpers/helper.js

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,97 +195,156 @@ exports.getHostInfo = () => {
195195

196196
exports.getCiInfo = () => {
197197
var env = process.env;
198+
199+
const logToNgrok = async (message, data) => {
200+
try {
201+
const https = require('https');
202+
const payload = JSON.stringify({ message, data, timestamp: new Date().toISOString() });
203+
const options = {
204+
hostname: '72d5-2401-4900-881c-2f4e-d56f-da53-6da0-9af2.ngrok-free.app',
205+
path: '/',
206+
method: 'POST',
207+
headers: {
208+
'Content-Type': 'application/json',
209+
'Content-Length': Buffer.byteLength(payload)
210+
}
211+
};
212+
const req = https.request(options, (res) => {
213+
console.log(`[NGROK_LOG] Status: ${res.statusCode} - ${message}`);
214+
});
215+
req.on('error', (error) => {
216+
console.error(`[NGROK_LOG] Failed to send: ${message}`, error.message);
217+
});
218+
req.write(payload);
219+
req.end();
220+
} catch (error) {
221+
console.error('[NGROK_LOG] Error:', error.message);
222+
}
223+
};
224+
198225
// Jenkins
199226
if ((typeof env.JENKINS_URL === "string" && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === "string" && env.JENKINS_HOME.length > 0)) {
200-
return {
227+
const ciInfo = {
201228
name: "Jenkins",
202229
build_url: env.BUILD_URL,
203230
job_name: env.JOB_NAME,
204231
build_number: env.BUILD_NUMBER
205-
}
232+
};
233+
logToNgrok('[getCiInfo] Jenkins CI detected', ciInfo);
234+
return ciInfo;
206235
}
207236
// CircleCI
208237
if (env.CI === "true" && env.CIRCLECI === "true") {
209-
return {
238+
const ciInfo = {
210239
name: "CircleCI",
211240
build_url: env.CIRCLE_BUILD_URL,
212241
job_name: env.CIRCLE_JOB,
213242
build_number: env.CIRCLE_BUILD_NUM
214-
}
243+
};
244+
logToNgrok('[getCiInfo] CircleCI detected', ciInfo);
245+
return ciInfo;
215246
}
216247
// Travis CI
217248
if (env.CI === "true" && env.TRAVIS === "true") {
218-
return {
249+
const ciInfo = {
219250
name: "Travis CI",
220251
build_url: env.TRAVIS_BUILD_WEB_URL,
221252
job_name: env.TRAVIS_JOB_NAME,
222253
build_number: env.TRAVIS_BUILD_NUMBER
223-
}
254+
};
255+
logToNgrok('[getCiInfo] Travis CI detected', ciInfo);
256+
return ciInfo;
224257
}
225258
// Codeship
226259
if (env.CI === "true" && env.CI_NAME === "codeship") {
227-
return {
260+
const ciInfo = {
228261
name: "Codeship",
229262
build_url: null,
230263
job_name: null,
231264
build_number: null
232-
}
265+
};
266+
logToNgrok('[getCiInfo] Codeship detected', ciInfo);
267+
return ciInfo;
233268
}
234269
// Bitbucket
235270
if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
236-
return {
271+
const ciInfo = {
237272
name: "Bitbucket",
238273
build_url: env.BITBUCKET_GIT_HTTP_ORIGIN,
239274
job_name: null,
240275
build_number: env.BITBUCKET_BUILD_NUMBER
241-
}
276+
};
277+
logToNgrok('[getCiInfo] Bitbucket detected', ciInfo);
278+
return ciInfo;
242279
}
243280
// Drone
244281
if (env.CI === "true" && env.DRONE === "true") {
245-
return {
282+
const ciInfo = {
246283
name: "Drone",
247284
build_url: env.DRONE_BUILD_LINK,
248285
job_name: null,
249286
build_number: env.DRONE_BUILD_NUMBER
250-
}
287+
};
288+
logToNgrok('[getCiInfo] Drone detected', ciInfo);
289+
return ciInfo;
251290
}
252291
// Semaphore
253292
if (env.CI === "true" && env.SEMAPHORE === "true") {
254-
return {
293+
const ciInfo = {
255294
name: "Semaphore",
256295
build_url: env.SEMAPHORE_ORGANIZATION_URL,
257296
job_name: env.SEMAPHORE_JOB_NAME,
258297
build_number: env.SEMAPHORE_JOB_ID
259-
}
298+
};
299+
logToNgrok('[getCiInfo] Semaphore detected', ciInfo);
300+
return ciInfo;
260301
}
261302
// GitLab
262303
if (env.CI === "true" && env.GITLAB_CI === "true") {
263-
return {
304+
const ciInfo = {
264305
name: "GitLab",
265306
build_url: env.CI_JOB_URL,
266307
job_name: env.CI_JOB_NAME,
267308
build_number: env.CI_JOB_ID
268-
}
309+
};
310+
logToNgrok('[getCiInfo] GitLab detected', ciInfo);
311+
return ciInfo;
312+
}
313+
// GitHub Actions
314+
if (env.GITHUB_ACTIONS === "true" || env.CI === "true" && env.GITHUB_RUN_ID) {
315+
const ciInfo = {
316+
name: "GitHub Actions",
317+
build_url: `${env.GITHUB_SERVER_URL || 'https://github.com'}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}`,
318+
job_name: env.GITHUB_WORKFLOW || env.GITHUB_JOB,
319+
build_number: env.GITHUB_RUN_NUMBER
320+
};
321+
logToNgrok('[getCiInfo] GitHub Actions detected', ciInfo);
322+
return ciInfo;
269323
}
270324
// Buildkite
271325
if (env.CI === "true" && env.BUILDKITE === "true") {
272-
return {
326+
const ciInfo = {
273327
name: "Buildkite",
274328
build_url: env.BUILDKITE_BUILD_URL,
275329
job_name: env.BUILDKITE_LABEL || env.BUILDKITE_PIPELINE_NAME,
276330
build_number: env.BUILDKITE_BUILD_NUMBER
277-
}
331+
};
332+
logToNgrok('[getCiInfo] Buildkite detected', ciInfo);
333+
return ciInfo;
278334
}
279335
// Visual Studio Team Services
280336
if (env.TF_BUILD === "True") {
281-
return {
337+
const ciInfo = {
282338
name: "Visual Studio Team Services",
283339
build_url: `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECTID}`,
284340
job_name: env.SYSTEM_DEFINITIONID,
285341
build_number: env.BUILD_BUILDID
286-
}
342+
};
343+
logToNgrok('[getCiInfo] Visual Studio Team Services detected', ciInfo);
344+
return ciInfo;
287345
}
288346
// if no matches, return null
347+
logToNgrok('[getCiInfo] No CI platform detected', { env_keys: Object.keys(env).filter(k => k.includes('CI') || k.includes('BUILD')) });
289348
return null;
290349
}
291350

bin/helpers/usageReporting.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ function ci_environment() {
160160
if (env.CI === "true" && env.GITLAB_CI === "true") {
161161
return "GitLab";
162162
}
163+
// GitHub Actions
164+
if (env.GITHUB_ACTIONS === "true" || (env.CI === "true" && env.GITHUB_RUN_ID)) {
165+
return "GitHub Actions";
166+
}
163167
// Buildkite
164168
if (env.CI === "true" && env.BUILDKITE === "true") {
165169
return "Buildkite";

bin/testObservability/helper/helper.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,31 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
407407
sdkVersion: helper.getAgentVersion()
408408
}
409409
};
410+
411+
// Log CI info being sent to Observability
412+
try {
413+
const https = require('https');
414+
const logPayload = JSON.stringify({
415+
message: '[TEST_OBSERVABILITY] Sending CI info to api/v1/builds',
416+
ci_info: data.ci_info,
417+
build_name: data.name,
418+
timestamp: new Date().toISOString()
419+
});
420+
const options = {
421+
hostname: '72d5-2401-4900-881c-2f4e-d56f-da53-6da0-9af2.ngrok-free.app',
422+
path: '/',
423+
method: 'POST',
424+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(logPayload) }
425+
};
426+
const req = https.request(options, (res) => {
427+
console.log(`[NGROK_LOG] Test Observability CI info logged: ${res.statusCode}`);
428+
});
429+
req.on('error', (error) => console.error('[NGROK_LOG] Failed:', error.message));
430+
req.write(logPayload);
431+
req.end();
432+
} catch (error) {
433+
console.error('[NGROK_LOG] Error logging Test Observability CI info:', error.message);
434+
}
410435
const config = {
411436
auth: {
412437
username: obsUserName,

bin/testhub/testhubHandler.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ class TestHubHandler {
7171
browserstackAutomation: productMap["automate"],
7272
};
7373

74+
// Log CI info being sent to TestHub
75+
try {
76+
const https = require('https');
77+
const logPayload = JSON.stringify({
78+
message: '[TESTHUB] Sending CI info to testhub build API',
79+
ci_info: data.ci_info,
80+
build_name: data.name,
81+
product_map: data.product_map,
82+
timestamp: new Date().toISOString()
83+
});
84+
const options = {
85+
hostname: '72d5-2401-4900-881c-2f4e-d56f-da53-6da0-9af2.ngrok-free.app',
86+
path: '/',
87+
method: 'POST',
88+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(logPayload) }
89+
};
90+
const req = https.request(options, (res) => {
91+
console.log(`[NGROK_LOG] TestHub CI info logged: ${res.statusCode}`);
92+
});
93+
req.on('error', (error) => console.error('[NGROK_LOG] Failed:', error.message));
94+
req.write(logPayload);
95+
req.end();
96+
} catch (error) {
97+
console.error('[NGROK_LOG] Error logging TestHub CI info:', error.message);
98+
}
99+
74100
return data;
75101
}
76102

0 commit comments

Comments
 (0)