Skip to content

Commit

Permalink
get-measurement step will now also create and display a badge (#1)
Browse files Browse the repository at this point in the history
* get-measurement step will now also create and display a badge

* passes in run_id to badge endpoint

* refactor so curl command is actually correct

* updated to reflect value/unit split in api

* removed badge from github step summary as it was misleading
  • Loading branch information
dan-mm authored Mar 3, 2023
1 parent 052b121 commit 1867ca3
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ runs:
/tmp/eco-ci/demo-reporter > /tmp/eco-ci/cpu-utilization.txt &
- if: inputs.task == 'get-measurement'
id: run-model
name: Running estimation model
shell: bash
run: |
Expand Down Expand Up @@ -147,12 +148,41 @@ runs:
echo "🖥 avg. CPU utilization [%]:" >> $GITHUB_STEP_SUMMARY
awk '{ total += $1; count++ } END { print total/count }' /tmp/eco-ci/cpu-utilization.txt >> $GITHUB_STEP_SUMMARY
echo "🔋 Total Energy [Joules] :" >> $GITHUB_STEP_SUMMARY
awk '{sum+=$1} END {print sum}' /tmp/eco-ci/energy.txt >> $GITHUB_STEP_SUMMARY
total_energy=$(awk '{sum+=$1} END {print sum}' /tmp/eco-ci/energy.txt)
echo ${total_energy} >> ${GITHUB_STEP_SUMMARY}
echo "total_energy=${total_energy}" >> ${GITHUB_OUTPUT}
echo "🔌 avg. Power [Watts]:" >> $GITHUB_STEP_SUMMARY
awk '{ total += $1; count++ } END { print total/count }' /tmp/eco-ci/energy.txt >> $GITHUB_STEP_SUMMARY
echo '📈 Energy graph:' >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo ' ' >> $GITHUB_STEP_SUMMARY
cat /tmp/eco-ci/energy.txt | /home/runner/go/bin/asciigraph -h 10 -c "Watts over time" >> $GITHUB_STEP_SUMMARY
echo ' ```' >> $GITHUB_STEP_SUMMARY
- if: inputs.task == 'get-measurement'
name: energy used badge
id: energy-used-badge
shell: bash
run: |
api_base="https://api.green-coding.berlin"
add_endpoint=$api_base"/v1/ci/badge/add/"
get_endpoint=$api_base"/v1/ci/badge/get/"
metrics_url="https://metrics.green-coding.berlin"
value="${{ steps.run-model.outputs.total_energy }}"
value_mJ=$(echo "$value*1000" | bc -l | cut -d '.' -f 1)
unit="mJ"
repo_enc=$( echo ${{ github.repository }} | jq -Rr @uri)
branch_enc=$( echo ${{ github.ref_name }} | jq -Rr @uri)
workflow_enc=$( echo ${{ github.workflow }} | jq -Rr @uri)
run_id_enc=$( echo ${{ github.run_id }} | jq -Rr @uri)
curl -X POST "$add_endpoint" -H 'Content-Type: application/json' -d "{\"value\":\"$value_mJ\",\"unit\":\"$unit\",\"repo\":\"${{ github.repository }}\",\"branch\":\"${{ github.ref_name }}\",\"workflow\":\"${{ github.workflow }}\",\"run_id\":\"${{ github.run_id }}\",\"project_id\":\"\"}"
echo "Badge for your README.md" >> $GITHUB_STEP_SUMMARY
echo ' ```' >> $GITHUB_STEP_SUMMARY
echo "[![Energy Used](${get_endpoint}?repo=${repo_enc}&branch=${branch_enc}&workflow=${workflow_enc})](${metrics_url}/ci.html?repo=${repo_enc}&branch=${branch_enc}&workflow=${workflow_enc})" >> $GITHUB_STEP_SUMMARY
echo ' ```' >> $GITHUB_STEP_SUMMARY

0 comments on commit 1867ca3

Please sign in to comment.