diff --git a/README.md b/README.md index 01e7ac3..4e8475f 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ jobs: - `display-results` - Outputs the energy results to the`$GITHUB_STEP_SUMMARY`. Creates a table that shows the energy results of all the get-measurements, and then a final row for the entire run. Displays the avergae cpu utilization, the total Joules used, and average wattage for each measurment+total run. It will also display a graph of the energy used, and a badge for you to display. - This badge will always be updated to display the total energy of the most recent run of the workflow that generated this badge. - The total measurement of this task is provided as output `data-total-json` in json format (see example below). + - Can be used with `pr-comment` flag (see below) to post the results as a comment on the PR. - `branch`: (optional) (default: ${{ github.ref_name }}) - Used with `get_measurement` and `display_results` to correctly identify this CI run for the Badge. - `label`: (optional) (default: 'measurement ##') @@ -94,6 +95,9 @@ jobs: - used with display-results - Shows the badge for the ci run during display-results step - 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 #### Continuing on Errors diff --git a/action.yml b/action.yml index f8b5a41..693053a 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,9 @@ inputs: description: 'Shows the badge for the ci run during display-results step' default: true required: false + pr-comment: + description: 'Add a comment to the PR with the results during display-results step' + default: false outputs: data-total-json: description: "Contains the data of the total measurement which is retrieved by the 'display-results' task." @@ -51,6 +54,22 @@ runs: name: Setup shell: bash run: | + if command -v python3 &>/dev/null; then + echo "Python is already installed." + else + echo "Python is not installed. Installing..." + apt-get update + apt-get install -y python3.10 python3.10-venv + echo "Python has been installed." + fi + + python_version=$(python3 --version 2>&1) + python_major_version=$(python3 -c 'import sys; print(sys.version_info[0])') + python_minor_version=$(python3 -c 'import sys; print(sys.version_info[1])') + python_cache_path="${base_root}venv/lib/python${python_major_version}.${python_minor_version}/site-packages" + echo "python_cache_path=$python_cache_path" >> $GITHUB_OUTPUT + + # call the initialize function of setup.sh ${{github.action_path}}/scripts/setup.sh initialize -g ${{inputs.display-graph}} @@ -72,7 +91,7 @@ runs: cache-name: cache-pip-packages with: # npm cache files are stored in `~/.npm` on Linux/macOS - path: /tmp/eco-ci/venv/lib/python3.10/site-packages + path: ${{ steps.initialize.outputs.python_cache_path }} key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.hash-requirements.outputs.myhash }} restore-keys: | ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.hash-requirements.outputs.myhash }} @@ -123,4 +142,20 @@ runs: ${{github.action_path}}/scripts/display_results.sh -dt ${{inputs.display-table}} -dg ${{inputs.display-graph}} -db ${{inputs.display-badge}} -b "${{inputs.branch}}" -r ${{ github.run_id }} -R "${{ github.repository }}" -sd ${{inputs.send-data}} -s "github" cat "/tmp/eco-ci/output.txt" >> $GITHUB_STEP_SUMMARY total_data_file="/tmp/eco-ci/total-data.json" - echo "data-total-json=$(cat $total_data_file)" >> $GITHUB_OUTPUT \ No newline at end of file + echo "data-total-json=$(cat $total_data_file)" >> $GITHUB_OUTPUT + + - if: github.event_name == 'pull_request' && inputs.task == 'display-results' && inputs.pr-comment == 'true' + name: Comment on Pull Request + id: pr-comment + shell: bash + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + COMMENT=$(cat "/tmp/eco-ci/output-multiline.txt") + + API_URL="${{ github.api_url }}/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" + curl -X POST -H "Authorization: Bearer ${{github.token}}" -d @- $API_URL < /tmp/eco-ci/energy.txt + cat /tmp/eco-ci/cpu-util.txt | python3. /tmp/eco-ci/spec-power-model/xgb.py --silent | tee -a /tmp/eco-ci/energy-total.txt > /tmp/eco-ci/energy.txt else - cat /tmp/eco-ci/cpu-util.txt | python3.10 /tmp/eco-ci/spec-power-model/xgb.py \ + cat /tmp/eco-ci/cpu-util.txt | python3 /tmp/eco-ci/spec-power-model/xgb.py \ --tdp $TDP --cpu-threads $CPU_THREADS \ --cpu-cores $CPU_CORES --cpu-make $CPU_MAKE \ --release-year $RELEASE_YEAR --ram $RAM \ @@ -50,6 +51,22 @@ function display_results { max_measurement_number=$measurement_number done + echo "Eco-Ci Output:

