Skip to content

Commit

Permalink
Integrate energy measurements (#1863)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Adds an Action for estimating the energy usage and carbon emissions of
our CI events
* Addresses a small but rare `pytest` teardown race condition

### Does this PR introduce a breaking change?

No.

### Other information:

https://github.com/green-coding-solutions/eco-ci-energy-estimation
  • Loading branch information
Zeitsperre authored Nov 22, 2024
2 parents aaf115c + e05cfb3 commit 4f00c08
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 32 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,38 @@ jobs:
egress-policy: block
allowed-endpoints: >
api.deps.dev:443
api.electricitymap.org:443
api.github.com:443
api.green-coding.io:443
api.securityscorecards.dev:443
github.com:443
ip-api.com:80
ipapi.co:443
proxy.golang.org:443
pypi.org:443
sum.golang.org:443
- name: Start Energy Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: start-measurement
branch: ${{ github.head_ref || github.ref_name }}

- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Dependency Review
uses: actions/dependency-review-action@4081bf99e2866ebe428fc0477b69eb4fcda7220a # v4.4.0

- name: Energy Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Dependency Review'
continue-on-error: true

- name: Show Energy Results
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: display-results
continue-on-error: true
183 changes: 158 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,22 @@ jobs:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.electricitymap.org:443
api.github.com:443
api.green-coding.io:443
files.pythonhosted.org:443
github.com:443
ip-api.com:80
ipapi.co:443
proxy.golang.org:443
pypi.org:443
sum.golang.org:443
- name: Start Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: start-measurement
branch: ${{ github.head_ref || github.ref_name }}
continue-on-error: true
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python3
Expand All @@ -58,6 +71,12 @@ jobs:
- name: Install CI libraries
run: |
python -m pip install --require-hashes -r CI/requirements_ci.txt
- name: Setup Python Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Environment setup (Python${{ matrix.python-version }}, lint)'
continue-on-error: true
- name: Environment Caching
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
Expand All @@ -71,6 +90,17 @@ jobs:
- name: Run linting suite
run: |
python -m tox -e lint
- name: Tests measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Lint (Python${{ matrix.python-version }})'
continue-on-error: true
- name: Show Energy Results
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: display-results
continue-on-error: true

test-preliminary:
name: Python${{ matrix.python-version }} (${{ matrix.os }})
Expand All @@ -88,12 +118,24 @@ jobs:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.electricitymap.org:443
api.github.com:443
dap.service.does.not.exist:443
api.green-coding.io:443
coveralls.io:443
files.pythonhosted.org:443
github.com:443
ip-api.com:80
ipapi.co:443
proxy.golang.org:443
pypi.org:443
raw.githubusercontent.com:443
sum.golang.org:443
- name: Start Energy Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: start-measurement
branch: ${{ github.head_ref || github.ref_name }}
continue-on-error: true
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python${{ matrix.python-version }}
Expand All @@ -104,6 +146,12 @@ jobs:
- name: Install CI libraries
run: |
python -m pip install --require-hashes -r CI/requirements_ci.txt
- name: Environment Setup Energy Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Environment setup (Python${{ matrix.python-version }}, standard)'
continue-on-error: true
- name: Environment Caching
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
Expand All @@ -116,7 +164,19 @@ jobs:
python -m tox -- -m 'not slow'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: run-${{ matrix.python-version }}-ubuntu-latest-preliminary
COVERALLS_PARALLEL: true
- name: Tests measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Testing with tox (Python${{ matrix.python-version }})'
continue-on-error: true
- name: Show Energy Results
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: display-results
continue-on-error: true

test-pypi:
needs: lint
Expand Down Expand Up @@ -180,18 +240,27 @@ jobs:
with:
egress-policy: block
allowed-endpoints: >
api.electricitymap.org:443
api.github.com:443
api.green-coding.io:443
azure.archive.ubuntu.com:80
coveralls.io:443
dap.service.does.not.exist:443
esm.ubuntu.com:443
files.pythonhosted.org:443
github.com:443
ip-api.com:80
ipapi.co:443
motd.ubuntu.com:443
packages.microsoft.com:443
ppa.launchpadcontent.net:443
proxy.golang.org:443
pypi.org:443
raw.githubusercontent.com:443
sum.golang.org:443
- name: Start Energy Measurement
if : ${{ matrix.os == 'ubuntu-latest' }}
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: start-measurement
branch: ${{ github.head_ref || github.ref_name }}
continue-on-error: true
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Eigen3 (SBCK)
Expand All @@ -207,6 +276,13 @@ jobs:
- name: Install CI libraries
run: |
python -m pip install --require-hashes -r CI/requirements_ci.txt
- name: Environment Setup Energy Measurement
if : ${{ matrix.os == 'ubuntu-latest' }}
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Environment setup (Python${{ matrix.python-version }}, ${{ matrix.tox-env }})'
continue-on-error: true
- name: Environment Caching
# if prefetch is not in tox-env
if: contains(matrix.tox-env, 'prefetch') == false
Expand All @@ -232,6 +308,19 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: run-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.tox-env }}
COVERALLS_PARALLEL: true
- name: Tests measurement
if : ${{ matrix.os == 'ubuntu-latest' }}
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Testing with tox (Python${{ matrix.python-version }}, ${{ matrix.tox-env }})'
continue-on-error: true
- name: Show Energy Results
if : ${{ matrix.os == 'ubuntu-latest' }}
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: display-results
continue-on-error: true

