Skip to content

Commit ed18bae

Browse files
committed
Tidy UI configuration
1 parent f974e0c commit ed18bae

File tree

8 files changed

+151
-54
lines changed

8 files changed

+151
-54
lines changed

.eslintrc.json

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
2-
"plugins": [
3-
"@typescript-eslint"
4-
],
5-
"extends": [
6-
"plugin:github/recommended"
7-
],
2+
"plugins": ["@typescript-eslint"],
3+
"extends": ["plugin:github/recommended"],
84
"parser": "@typescript-eslint/parser",
95
"parserOptions": {
106
"ecmaVersion": 9,
@@ -36,10 +32,7 @@
3632
"allowExpressions": true
3733
}
3834
],
39-
"@typescript-eslint/func-call-spacing": [
40-
"error",
41-
"never"
42-
],
35+
"@typescript-eslint/func-call-spacing": ["error", "never"],
4336
"@typescript-eslint/no-array-constructor": "error",
4437
"@typescript-eslint/no-explicit-any": "error",
4538
"@typescript-eslint/no-extraneous-class": "error",
@@ -60,10 +53,7 @@
6053
"@typescript-eslint/require-array-sort-compare": "error",
6154
"@typescript-eslint/restrict-plus-operands": "error",
6255
"semi": "off",
63-
"@typescript-eslint/semi": [
64-
"error",
65-
"never"
66-
],
56+
"@typescript-eslint/semi": ["error", "never"],
6757
"@typescript-eslint/type-annotation-spacing": "error",
6858
"@typescript-eslint/unbound-method": "error"
6959
},

.github/workflows/self-test.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: self-test
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'src/**'
7+
- 'action.yml'
8+
- '.github/workflows/self-test.yml'
9+
workflow_dispatch:
10+
11+
permissions:
12+
pull-requests: write
13+
contents: read
14+
15+
jobs:
16+
self-test:
17+
name: Test the action against itself
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 20
27+
28+
- name: Build & package
29+
run: |
30+
npm ci
31+
npm run build
32+
npm run package
33+
34+
# Test the action itself (using the local changes)
35+
- name: Run workflow telemetry
36+
uses: ./
37+
with:
38+
comment_on_pr: true
39+
job_summary: true
40+
theme: light
41+
proc_trace_table_show: true
42+
proc_trace_sys_enable: true
43+
44+
# This is a simple test that gives the action something to measure
45+
- name: Run some commands to generate metrics
46+
run: |
47+
echo "Creating some disk activity..."
48+
dd if=/dev/zero of=testfile bs=1M count=100
49+
rm testfile
50+
51+
echo "Creating some CPU activity..."
52+
for i in {1..10000000}
53+
do
54+
done
55+
56+
# # Run another test command after the action starts monitoring
57+
# - name: More test commands
58+
# run: |
59+
# echo "Running more commands to generate metrics..."
60+
# wget -q https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
61+
# tar xzf node_exporter-1.6.1.linux-amd64.tar.gz
62+
# rm node_exporter-1.6.1.linux-amd64.tar.gz
63+
#
64+
# # Wait a bit to ensure metrics are collected
65+
# - name: Wait for metrics collection
66+
# run: sleep 10

.prettierrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"printWidth": 80,
33
"tabWidth": 2,
44
"useTabs": false,
5-
"semi": false,
5+
"semi": true,
66
"singleQuote": true,
7-
"trailingComma": "none",
7+
"trailingComma": "es5",
88
"bracketSpacing": true,
99
"arrowParens": "avoid"
1010
}

src/config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Configuration constants
2+
export const UI_CONFIG = {
3+
FONT_FAMILY: 'Arial, Helvetica, sans-serif'
4+
}
5+
6+
// Chart configuration defaults
7+
export const CHART_DEFAULTS = {
8+
options: {
9+
width: 1000,
10+
height: 500,
11+
xAxis: {
12+
label: 'Time',
13+
fontFamily: UI_CONFIG.FONT_FAMILY
14+
},
15+
yAxis: {
16+
fontFamily: UI_CONFIG.FONT_FAMILY
17+
},
18+
timeTicks: {
19+
unit: 'auto'
20+
},
21+
fontFamily: UI_CONFIG.FONT_FAMILY
22+
}
23+
}
24+
25+
// Mermaid chart defaults
26+
export const MERMAID_DEFAULTS = {
27+
gantt: {
28+
dateFormat: 'x',
29+
axisFormat: '%H:%M:%S',
30+
fontFamily: UI_CONFIG.FONT_FAMILY
31+
}
32+
}

