@@ -152,6 +152,9 @@ jobs:
152152
153153 # Save updated stats
154154 echo "$new_stats" > "${{ env.STATS_FILE }}"
155+
156+ # Build new state file
157+ new_state=$(echo "$previous_state" | jq --arg time "$current_time" '.last_run = $time | .runners = {}')
155158
156159 if [ -f "current_runners.tmp" ]; then
157160 while IFS=',' read -r name status consecutive labels; do
@@ -161,6 +164,9 @@ jobs:
161164 fi
162165 done < current_runners.tmp
163166 fi
167+
168+ # Save new state
169+ echo "$new_state" > "${{ env.STATE_FILE }}"
164170
165171 # Prepare notification messages
166172 notification_message=""
@@ -219,20 +225,33 @@ jobs:
219225 # Load stats
220226 stats=$(cat "${{ env.STATS_FILE }}")
221227
222- # Calculate statistics for each runner
223- weekly_report="📊 **Weekly Runner Statistics Report**\n\n"
224- weekly_report+="_Period: Last 7 days • Generated: $(date -u +'%Y-%m-%d %H:%M UTC')_\n\n"
225-
226228 # Get list of runners that have data
227229 runners=$(echo "$stats" | jq -r '.runners | keys[]' | sort)
228230
231+ # Create temporary file for weekly report content
232+ weekly_report_file="weekly_report.tmp"
233+
234+ # Write report header
235+ cat > "$weekly_report_file" << 'EOF'
236+ 📊 **Weekly Runner Statistics Report**
237+
238+ EOF
239+
240+ echo "_Period: Last 7 days • Generated: $(date -u +'%Y-%m-%d %H:%M UTC')_" >> "$weekly_report_file"
241+ echo "" >> "$weekly_report_file"
242+
229243 if [ -z "$runners" ]; then
230- weekly_report+= "No runner data available for the past 7 days.\n "
244+ echo "No runner data available for the past 7 days." >> "$weekly_report_file "
231245 else
232- weekly_report+="| Runner | Idle | Active | Offline | Labels |\n"
233- weekly_report+="|--------|------|---------|---------|--------|\n"
246+ # Write table header
247+ cat >> "$weekly_report_file" << 'EOF'
248+ | Runner | Idle | Active | Offline | Labels |
249+ |--------|------|---------|---------|--------|
250+ EOF
234251
235- for runner in $runners; do
252+ # Process each runner and write to temp file
253+ echo "$runners" | while read -r runner; do
254+ if [ -z "$runner" ]; then continue; fi
236255 echo "Processing stats for runner: $runner"
237256
238257 # Calculate percentages using jq
@@ -261,20 +280,27 @@ jobs:
261280 labels_display="\`$labels\`"
262281 fi
263282
264- weekly_report+= "| \`$runner\` | ${idle_pct}% | ${active_pct}% | ${offline_pct}% | $labels_display |\n "
283+ echo "| \`$runner\` | ${idle_pct}% | ${active_pct}% | ${offline_pct}% | $labels_display |" >> "$weekly_report_file "
265284 done
266285
267- weekly_report+="\n**Legend:**\n"
268- weekly_report+="• **Idle**: Runner online but not executing jobs\n"
269- weekly_report+="• **Active**: Runner online and executing jobs\n"
270- weekly_report+="• **Offline**: Runner not responding\n\n"
271- weekly_report+="_Statistics based on $(echo "$stats" | jq -r '[.runners[].history[]] | length') data points collected every 15 minutes._\n"
286+ # Add legend and footer
287+ cat >> "$weekly_report_file" << EOF
288+
289+ **Legend:**
290+ • **Idle**: Runner online but not executing jobs
291+ • **Active**: Runner online and executing jobs
292+ • **Offline**: Runner not responding
293+
294+ _Statistics based on $(echo "$stats" | jq -r '[.runners[].history[]] | length') data points collected every 15 minutes._
295+ EOF
272296 fi
273297
274- echo "should_send_weekly=$is_weekly_report" >> $GITHUB_OUTPUT
275298 echo "weekly_message<<EOF" >> $GITHUB_OUTPUT
276- echo -e "$weekly_report " >> $GITHUB_OUTPUT
299+ cat "$weekly_report_file " >> $GITHUB_OUTPUT
277300 echo "EOF" >> $GITHUB_OUTPUT
301+
302+ # Clean up temp file
303+ rm -f "$weekly_report_file"
278304
279305 - name : Send status message on Zulip
280306 if : steps.check-runners.outputs.should_notify == 'true'
@@ -290,7 +316,7 @@ jobs:
290316 ${{ steps.check-runners.outputs.message }}
291317
292318 - name : Send weekly report on Zulip
293- if : steps.weekly-stats .outputs.should_send_weekly == 'true'
319+ if : steps.check-runners .outputs.is_weekly_report == 'true'
294320 uses : zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2
295321 with :
296322 api-key : ${{ secrets.ZULIP_MONITOR_RUNNERS_API_KEY }}
@@ -327,8 +353,10 @@ jobs:
327353
328354 echo ""
329355 echo "=== Statistics Summary ==="
330- cat "${{ env.STATS_FILE }}" | jq '.runners | keys | length' | xargs echo "Runners tracked:"
331- cat "${{ env.STATS_FILE }}" | jq '[.runners[].history[]] | length' | xargs echo "Total data points:"
356+ runner_count=$(cat "${{ env.STATS_FILE }}" | jq '.runners | keys | length')
357+ echo "Runners tracked: $runner_count"
358+ data_points=$(cat "${{ env.STATS_FILE }}" | jq '[.runners[].history[]] | length')
359+ echo "Total data points: $data_points"
332360
333361 echo ""
334362 echo "=== 7-Day Statistics Report ==="
@@ -342,7 +370,7 @@ jobs:
342370 echo "✅ No status notifications needed - all runners stable"
343371 fi
344372
345- if [ "${{ steps.weekly-stats .outputs.should_send_weekly }}" = "true" ]; then
373+ if [ "${{ steps.check-runners .outputs.is_weekly_report }}" = "true" ]; then
346374 echo "📊 Weekly report sent to Zulip"
347375 else
348376 echo "📊 Weekly report generated but not sent (not scheduled weekly run)"
0 commit comments