-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlocal_ci.example.sh
86 lines (61 loc) · 2.96 KB
/
local_ci.example.sh
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
#!/usr/bin/env bash
set -euo pipefail
shell=bash
ECO_CI_SEND_DATA='true'
ECO_CI_DISPLAY_BADGE='true'
ECO_CI_DISPLAY_TABLE='true'
ECO_CI_WORKFLOW_ID='YOUR_WORKFLOW_ID'
# If you want filter data in the GMT Dashboard or in CarbonDB you can here manually set data for drill-down later
# The values given are just some default recommendations
ECO_CI_FILTER_TYPE='machine.ci'
ECO_CI_FILTER_PROJECT='CI/CD'
ECO_CI_FILTER_MACHINE='local-runner'
ECO_CI_FILTER_TAGS='' # Tags must be comma separated. Tags cannot have commas itself or contain quotes
ECO_CI_CALCULATE_CO2='true'
ECO_CI_JSON_OUTPUT='true'
ECO_CI_GMT_API_TOKEN=''
ECO_CI_ELECTRICITYMAPS_API_TOKEN=''
# Change this to a local installation of the GMT if you have
ECO_CI_API_ENDPOINT_ADD='http://api.green-coding.internal:9142/v2/ci/measurement/add'
ECO_CI_API_BADGE_GET='http://api.green-coding.internal:9142/v1/ci/badge/get'
ECO_CI_DASHBOARD_URL='http://metrics.green-coding.internal:9142'
# Use a generated power curve from Cloud Energy here
ECO_CI_MACHINE_POWER_DATA="default.sh"
# Initialize
echo "Initialize"
$shell "$(dirname "$0")/scripts/setup.sh" start_measurement "$ECO_CI_MACHINE_POWER_DATA" "MY_RUN_ID" "NO_BRANCH" "LOCAL_TEST_REPO" "$ECO_CI_WORKFLOW_ID" "MY WORKFLOW NAME" "NO SHA" "local" "$ECO_CI_SEND_DATA" "$ECO_CI_FILTER_TYPE" "$ECO_CI_FILTER_PROJECT" "$ECO_CI_FILTER_MACHINE" "$ECO_CI_FILTER_TAGS" "$ECO_CI_CALCULATE_CO2" "$ECO_CI_GMT_API_TOKEN" "$ECO_CI_ELECTRICITYMAPS_API_TOKEN" "$ECO_CI_JSON_OUTPUT" "$ECO_CI_API_ENDPOINT_ADD" "$ECO_CI_API_BADGE_GET" "$ECO_CI_DASHBOARD_URL"
echo "Duration: "$(($(date "+%s%6N") - $(cat /tmp/eco-ci/timer-total.txt))) "us"
# Do some work
echo "Sleeping"
sleep 2s
echo "Duration: "$(($(date "+%s%6N") - $(cat /tmp/eco-ci/timer-total.txt))) "us"
$shell "$(dirname "$0")/scripts/make_measurement.sh" make_measurement "My_label"
# Do some other work
echo "ls -alhR"
timeout 3s ls -alhR / &> /dev/null || true
echo "Duration: "$(($(date "+%s%6N") - $(cat /tmp/eco-ci/timer-total.txt))) "us"
echo "Sleeping "
sleep 1
echo "Duration: "$(($(date "+%s%6N") - $(cat /tmp/eco-ci/timer-total.txt))) "us"
$shell "$(dirname "$0")/scripts/make_measurement.sh" make_measurement "other label"
#"My other label"
echo "Display Results"
echo "Duration: "$(($(date "+%s%6N") - $(cat /tmp/eco-ci/timer-total.txt))) "us"
# Display results
ECO_CI_FORMAT_CLR="\e[44m"
ECO_CI_TXT_CLEAR="\e[0m"
echo "Dump files"
cat /tmp/eco-ci/energy-step.txt
cat /tmp/eco-ci/cpu-util-step.txt
cat /tmp/eco-ci/energy-total.txt
cat /tmp/eco-ci/cpu-util-total.txt
$shell "$(dirname "$0")/scripts/display_results.sh" display_results $ECO_CI_DISPLAY_TABLE $ECO_CI_DISPLAY_BADGE
if [[ "$ECO_CI_JSON_OUTPUT" == 'true' ]]; then
echo "JSON Dump:"
cat /tmp/eco-ci/lap-data.json
cat /tmp/eco-ci/total-data.json
fi
echo -e "\n"
echo -e "$ECO_CI_FORMAT_CLR$(cat /tmp/eco-ci/output.txt)$ECO_CI_TXT_CLEAR"
echo "Duration: "$(($(date "+%s%6N") - $(cat /tmp/eco-ci/timer-total.txt))) "us"
$shell "$(dirname "$0")/scripts/setup.sh" end_measurement