src/interfaces/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { components } from '@octokit/openapi-types'
33

44
export type WorkflowJobType = components['schemas']['job']
55

6+
67
export interface CPUStats {
78
readonly time: number
89
readonly totalLoad: number

src/processTracer.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import si from 'systeminformation'
55
import { sprintf } from 'sprintf-js'
66
import { parse } from './procTraceParser'
77
import { CompletedCommand, WorkflowJobType } from './interfaces'
8+
import { MERMAID_DEFAULTS } from './config'
89
import * as logger from './logger'
910

1011
const PROC_TRACER_PID_KEY = 'PROC_TRACER_PID'
@@ -67,8 +68,9 @@ export async function start(): Promise<boolean> {
6768
logger.info(`Starting process tracer ...`)
6869

6970
try {
70-
const procTracerBinaryName: string | null =
71-
await getProcessTracerBinaryName()
71+
const procTracerBinaryName:
72+
| string
73+
| null = await getProcessTracerBinaryName()
7274
if (procTracerBinaryName) {
7375
const procTraceOutFilePath = path.join(
7476
__dirname,
@@ -200,8 +202,16 @@ export async function report(
200202
if (procTraceChartShow) {
201203
chartContent = chartContent.concat('gantt', '\n')
202204
chartContent = chartContent.concat('\t', `title ${currentJob.name}`, '\n')
203-
chartContent = chartContent.concat('\t', `dateFormat x`, '\n')
204-
chartContent = chartContent.concat('\t', `axisFormat %H:%M:%S`, '\n')
205+
chartContent = chartContent.concat(
206+
'\t',
207+
`dateFormat ${MERMAID_DEFAULTS.gantt.dateFormat}`,
208+
'\n'
209+
)
210+
chartContent = chartContent.concat(
211+
'\t',
212+
`axisFormat ${MERMAID_DEFAULTS.gantt.axisFormat}`,
213+
'\n'
214+
)
205215

206216
const filteredCommands: CompletedCommand[] = [...completedCommands]
207217
.sort((a: CompletedCommand, b: CompletedCommand) => {
@@ -284,7 +294,7 @@ export async function report(
284294

285295
///////////////////////////////////////////////////////////////////////////
286296

287-
const postContentItems: string[] = ['', '### Process Trace']
297+
const postContentItems: string[] = ['', '### Process trace']
288298
if (procTraceChartShow) {
289299
postContentItems.push(
290300
'',
@@ -296,7 +306,7 @@ export async function report(
296306
if (procTraceTableShow) {
297307
postContentItems.push(
298308
'',
299-
`#### All processes with detail`,
309+
`#### All processes with details`,
300310
'',
301311
'```' + '\n' + tableContent + '\n' + '```'
302312
)

src/statCollector.ts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from './interfaces'
2222
import * as logger from './logger'
2323
import { log } from 'console'
24+
import { CHART_DEFAULTS } from './config'
2425

2526
const STAT_SERVER_PORT = 7777
2627

@@ -60,16 +61,16 @@ async function reportWorkflowMetrics(): Promise<string> {
6061
const cpuLoad =
6162
userLoadX && userLoadX.length && systemLoadX && systemLoadX.length
6263
? await getStackedAreaGraph({
63-
label: 'CPU Load (%)',
64+
label: 'CPU load (%)',
6465
axisColor,
6566
areas: [
6667
{
67-
label: 'User Load',
68+
label: 'User load',
6869
color: '#e41a1c99',
6970
points: userLoadX
7071
},
7172
{
72-
label: 'System Load',
73+
label: 'System load',
7374
color: '#ff7f0099',
7475
points: systemLoadX
7576
}
@@ -83,7 +84,7 @@ async function reportWorkflowMetrics(): Promise<string> {
8384
availableMemoryX &&
8485
availableMemoryX.length
8586
? await getStackedAreaGraph({
86-
label: 'Memory Usage (MB)',
87+
label: 'Memory usage (MB)',
8788
axisColor,
8889
areas: [
8990
{
@@ -103,7 +104,7 @@ async function reportWorkflowMetrics(): Promise<string> {
103104
const networkIORead =
104105
networkReadX && networkReadX.length
105106
? await getLineGraph({
106-
label: 'Network I/O Read (MB)',
107+
label: 'Network I/O read (MB)',
107108
axisColor,
108109
line: {
109110
label: 'Read',
@@ -116,7 +117,7 @@ async function reportWorkflowMetrics(): Promise<string> {
116117
const networkIOWrite =
117118
networkWriteX && networkWriteX.length
118119
? await getLineGraph({
119-
label: 'Network I/O Write (MB)',
120+
label: 'Network I/O write (MB)',
120121
axisColor,
121122
line: {
122123
label: 'Write',
@@ -129,7 +130,7 @@ async function reportWorkflowMetrics(): Promise<string> {
129130
const diskIORead =
130131
diskReadX && diskReadX.length
131132
? await getLineGraph({
132-
label: 'Disk I/O Read (MB)',
133+
label: 'Disk I/O read (MB)',
133134
axisColor,
134135
line: {
135136
label: 'Read',
@@ -142,7 +143,7 @@ async function reportWorkflowMetrics(): Promise<string> {
142143
const diskIOWrite =
143144
diskWriteX && diskWriteX.length
144145
? await getLineGraph({
145-
label: 'Disk I/O Write (MB)',
146+
label: 'Disk I/O write (MB)',
146147
axisColor,
147148
line: {
148149
label: 'Write',
@@ -155,7 +156,7 @@ async function reportWorkflowMetrics(): Promise<string> {
155156
const diskSizeUsage =
156157
diskUsedX && diskUsedX.length && diskAvailableX && diskAvailableX.length
157158
? await getStackedAreaGraph({
158-
label: 'Disk Usage (MB)',
159+
label: 'Disk usage (MB)',
159160
axisColor,
160161
areas: [
161162
{
@@ -175,21 +176,21 @@ async function reportWorkflowMetrics(): Promise<string> {
175176
const postContentItems: string[] = []
176177
if (cpuLoad) {
177178
postContentItems.push(
178-
'### CPU Metrics',
179+
'### CPU metrics',
179180
`![${cpuLoad.id}](${cpuLoad.url})`,
180181
''
181182
)
182183
}
183184
if (memoryUsage) {
184185
postContentItems.push(
185-
'### Memory Metrics',
186+
'### Memory metrics',
186187
`![${memoryUsage.id}](${memoryUsage.url})`,
187188
''
188189
)
189190
}
190191
if ((networkIORead && networkIOWrite) || (diskIORead && diskIOWrite)) {
191192
postContentItems.push(
192-
'### IO Metrics',
193+
'### IO metrics',
193194
'| | Read | Write |',
194195
'|--- |--- |--- |'
195196
)
@@ -206,7 +207,7 @@ async function reportWorkflowMetrics(): Promise<string> {
206207
}
207208
if (diskSizeUsage) {
208209
postContentItems.push(
209-
'### Disk Size Metrics',
210+
'### Disk size metrics',
210211
`![${diskSizeUsage.id}](${diskSizeUsage.url})`,
211212
''
212213
)
@@ -358,16 +359,10 @@ async function getDiskSizeStats(): Promise<ProcessedDiskSizeStats> {
358359
async function getLineGraph(options: LineGraphOptions): Promise<GraphResponse> {
359360
const payload = {
360361
options: {
361-
width: 1000,
362-
height: 500,
363-
xAxis: {
364-
label: 'Time'
365-
},
362+
...CHART_DEFAULTS.options,
366363
yAxis: {
364+
...CHART_DEFAULTS.options.yAxis,
367365
label: options.label
368-
},
369-
timeTicks: {
370-
unit: 'auto'
371366
}
372367
},
373368
lines: [options.line]
@@ -392,16 +387,10 @@ async function getStackedAreaGraph(
392387
): Promise<GraphResponse> {
393388
const payload = {
394389
options: {
395-
width: 1000,
396-
height: 500,
397-
xAxis: {
398-
label: 'Time'
399-
},
390+
...CHART_DEFAULTS.options,
400391
yAxis: {
392+
...CHART_DEFAULTS.options.yAxis,
401393
label: options.label
402-
},
403-
timeTicks: {
404-
unit: 'auto'
405394
}
406395
},
407396
areas: options.areas

0 commit comments

Comments
 (0)