" >> $output_multiline + echo "Total Energy [Joules]: $total_energy
" >> $output_multiline + echo "Total Avg. CPU Utilization: $cpu_avg
" >> $output_multiline + echo "Total Avg. Power [Watts]: $power_avg
" >> $output_multiline + echo "Total Duration [seconds]: $time
" >> $output_multiline + echo "--------------------------------
" >> $output_multiline + + for (( i=1; i<=$max_measurement_number; i++ )); do + echo "Label $i: $(eval echo \$label_$i)
" >> $output_multiline + echo "Energy Used [Joules]: $(eval echo \$total_energy_$i)
" >> $output_multiline + echo "Avg. CPU Utilization: $(eval echo \$cpu_avg_$i)
" >> $output_multiline + echo "Avg. Power [Watts]: $(eval echo \$power_avg_$i)
" >> $output_multiline + echo "Duration [seconds]: $(eval echo \$time_$i)
" >> $output_multiline + echo "--------------------------------
" >> $output_multiline + done + if [[ $source == 'github' ]]; then echo "|Label|🖥 avg. CPU utilization [%]|🔋 Total Energy [Joules]|🔌 avg. Power [Watts]|Duration [Seconds]|" >> $output echo "|---|---|---|---|---|" >> $output @@ -63,20 +80,7 @@ function display_results { # echo -e "$final_line" >> $output echo '' >> $output elif [[ $source == 'gitlab' ]]; then - echo "Total Energy [Joules]: $total_energy" >> $output - echo "Total Avg. CPU Utilization: $cpu_avg" >> $output - echo "Total Avg. Power [Watts]: $power_avg" >> $output - echo "Total Duration [seconds]: $time" >> $output - echo "----------------" >> $output - - for (( i=1; i<=$max_measurement_number; i++ )); do - echo "Label $i: $(eval echo \$label_$i)" >> $output - echo "Energy Used [Joules]: $(eval echo \$total_energy_$i)" >> $output - echo "Avg. CPU Utilization: $(eval echo \$cpu_avg_$i)" >> $output - echo "Avg. Power [Watts]: $(eval echo \$power_avg_$i)" >> $output - echo "Duration [seconds]: $(eval echo \$time_$i)" >> $output - echo "----------------" >> $output - done + echo $(cat "/tmp/eco-ci/output-short.txt") >> $output fi diff --git a/scripts/make_measurement.sh b/scripts/make_measurement.sh index 64c0f7c..a648dcd 100755 --- a/scripts/make_measurement.sh +++ b/scripts/make_measurement.sh @@ -18,9 +18,9 @@ function make_measurement() { ## make a note that we cannot use --energy, skew the result as we do not have an input delay. # this works because demo-reporter is 1/second if [[ "$MODEL_NAME" == "unknown" ]]; then - cat /tmp/eco-ci/cpu-util.txt | python3.10 /tmp/eco-ci/spec-power-model/xgb.py --silent | tee -a /tmp/eco-ci/energy-total.txt > /tmp/eco-ci/energy.txt + cat /tmp/eco-ci/cpu-util.txt | python3 /tmp/eco-ci/spec-power-model/xgb.py --silent | tee -a /tmp/eco-ci/energy-total.txt > /tmp/eco-ci/energy.txt else - cat /tmp/eco-ci/cpu-util.txt | python3.10 /tmp/eco-ci/spec-power-model/xgb.py \ + cat /tmp/eco-ci/cpu-util.txt | python3 /tmp/eco-ci/spec-power-model/xgb.py \ --tdp $TDP --cpu-threads $CPU_THREADS \ --cpu-cores $CPU_CORES --cpu-make $CPU_MAKE \ --release-year $RELEASE_YEAR --ram $RAM \ diff --git a/scripts/setup.sh b/scripts/setup.sh index 80c7ea4..23f6506 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -37,7 +37,7 @@ function initialize { function setup_python { # Create a venv, and backup old - python3.10 -m venv /tmp/eco-ci/venv + python3 -m venv /tmp/eco-ci/venv if [[ $VIRTUAL_ENV != '' ]]; then $PREVIOUS_VENV=$VIRTUAL_ENV @@ -47,7 +47,7 @@ function setup_python { # Installing requirements # first activate our venv source /tmp/eco-ci/venv/bin/activate - python3.10 -m pip install -r /tmp/eco-ci/spec-power-model/requirements.txt + python3 -m pip install -r /tmp/eco-ci/spec-power-model/requirements.txt # now reset to old venv deactivate our venv # reactivate the old one, if it was present