test-conda:
needs: lint
Expand All @@ -240,7 +329,7 @@ jobs:
contains(github.event.pull_request.labels.*.name, 'approved') ||
(github.event.review.state == 'approved') ||
(github.event_name == 'push')
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
matrix:
os: [ 'ubuntu-latest' ]
Expand All @@ -256,16 +345,25 @@ jobs:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.electricitymap.org:443
api.github.com:443
conda.anaconda.org:443
api.green-coding.io:443
coveralls.io:443
dap.service.does.not.exist:443
files.pythonhosted.org:443
github.com:443
ip-api.com:80
ipapi.co:443
objects.githubusercontent.com:443
proxy.golang.org:443
pypi.org:443
raw.githubusercontent.com:443
repo.anaconda.com:443
sum.golang.org:443
- name: Start Energy Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: start-measurement
branch: ${{ github.head_ref || github.ref_name }}
continue-on-error: true
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Conda (Micromamba) with Python${{ matrix.python-version }}
Expand All @@ -276,9 +374,6 @@ jobs:
environment-file: environment.yml
create-args: >-
python=${{ matrix.python-version }}
- name: Micromamba version
run: |
echo "micromamba: $(micromamba --version)"
- name: Test Data Caching
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
Expand All @@ -293,42 +388,80 @@ jobs:
micromamba list
xclim show_version_info
python -m pip check || true
- name: Environment Setup Energy Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Environment setup (conda, Python${{ matrix.python-version }})'
continue-on-error: true
- name: Test with pytest
run: |
python -m pytest --numprocesses=logical --durations=10 --cov=xclim --cov-report=term-missing
# - name: Install tox
# shell: bash -l {0}
# run: |
# mamba install -n xclim39 tox tox-conda
# - name: Test
# shell: bash -l {0}
# run: |
# conda activate xclim39
# tox -e opt-slow
# env:
# CONDA_EXE: mamba
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Report coverage
run: |
coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: run-{{ matrix.python-version }}-conda
COVERALLS_PARALLEL: true
- name: Tests measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Testing with pytest (conda, Python${{ matrix.python-version }})'
continue-on-error: true
- name: Show Energy Results
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: display-results
continue-on-error: true

finish:
name: Finish
needs:
- test-preliminary
- test-pypi
- test-conda
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: audit
egress-policy: block
allowed-endpoints: >
api.electricitymap.org:443
api.github.com:443
api.green-coding.io:443
coveralls.io:443
files.pythonhosted.org:443
github.com:443
ip-api.com:80
ipapi.co:443
objects.githubusercontent.com:443
proxy.golang.org:443
pypi.org:443
sum.golang.org:443
- name: Start Energy Measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: start-measurement
branch: ${{ github.head_ref || github.ref_name }}
continue-on-error: true
- name: Coveralls Finished
uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8 # v2.3.4
with:
parallel-finished: true
- name: Finish measurement
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: get-measurement
label: 'Finish Run'
continue-on-error: true
- name: Show Energy Results
uses: green-coding-solutions/eco-ci-energy-estimation@86f1b2ee12db687bca0d15160a529bb64a7b60d9 # v4.0.0
with:
task: display-results
continue-on-error: true
8 changes: 4 additions & 4 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
egress-policy: audit

- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Run Analysis
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
with:
results_file: results.sarif
results_format: sarif
Expand All @@ -59,14 +59,14 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: Upload Artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # 3.23.0
uses: github/codeql-action/upload-sarif@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # 3.23.0
with:
sarif_file: results.sarif
Loading

0 comments on commit 4f00c08

Please sign in to comment.