Skip to content

Commit

Permalink
Merge pull request #35 from green-coding-berlin/pr-comment-display-ch…
Browse files Browse the repository at this point in the history
…ange

pr-comment change view
  • Loading branch information
dan-mm authored Aug 4, 2023
2 parents 08455c3 + 19d408f commit f098b21
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ on:
permissions:
contents: read
actions: read
pull-requests: write

jobs:
test-action:
Expand Down Expand Up @@ -49,3 +50,4 @@ jobs:
uses: ./
with:
task: display-results
pr-comment: true
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ jobs:
- automatically false if send-data is also false
- `pr-comment`: (optional) (default: false)
- used with display-results
- if on, will post a comment on the PR issue with the Eco-CI results
- if on, will post a comment on the PR issue with the Eco-CI results. only occurs if the triggering event is a pull_request
- remember to set `pull-requests: write` to true in your workflow file


#### Continuing on Errors

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ runs:
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
COMMENT=$(cat "/tmp/eco-ci/output-multiline.txt")
COMMENT=$(cat "/tmp/eco-ci/output-pr.txt" | jq -Rs '.')
API_URL="${{ github.api_url }}/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
curl -X POST -H "Authorization: Bearer ${{github.token}}" -d @- $API_URL <<EOF
{
"body": "$COMMENT"
"body": $COMMENT
}
EOF
40 changes: 12 additions & 28 deletions scripts/display_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source "$(dirname "$0")/vars.sh" read_vars

function display_results {
output="/tmp/eco-ci/output.txt"
output_multiline="/tmp/eco-ci/output-multiline.txt"
output_pr="/tmp/eco-ci/output-pr.txt"

if [[ $MEASUREMENT_RAN != true ]]; then
echo "Running a measurement to have at least one result to display."
Expand Down Expand Up @@ -50,23 +50,6 @@ function display_results {
max_measurement_number=$measurement_number
done

## Used for display in the PR comment body
echo "Eco-Ci Output:<br/><br/>" >> $output_multiline
echo "Total Energy [Joules]: $total_energy<br/>" >> $output_multiline
echo "Total Avg. CPU Utilization: $cpu_avg<br/>" >> $output_multiline
echo "Total Avg. Power [Watts]: $power_avg<br/>" >> $output_multiline
echo "Total Duration [seconds]: $time<br/>" >> $output_multiline
echo "--------------------------------<br/>" >> $output_multiline

for (( i=1; i<=$max_measurement_number; i++ )); do
echo "Label $i: $(eval echo \$label_$i)<br/>" >> $output_multiline
echo "Energy Used [Joules]: $(eval echo \$total_energy_$i)<br/>" >> $output_multiline
echo "Avg. CPU Utilization: $(eval echo \$cpu_avg_$i)<br/>" >> $output_multiline
echo "Avg. Power [Watts]: $(eval echo \$power_avg_$i)<br/>" >> $output_multiline
echo "Duration [seconds]: $(eval echo \$time_$i)<br/>" >> $output_multiline
echo "--------------------------------<br/>" >> $output_multiline
done

## Gitlab Specific Output
if [[ $source == 'gitlab' ]]; then
echo "\"$CI_JOB_NAME: Energy [Joules]:\" $total_energy" | tee -a $output metrics.txt
Expand All @@ -87,25 +70,26 @@ function display_results {
if [[ ${display_table} == 'true' ]]; then
## Used for the main output display for github (step summary) / gitlab (artifacts)
if [[ $source == 'github' ]]; then
echo "|Label|🖥 avg. CPU utilization [%]|🔋 Total Energy [Joules]|🔌 avg. Power [Watts]|Duration [Seconds]|" >> $output
echo "|---|---|---|---|---|" >> $output
echo "|Total Run|$cpu_avg|$total_energy|$power_avg|$time|" >> $output
echo "Eco-CI Output: " >> $output_pr
echo "|Label|🖥 avg. CPU utilization [%]|🔋 Total Energy [Joules]|🔌 avg. Power [Watts]|Duration [Seconds]|" | tee -a $output $output_pr
echo "|---|---|---|---|---|" | tee -a $output $output_pr
echo "|Total Run|$cpu_avg|$total_energy|$power_avg|$time|" | tee -a $output $output_pr
#display measurument lines in table summary
for (( i=1; i<=$max_measurement_number; i++ ))
do
echo "|$(eval echo \$label_$i)|$(eval echo \$cpu_avg_$i)|$(eval echo \$total_energy_$i)|$(eval echo \$power_avg_$i)|$(eval echo \$time_$i)|" >> $output
echo "|$(eval echo \$label_$i)|$(eval echo \$cpu_avg_$i)|$(eval echo \$total_energy_$i)|$(eval echo \$power_avg_$i)|$(eval echo \$time_$i)|" | tee -a $output $output_pr
done
echo '' >> $output
echo '' | tee -a $output $output_pr
fi
fi

if [[ ${display_graph} == 'true' ]]; then
if [[ $source == 'github' ]]; then
echo '📈 Energy graph:' >> $output
echo '```bash' >> $output
echo ' ' >> $output
cat /tmp/eco-ci/energy-total.txt | /home/runner/go/bin/asciigraph -h 10 -c "Watts over time" >> $output
echo ' ```' >> $output
echo '📈 Energy graph:' | tee -a $output $output_pr
echo '```bash' | tee -a $output $output_pr
echo ' ' | tee -a $output $output_pr
cat /tmp/eco-ci/energy-total.txt | /home/runner/go/bin/asciigraph -h 10 -c "Watts over time" | tee -a $output $output_pr
echo ' ```' | tee -a $output $output_pr
elif [[ $source == 'gitlab' ]]; then
echo '📈 Energy graph:' >> $output
cat /tmp/eco-ci/energy-total.txt | /home/runner/go/bin/asciigraph -h 10 -c "Watts over time" >> $output
Expand Down

0 comments on commit f098b21

Please sign in to comment.