Skip to content

Update overhead_test.yml #424

Update overhead_test.yml

Update overhead_test.yml #424

Workflow file for this run

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