playwright-slack-report-burak 3.0.0 → 3.0.2

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.
@@ -72,19 +72,58 @@ class SlackReporter {
72
72
  }
73
73
  const resultSummary = await this.resultsParser.getParsedResults();
74
74
  // SHARDING SUPPORT - Stop slack messages for non-zero index shard(s)
75
- // Support both explicit MATRIX_SHARD/MATRIX_INDEX and workflow-style 1-based indexing
76
- // If MATRIX_SHARD is not set, shard 0 will still send reports (handles single shard case)
77
- const currentShardIndex = process.env.MATRIX_SHARD !== undefined
75
+ // The workflow uses 1-based shards (1, 2, 3...), but we need to determine which shard we are
76
+ // Only shard 0 (0-based) or shard 1 (1-based) should post when aggregating
77
+
78
+ let currentShardIndex = process.env.MATRIX_SHARD !== undefined
78
79
  ? process.env.MATRIX_SHARD
79
80
  : (process.env.MATRIX_INDEX !== undefined ? process.env.MATRIX_INDEX : undefined);
80
81
 
81
- // Only skip if explicitly set and not 0 (or '0')
82
- // This allows shard 0 to send reports even when MATRIX_SHARD is not set
83
- if (currentShardIndex !== undefined && currentShardIndex !== '0' && currentShardIndex !== 0) {
84
- const totalShards = process.env.MATRIX_COUNT || '1';
82
+ // Get shard info from ResultsParser which might have detected it from artifact fetching
83
+ const parserShardIndex = this.resultsParser.shardIndex;
84
+ const parserTotalShards = this.resultsParser.totalShardCount;
85
+
86
+ // Use parser values if env vars not set
87
+ const totalShards = process.env.MATRIX_COUNT ? parseInt(process.env.MATRIX_COUNT, 10) : parserTotalShards;
88
+
89
+ // If we still don't have shard index, try to infer from parser
90
+ if (currentShardIndex === undefined && parserShardIndex !== undefined) {
91
+ currentShardIndex = parserShardIndex.toString();
92
+ }
93
+
94
+ // CRITICAL: If we're in CI and don't know which shard we are, we MUST block posting
95
+ // This prevents all shards from posting when MATRIX_SHARD is not set
96
+ // Exception: If we're certain it's a single shard (totalShards === 1 AND no artifacts to fetch)
97
+ if (process.env.CI && currentShardIndex === undefined) {
98
+ // In CI without shard index = assume multiple shards and block all posts
99
+ // Only shard 0/1 should post when aggregating, but we can't detect it without MATRIX_SHARD
100
+ this.log(`❌ CI environment detected but shard index not set (MATRIX_SHARD/MATRIX_INDEX missing).`);
101
+ this.log(`❌ Skipping Slack report to prevent duplicate messages from all shards.`);
102
+ this.log(`💡 Fix: Add these env vars to your workflow:`);
103
+ this.log(`💡 env:`);
104
+ this.log(`💡 MATRIX_SHARD: $\{\{ matrix.shard - 1 \}\} # 0-based (shard 1 posts)`);
105
+ this.log(`💡 MATRIX_COUNT: $\{\{ strategy.job-total \}\}`);
106
+ this.log(`💡 OR use 1-based: MATRIX_SHARD: $\{\{ matrix.shard \}\} (then only shard 1 posts)`);
107
+ return;
108
+ }
109
+
110
+ // Convert to number for comparison
111
+ const shardIndexNum = currentShardIndex !== undefined ? parseInt(currentShardIndex, 10) : 0;
112
+
113
+ // Only allow shard 0 (0-based) or shard 1 (1-based) to post when there are multiple shards
114
+ // This ensures only one shard posts the aggregated report
115
+ if (totalShards > 1 && shardIndexNum !== 0 && shardIndexNum !== 1) {
85
116
  this.log(`❌ Stopping reporter for non-zero index shard ${currentShardIndex} of ${totalShards}`);
117
+ this.log(`ℹ️ Only shard 0 (0-based) or shard 1 (1-based) will post the aggregated report.`);
86
118
  return;
87
119
  }
120
+
121
+ // Single shard - always allow posting
122
+ if (totalShards === 1) {
123
+ this.log(`ℹ️ Single shard detected. Posting Slack report.`);
124
+ } else {
125
+ this.log(`ℹ️ Multiple shards detected (${totalShards}). Shard ${currentShardIndex} will post aggregated report.`);
126
+ }
88
127
  resultSummary.meta = this.meta;
89
128
  const maxRetry = Math.max(...resultSummary.tests.map((o) => o.retry));
90
129
  if (this.sendResults === 'on-failure'
package/package.json CHANGED
@@ -31,7 +31,7 @@
31
31
  "lint-fix": "npx eslint . --ext .ts --fix"
32
32
  },
33
33
  "name": "playwright-slack-report-burak",
34
- "version": "3.0.0",
34
+ "version": "3.0.2",
35
35
  "main": "index.js",
36
36
  "types": "dist/index.d.ts",
37
37
  "author": "Burak B. <burak.boluk@hotmail.com>",