playwright-slack-report-burak 3.0.15 → 3.0.16
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 +52 -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,66 @@ 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 Playwright's shard config (highest priority for local runs)
|
|
345
|
+
let playwrightShardInfo = null;
|
|
346
|
+
if (this.fullConfig && this.fullConfig.shard) {
|
|
347
|
+
playwrightShardInfo = {
|
|
348
|
+
current: this.fullConfig.shard.current,
|
|
349
|
+
total: this.fullConfig.shard.total
|
|
350
|
+
};
|
|
351
|
+
this.log(`🔍 [Shard Detection] Found Playwright shard config: ${playwrightShardInfo.current}/${playwrightShardInfo.total}`);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Step 1: Try GitHub Actions API detection (only if actually in GitHub Actions)
|
|
336
355
|
let githubApiShardInfo = null;
|
|
337
|
-
if (
|
|
338
|
-
this.log(`🔍 [Shard Detection]
|
|
356
|
+
if (isActuallyInGitHubActions) {
|
|
357
|
+
this.log(`🔍 [Shard Detection] Actually running in GitHub Actions - attempting API detection...`);
|
|
339
358
|
githubApiShardInfo = await this.detectGitHubActionsShardInfo();
|
|
359
|
+
} else if (process.env.GITHUB_ACTIONS === 'true') {
|
|
360
|
+
this.log(`🔍 [Shard Detection] GitHub Actions env vars set but not actually in runner - skipping API detection`);
|
|
340
361
|
}
|
|
341
362
|
|
|
342
|
-
// Step 2: Detect shard index
|
|
343
|
-
let currentShardIndex
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
if (
|
|
363
|
+
// Step 2: Detect shard index (priority order: Playwright config > env vars > GitHub API)
|
|
364
|
+
let currentShardIndex;
|
|
365
|
+
if (playwrightShardInfo) {
|
|
366
|
+
// Playwright uses 1-based indexing, convert to 0-based
|
|
367
|
+
currentShardIndex = (playwrightShardInfo.current - 1).toString();
|
|
368
|
+
this.log(`🔍 [Shard Detection] Using Playwright shard config (converted to 0-based): "${currentShardIndex}"`);
|
|
369
|
+
} else if (process.env.MATRIX_SHARD !== undefined) {
|
|
370
|
+
currentShardIndex = process.env.MATRIX_SHARD;
|
|
371
|
+
this.log(`🔍 [Shard Detection] Using MATRIX_SHARD env var: "${currentShardIndex}"`);
|
|
372
|
+
} else if (process.env.MATRIX_INDEX !== undefined) {
|
|
373
|
+
currentShardIndex = process.env.MATRIX_INDEX;
|
|
374
|
+
this.log(`🔍 [Shard Detection] Using MATRIX_INDEX env var: "${currentShardIndex}"`);
|
|
375
|
+
} else if (githubApiShardInfo) {
|
|
349
376
|
currentShardIndex = githubApiShardInfo.shardIndex.toString();
|
|
350
377
|
this.log(`🔍 [Shard Detection] Using GitHub API detected shardIndex: "${currentShardIndex}"`);
|
|
351
378
|
}
|
|
352
379
|
|
|
353
380
|
this.log(`🔍 [Shard Detection] Initial currentShardIndex: ${currentShardIndex !== undefined ? `"${currentShardIndex}"` : 'undefined'}`);
|
|
354
381
|
|
|
355
|
-
// Step
|
|
382
|
+
// Step 3: Get shard count from multiple sources (priority order)
|
|
356
383
|
let totalShards;
|
|
357
|
-
if (
|
|
384
|
+
if (playwrightShardInfo) {
|
|
385
|
+
totalShards = playwrightShardInfo.total;
|
|
386
|
+
this.log(`🔍 [Shard Detection] Using Playwright shard config totalShards: ${totalShards}`);
|
|
387
|
+
} else if (process.env.MATRIX_COUNT !== undefined) {
|
|
358
388
|
totalShards = parseInt(process.env.MATRIX_COUNT, 10);
|
|
359
389
|
this.log(`🔍 [Shard Detection] Using MATRIX_COUNT env var: ${totalShards}`);
|
|
360
390
|
} else if (githubApiShardInfo && githubApiShardInfo.totalShards > 1) {
|
|
@@ -390,7 +420,8 @@ class SlackReporter {
|
|
|
390
420
|
|
|
391
421
|
// CRITICAL: In CI (especially GitHub Actions), if we can't detect shard info, block posting
|
|
392
422
|
// This prevents duplicate messages when running with multiple shards
|
|
393
|
-
if (
|
|
423
|
+
// BUT: Don't block if we're running locally (even if CI env vars are set)
|
|
424
|
+
if (isActuallyInGitHubActions && currentShardIndex === undefined) {
|
|
394
425
|
if (process.env.GITHUB_ACTIONS === 'true') {
|
|
395
426
|
this.log(`❌ [Shard Detection] BLOCKING: GitHub Actions detected but shard index cannot be determined.`);
|
|
396
427
|
this.log(`❌ Attempted: GitHub API detection ${githubApiShardInfo ? 'succeeded' : 'failed'}, env vars not set`);
|
|
@@ -421,11 +452,17 @@ class SlackReporter {
|
|
|
421
452
|
// This ensures ResultsParser always has correct values, even if we block posting
|
|
422
453
|
this.resultsParser.updateShardInfo(shardIndexNum, totalShards);
|
|
423
454
|
|
|
455
|
+
// For local runs with CI env vars set but not actually in CI, allow posting if single shard
|
|
456
|
+
// or if shard index is 0
|
|
457
|
+
if (!isActuallyInGitHubActions && process.env.CI && totalShards > 1 && currentShardIndex === undefined) {
|
|
458
|
+
this.log(`⚠️ [Shard Detection] Local run with CI env vars but shard info unclear - allowing post (may cause duplicates)`);
|
|
459
|
+
}
|
|
460
|
+
|
|
424
461
|
// CRITICAL: For GitHub Actions with multiple shards, only shard 0 should post
|
|
425
462
|
// If we're in CI with multiple shards and don't know which shard we are, block all posts
|
|
426
463
|
// This prevents duplicate messages when MATRIX_SHARD/MATRIX_INDEX is not set
|
|
427
|
-
if (
|
|
428
|
-
this.log(`❌ [Shard Detection] BLOCKING:
|
|
464
|
+
if (isActuallyInGitHubActions && totalShards > 1 && currentShardIndex === undefined) {
|
|
465
|
+
this.log(`❌ [Shard Detection] BLOCKING: GitHub Actions detected with ${totalShards} shards but shard index not set (MATRIX_SHARD/MATRIX_INDEX missing).`);
|
|
429
466
|
this.log(`❌ Skipping Slack report to prevent duplicate messages from all shards.`);
|
|
430
467
|
this.log(`💡 Fix: Add these env vars to your workflow:`);
|
|
431
468
|
this.log(`💡 env:`);
|
package/package.json
CHANGED