@@ -15,19 +15,19 @@ runs:
1515 run : |
1616 # Check if WORKFLOW_START_TIME is set
1717 if [ -z "$WORKFLOW_START_TIME" ]; then
18- echo "Warning: WORKFLOW_START_TIME not set, skipping metrics upload"
19- exit 0
18+ echo "Warning: WORKFLOW_START_TIME not set, skipping metrics upload"
19+ exit 0
2020 fi
2121
2222 duration=$(($(date +%s) - $WORKFLOW_START_TIME))
2323
2424 # Build job name with matrix values
2525 job_name="${{ github.job }}"
2626 if [ ! -z "${{ matrix.java-version || '' }}" ]; then
27- job_name="${job_name}(${{ matrix.java-version }})"
27+ job_name="${job_name}(${{ matrix.java-version }})"
2828 fi
2929 if [ ! -z "${{ matrix.os || '' }}" ]; then
30- job_name="${job_name}(${{ matrix.os }})"
30+ job_name="${job_name}(${{ matrix.os }})"
3131 fi
3232
3333 # Determine success/failure (1 for success, 0 for failure)
4040 aws cloudwatch put-metric-data \
4141 --namespace "GitHub/Workflows" \
4242 --metric-data '[{
43- "MetricName": "Duration",
44- "Value": '$duration',
45- "Unit": "Seconds",
46- "Dimensions": [
47- {
48- "Name": "WorkflowName",
49- "Value": "${{ github.workflow }}"
50- },
51- {
52- "Name": "JobName",
53- "Value": "'$job_name'"
54- },
55- {
56- "Name": "Repository",
57- "Value": "${{ github.repository }}"
58- }
59- ]
60- },
61- {
6243 "MetricName": "Success",
6344 "Value": '$success_value',
6445 "Unit": "Count",
7253 "Value": "'$job_name'"
7354 },
7455 {
75- "Name": "Repository",
56+ "Name": "Repository",
7657 "Value": "${{ github.repository }}"
7758 }
7859 ]
79- }
80- ]'
60+ }]'
61+
62+ # Send Duration metric only if workflow successful
63+ if [ "$success_value" -eq 1 ]; then
64+ aws cloudwatch put-metric-data \
65+ --namespace "GitHub/Workflows" \
66+ --metric-data '[{
67+ "MetricName": "Duration",
68+ "Value": '$duration',
69+ "Unit": "Seconds",
70+ "Dimensions": [
71+ {
72+ "Name": "WorkflowName",
73+ "Value": "${{ github.workflow }}"
74+ },
75+ {
76+ "Name": "JobName",
77+ "Value": "'$job_name'"
78+ },
79+ {
80+ "Name": "Repository",
81+ "Value": "${{ github.repository }}"
82+ }
83+ ]
84+ }]'
85+ fi
0 commit comments