playwright-slack-report-burak 3.0.15 → 3.0.17
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.
- package/dist/src/SlackReporter.js +86 -15
- package/package.json +1 -1
|
@@ -46,9 +46,11 @@ class SlackReporter {
|
|
|
46
46
|
suite;
|
|
47
47
|
separateFlaky = false;
|
|
48
48
|
logs = [];
|
|
49
|
+
fullConfig;
|
|
49
50
|
onBegin(fullConfig, suite) {
|
|
50
51
|
// Log package version
|
|
51
52
|
console.log(`📦 [SlackReporter] playwright-slack-report-burak v${packageVersion}`);
|
|
53
|
+
this.fullConfig = fullConfig;
|
|
52
54
|
this.suite = suite;
|
|
53
55
|
this.logs = [];
|
|
54
56
|
const slackReporterConfig = fullConfig.reporter.filter((f) => f[0].toLowerCase().includes('slackreporter'))[0][1];
|
|
@@ -323,38 +325,100 @@ class SlackReporter {
|
|
|
323
325
|
|
|
324
326
|
this.log('🔍 [Shard Detection] Starting shard detection logic...');
|
|
325
327
|
|
|
328
|
+
// Check if we're actually running in GitHub Actions (not just env vars set locally)
|
|
329
|
+
const isActuallyInGitHubActions = process.env.GITHUB_ACTIONS === 'true' &&
|
|
330
|
+
process.env.GITHUB_RUN_ID !== undefined &&
|
|
331
|
+
process.env.GITHUB_RUNNER_NAME !== undefined;
|
|
332
|
+
|
|
326
333
|
// Log all relevant environment variables
|
|
327
334
|
this.log(`🔍 [Shard Detection] Environment variables:`);
|
|
328
335
|
this.log(`🔍 CI: ${process.env.CI !== undefined ? `"${process.env.CI}"` : 'undefined'}`);
|
|
329
336
|
this.log(`🔍 GITHUB_ACTIONS: ${process.env.GITHUB_ACTIONS !== undefined ? `"${process.env.GITHUB_ACTIONS}"` : 'undefined'}`);
|
|
330
337
|
this.log(`🔍 GITHUB_JOB: ${process.env.GITHUB_JOB !== undefined ? `"${process.env.GITHUB_JOB}"` : 'undefined'}`);
|
|
338
|
+
this.log(`🔍 GITHUB_RUN_ID: ${process.env.GITHUB_RUN_ID !== undefined ? `"${process.env.GITHUB_RUN_ID}"` : 'undefined'}`);
|
|
339
|
+
this.log(`🔍 GITHUB_RUNNER_NAME: ${process.env.GITHUB_RUNNER_NAME !== undefined ? `"${process.env.GITHUB_RUNNER_NAME}"` : 'undefined'}`);
|
|
331
340
|
this.log(`🔍 MATRIX_SHARD: ${process.env.MATRIX_SHARD !== undefined ? `"${process.env.MATRIX_SHARD}"` : 'undefined'}`);
|
|
332
341
|
this.log(`🔍 MATRIX_INDEX: ${process.env.MATRIX_INDEX !== undefined ? `"${process.env.MATRIX_INDEX}"` : 'undefined'}`);
|
|
333
342
|
this.log(`🔍 MATRIX_COUNT: ${process.env.MATRIX_COUNT !== undefined ? `"${process.env.MATRIX_COUNT}"` : 'undefined'}`);
|
|
334
343
|
|
|
335
|
-
//
|
|
344
|
+
// Check for Playwright shard environment variables (Playwright may set these)
|
|
345
|
+
this.log(`🔍 PLAYWRIGHT_SHARD: ${process.env.PLAYWRIGHT_SHARD !== undefined ? `"${process.env.PLAYWRIGHT_SHARD}"` : 'undefined'}`);
|
|
346
|
+
|
|
347
|
+
// Check Playwright's shard config (highest priority for local runs)
|
|
348
|
+
let playwrightShardInfo = null;
|
|
349
|
+
if (this.fullConfig) {
|
|
350
|
+
// Debug: log config structure
|
|
351
|
+
this.log(`🔍 [Shard Detection] Checking Playwright config for shard info...`);
|
|
352
|
+
this.log(`🔍 fullConfig.shard: ${this.fullConfig.shard ? JSON.stringify(this.fullConfig.shard) : 'undefined'}`);
|
|
353
|
+
|
|
354
|
+
if (this.fullConfig.shard) {
|
|
355
|
+
// Playwright shard can be either { current, total } or undefined
|
|
356
|
+
if (this.fullConfig.shard.current !== undefined && this.fullConfig.shard.total !== undefined) {
|
|
357
|
+
playwrightShardInfo = {
|
|
358
|
+
current: this.fullConfig.shard.current,
|
|
359
|
+
total: this.fullConfig.shard.total
|
|
360
|
+
};
|
|
361
|
+
this.log(`🔍 [Shard Detection] Found Playwright shard config: ${playwrightShardInfo.current}/${playwrightShardInfo.total}`);
|
|
362
|
+
} else {
|
|
363
|
+
this.log(`🔍 [Shard Detection] Playwright shard config exists but missing current/total properties`);
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
this.log(`🔍 [Shard Detection] No Playwright shard config found in fullConfig`);
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
this.log(`🔍 [Shard Detection] fullConfig not available`);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Also check if shard info is in process.argv (command line)
|
|
373
|
+
// This is a fallback if config doesn't have it but --shard was passed
|
|
374
|
+
if (!playwrightShardInfo && process.argv) {
|
|
375
|
+
const shardArg = process.argv.find(arg => arg && arg.includes('--shard'));
|
|
376
|
+
if (shardArg) {
|
|
377
|
+
const shardMatch = shardArg.match(/--shard[=:]?(\d+)\/(\d+)/);
|
|
378
|
+
if (shardMatch) {
|
|
379
|
+
playwrightShardInfo = {
|
|
380
|
+
current: parseInt(shardMatch[1], 10),
|
|
381
|
+
total: parseInt(shardMatch[2], 10)
|
|
382
|
+
};
|
|
383
|
+
this.log(`🔍 [Shard Detection] Found shard in command line args: ${playwrightShardInfo.current}/${playwrightShardInfo.total}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Step 1: Try GitHub Actions API detection (only if actually in GitHub Actions)
|
|
336
389
|
let githubApiShardInfo = null;
|
|
337
|
-
if (
|
|
338
|
-
this.log(`🔍 [Shard Detection]
|
|
390
|
+
if (isActuallyInGitHubActions) {
|
|
391
|
+
this.log(`🔍 [Shard Detection] Actually running in GitHub Actions - attempting API detection...`);
|
|
339
392
|
githubApiShardInfo = await this.detectGitHubActionsShardInfo();
|
|
393
|
+
} else if (process.env.GITHUB_ACTIONS === 'true') {
|
|
394
|
+
this.log(`🔍 [Shard Detection] GitHub Actions env vars set but not actually in runner - skipping API detection`);
|
|
340
395
|
}
|
|
341
396
|
|
|
342
|
-
// Step 2: Detect shard index
|
|
343
|
-
let currentShardIndex
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
if (
|
|
397
|
+
// Step 2: Detect shard index (priority order: Playwright config > env vars > GitHub API)
|
|
398
|
+
let currentShardIndex;
|
|
399
|
+
if (playwrightShardInfo) {
|
|
400
|
+
// Playwright uses 1-based indexing, convert to 0-based
|
|
401
|
+
currentShardIndex = (playwrightShardInfo.current - 1).toString();
|
|
402
|
+
this.log(`🔍 [Shard Detection] Using Playwright shard config (converted to 0-based): "${currentShardIndex}"`);
|
|
403
|
+
} else if (process.env.MATRIX_SHARD !== undefined) {
|
|
404
|
+
currentShardIndex = process.env.MATRIX_SHARD;
|
|
405
|
+
this.log(`🔍 [Shard Detection] Using MATRIX_SHARD env var: "${currentShardIndex}"`);
|
|
406
|
+
} else if (process.env.MATRIX_INDEX !== undefined) {
|
|
407
|
+
currentShardIndex = process.env.MATRIX_INDEX;
|
|
408
|
+
this.log(`🔍 [Shard Detection] Using MATRIX_INDEX env var: "${currentShardIndex}"`);
|
|
409
|
+
} else if (githubApiShardInfo) {
|
|
349
410
|
currentShardIndex = githubApiShardInfo.shardIndex.toString();
|
|
350
411
|
this.log(`🔍 [Shard Detection] Using GitHub API detected shardIndex: "${currentShardIndex}"`);
|
|
351
412
|
}
|
|
352
413
|
|
|
353
414
|
this.log(`🔍 [Shard Detection] Initial currentShardIndex: ${currentShardIndex !== undefined ? `"${currentShardIndex}"` : 'undefined'}`);
|
|
354
415
|
|
|
355
|
-
// Step
|
|
416
|
+
// Step 3: Get shard count from multiple sources (priority order)
|
|
356
417
|
let totalShards;
|
|
357
|
-
if (
|
|
418
|
+
if (playwrightShardInfo) {
|
|
419
|
+
totalShards = playwrightShardInfo.total;
|
|
420
|
+
this.log(`🔍 [Shard Detection] Using Playwright shard config totalShards: ${totalShards}`);
|
|
421
|
+
} else if (process.env.MATRIX_COUNT !== undefined) {
|
|
358
422
|
totalShards = parseInt(process.env.MATRIX_COUNT, 10);
|
|
359
423
|
this.log(`🔍 [Shard Detection] Using MATRIX_COUNT env var: ${totalShards}`);
|
|
360
424
|
} else if (githubApiShardInfo && githubApiShardInfo.totalShards > 1) {
|
|
@@ -390,7 +454,8 @@ class SlackReporter {
|
|
|
390
454
|
|
|
391
455
|
// CRITICAL: In CI (especially GitHub Actions), if we can't detect shard info, block posting
|
|
392
456
|
// This prevents duplicate messages when running with multiple shards
|
|
393
|
-
if (
|
|
457
|
+
// BUT: Don't block if we're running locally (even if CI env vars are set)
|
|
458
|
+
if (isActuallyInGitHubActions && currentShardIndex === undefined) {
|
|
394
459
|
if (process.env.GITHUB_ACTIONS === 'true') {
|
|
395
460
|
this.log(`❌ [Shard Detection] BLOCKING: GitHub Actions detected but shard index cannot be determined.`);
|
|
396
461
|
this.log(`❌ Attempted: GitHub API detection ${githubApiShardInfo ? 'succeeded' : 'failed'}, env vars not set`);
|
|
@@ -421,11 +486,17 @@ class SlackReporter {
|
|
|
421
486
|
// This ensures ResultsParser always has correct values, even if we block posting
|
|
422
487
|
this.resultsParser.updateShardInfo(shardIndexNum, totalShards);
|
|
423
488
|
|
|
489
|
+
// For local runs with CI env vars set but not actually in CI, allow posting if single shard
|
|
490
|
+
// or if shard index is 0
|
|
491
|
+
if (!isActuallyInGitHubActions && process.env.CI && totalShards > 1 && currentShardIndex === undefined) {
|
|
492
|
+
this.log(`⚠️ [Shard Detection] Local run with CI env vars but shard info unclear - allowing post (may cause duplicates)`);
|
|
493
|
+
}
|
|
494
|
+
|
|
424
495
|
// CRITICAL: For GitHub Actions with multiple shards, only shard 0 should post
|
|
425
496
|
// If we're in CI with multiple shards and don't know which shard we are, block all posts
|
|
426
497
|
// This prevents duplicate messages when MATRIX_SHARD/MATRIX_INDEX is not set
|
|
427
|
-
if (
|
|
428
|
-
this.log(`❌ [Shard Detection] BLOCKING:
|
|
498
|
+
if (isActuallyInGitHubActions && totalShards > 1 && currentShardIndex === undefined) {
|
|
499
|
+
this.log(`❌ [Shard Detection] BLOCKING: GitHub Actions detected with ${totalShards} shards but shard index not set (MATRIX_SHARD/MATRIX_INDEX missing).`);
|
|
429
500
|
this.log(`❌ Skipping Slack report to prevent duplicate messages from all shards.`);
|
|
430
501
|
this.log(`💡 Fix: Add these env vars to your workflow:`);
|
|
431
502
|
this.log(`💡 env:`);
|
package/package.json
CHANGED