-
Notifications
You must be signed in to change notification settings - Fork 17
170 lines (155 loc) · 5.56 KB
/
data-json-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Test data output as json
on:
pull_request:
paths-ignore:
- 'README.md'
- 'LICENSE'
- '.gitlab-ci.yml.example'
- '.gitignore'
schedule:
# only run once a week to show the action is working and preserve as much energy as possible
# Reason being that we pull our ML model and this could have changed in the meantime
- cron: '22 4 * * 6'
workflow_dispatch:
jobs:
test-data-output-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Initialize Energy Estimation
uses: ./
with:
task: start-measurement
json-output: true
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Sleep 2
run: |
sleep 2
- name: Node Setup Energy Measurment
id: data-node-setup
uses: ./
with:
task: get-measurement
label: 'node setup'
send-data: false
- name: Print node setup data
run: |
echo "total json: ${{ steps.data-node-setup.outputs.data-lap-json }}"
- name: Assert node setup output is appropriate
shell: bash
run: |
# setup
output='${{ steps.data-node-setup.outputs.data-lap-json }}'
required_label="node setup"
required_fields=("repository" "branch" "workflow" "run_id" "label" "cpu_avg_percent" "energy_joules" "power_avg_watts" "time")
required_count=${#required_fields[@]}
# assertions
if [ -z "$output" ]; then
echo "Output must not be empty"
exit 1
fi
fields_count=$(echo "$output" | jq 'keys | length')
if ! [ "${fields_count}" -eq "${required_count}" ]; then
echo "output has ${fields_count} instead of ${required_count}"
exit 1
fi
for field in "${required_fields[@]}"; do
if ! echo "$output" | jq -e --arg field "$field" 'has($field)' >/dev/null; then
echo "output is missing the field: $field"
exit 1
fi
done
label=$(echo "$output" | jq -r '.label')
if [ "$label" == "$required_label" ]; then
echo "value of 'label' is '$required_label'"
else
echo "value of 'label' is '$label', but it should be '$required_label'"
exit 1
fi
- name: Wait before the next step
run: sleep 10
- name: Sleep measurement
id: data-sleep
uses: ./
with:
task: get-measurement
label: "sleep"
send-data: false
- name: Print sleep data
run: |
echo "total json: ${{ steps.data-sleep.outputs.data-lap-json }}"
- name: Assert sleep output is appropriate
shell: bash
run: |
# setup
output='${{ steps.data-sleep.outputs.data-lap-json }}'
required_label="sleep"
required_fields=("repository" "branch" "workflow" "run_id" "label" "cpu_avg_percent" "energy_joules" "power_avg_watts" "time")
required_count=${#required_fields[@]}
# assertions
if [ -z "$output" ]; then
echo "Output must not be empty"
exit 1
fi
fields_count=$(echo "$output" | jq 'keys | length')
if ! [ "${fields_count}" -eq "${required_count}" ]; then
echo "output has ${fields_count} instead of ${required_count}"
exit 1
fi
for field in "${required_fields[@]}"; do
if ! echo "$output" | jq -e --arg field "$field" 'has($field)' >/dev/null; then
echo "output is missing the field: $field"
exit 1
fi
done
label=$(echo "$output" | jq -r '.label')
if [ "$label" == "$required_label" ]; then
echo "value of 'label' is '$required_label'"
else
echo "value of 'label' is '$label', but it should be '$required_label'"
exit 1
fi
- name: Eco CI Energy Estimation
id: data-total
uses: ./
with:
task: display-results
send-data: false
- name: Print total data
run: |
echo "total json: ${{ steps.data-total.outputs.data-total-json }}"
- name: Assert total output is appropriate
shell: bash
run: |
# setup
output='${{ steps.data-total.outputs.data-total-json }}'
required_label="TOTAL"
required_fields=("repository" "branch" "workflow" "run_id" "label" "cpu_avg_percent" "energy_joules" "power_avg_watts" "time")
required_count=${#required_fields[@]}
# assertions
if [ -z "$output" ]; then
echo "Output must not be empty"
exit 1
fi
fields_count=$(echo "$output" | jq 'keys | length')
if ! [ "${fields_count}" -eq "${required_count}" ]; then
echo "output has ${fields_count} instead of ${required_count}"
exit 1
fi
for field in "${required_fields[@]}"; do
if ! echo "$output" | jq -e --arg field "$field" 'has($field)' >/dev/null; then
echo "output is missing the field: $field"
exit 1
fi
done
label=$(echo "$output" | jq -r '.label')
if [ "$label" == "$required_label" ]; then
echo "value of 'label' is '$required_label'"
else
echo "value of 'label' is '$label', but it should be '$required_label'"
exit 1
fi