Skip to content

Commit cb19d89

Browse files
release: 1.9.3
1 parent afa9191 commit cb19d89

7 files changed

Lines changed: 44 additions & 14 deletions

File tree

check_grid.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
DEFAULT_JOB_DURATION_HOURS,
6868
DEFAULT_TIMEOUT,
6969
GLOBAL_AVG_INTENSITY,
70+
ci_secret_hint,
7071
last_failure_reason,
7172
)
7273
from providers.runners import (
@@ -340,15 +341,17 @@ def _emit_token_warnings(zones_config, emaps_api_key, entsoe_token):
340341
extra = f" (+{len(needs_emaps) - 5} more)" if len(needs_emaps) > 5 else ""
341342
print(
342343
f"::notice::Zones [{zones_str}{extra}] need electricity_maps_token. "
343-
f"Get free at https://portal.electricitymaps.com/"
344+
f"Get free at https://portal.electricitymaps.com/ "
345+
f"and {ci_secret_hint('electricity_maps_token')}."
344346
)
345347

346348
if needs_entsoe:
347349
zones_str = ", ".join(needs_entsoe[:5])
348350
extra = f" (+{len(needs_entsoe) - 5} more)" if len(needs_entsoe) > 5 else ""
349351
print(
350352
f"::notice::Zones [{zones_str}{extra}] would use ENTSO-E with entsoe_token. "
351-
f"Get free at https://transparency.entsoe.eu/"
353+
f"Get free at https://transparency.entsoe.eu/ "
354+
f"and {ci_secret_hint('entsoe_token')}."
352355
)
353356

354357

providers/base.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,22 @@ def iso_now() -> str:
544544
def github_headers(token: str) -> dict:
545545
"""Standard bearer auth + accept headers for the GitHub REST API."""
546546
return {"Authorization": f"Bearer {token}", "Accept": "application/vnd.github+json"}
547+
548+
549+
_CI_SECRET_INSTRUCTIONS = {
550+
"GITHUB_ACTIONS": "Settings -> Secrets and variables -> Actions",
551+
"GITLAB_CI": "Settings -> CI/CD -> Variables",
552+
"CIRCLECI": "Project Settings -> Environment Variables",
553+
"BITBUCKET_BUILD_NUMBER": "Repository settings -> Pipelines -> Repository variables",
554+
"TF_BUILD": "Pipeline -> Edit -> Variables",
555+
"TRAVIS": "Repository Settings -> Environment Variables",
556+
"JENKINS_URL": "Manage Jenkins -> Credentials (or pipeline environment block)",
557+
}
558+
559+
560+
def ci_secret_hint(secret_name: str) -> str:
561+
"""Return a platform-specific hint for where to add a CI secret."""
562+
for env_var, location in _CI_SECRET_INSTRUCTIONS.items():
563+
if os.environ.get(env_var):
564+
return f"add it as a secret named {secret_name} ({location})"
565+
return f"set {secret_name} as a secret or environment variable in your CI/CD platform"

providers/eia.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
EIA_EMISSION_FACTORS,
88
EIA_STORAGE_FUELS,
99
api_request,
10+
ci_secret_hint,
1011
compute_trend,
1112
green_result,
1213
)
@@ -108,7 +109,8 @@ def check_carbon_intensity(zone, max_carbon, eia_api_key=""):
108109
if api_key == "DEMO_KEY":
109110
print(
110111
"::notice::Using built-in EIA DEMO_KEY (rate limit ~30 req/hr). "
111-
"For higher limits, register a free key at https://www.eia.gov/opendata/register.php"
112+
"For higher limits, register a free key at https://www.eia.gov/opendata/register.php "
113+
f"and {ci_secret_hint('EIA_API_KEY')}."
112114
)
113115
url = (
114116
f"{EIA_API_BASE}/electricity/rto/fuel-type-data/data"

providers/electricity_maps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sold per country/year, not a cheap flat key.
1313
"""
1414

15-
from providers.base import api_request_with_header, compute_trend, green_result
15+
from providers.base import api_request_with_header, ci_secret_hint, compute_trend, green_result
1616

1717
EMAPS_API_BASE = "https://api-access.electricitymaps.com/free-tier"
1818

@@ -25,8 +25,8 @@ def check_carbon_intensity(zone, max_carbon, emaps_api_key):
2525
if not emaps_api_key:
2626
print(
2727
f"::error::Electricity Maps API token required for zone '{zone}'. "
28-
"Get a free token in 30 seconds at https://portal.electricitymaps.com/ "
29-
"and set the electricity_maps_token input."
28+
"Get a free token at https://portal.electricitymaps.com/ "
29+
f"and {ci_secret_hint('electricity_maps_token')}."
3030
)
3131
return None, None
3232

providers/entsoe.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import xml.etree.ElementTree as ET
1111
from datetime import datetime, timedelta, timezone
1212

13-
from providers.base import DEFAULT_FUEL_FACTOR, FUEL_FACTORS, green_result, request
13+
from providers.base import DEFAULT_FUEL_FACTOR, FUEL_FACTORS, ci_secret_hint, green_result, request
1414

1515
ENTSOE_API_BASE = "https://web-api.tp.entsoe.eu/api"
1616

@@ -269,10 +269,13 @@ def check_carbon_intensity(zone, max_carbon, entsoe_token):
269269
Returns (is_green, intensity) or (None, None) on error.
270270
"""
271271
if not entsoe_token:
272+
reg_url = (
273+
"https://transparency.entsoe.eu/ (Login -> Account Settings -> Web API Security Token)"
274+
)
272275
print(
273276
f"::error::ENTSO-E security token required for zone '{zone}'. "
274-
"Register free at https://transparency.entsoe.eu/ → Login → "
275-
"Account Settings → Web API Security Token."
277+
f"Register free at {reg_url} "
278+
f"and {ci_secret_hint('entsoe_token')}."
276279
)
277280
return None, None
278281

@@ -304,10 +307,13 @@ def check_carbon_intensity(zone, max_carbon, entsoe_token):
304307
return None, None
305308

306309
if response.status_code == 401:
310+
reg_url = (
311+
"https://transparency.entsoe.eu/ (Login -> Account Settings -> Web API Security Token)"
312+
)
307313
print(
308-
"::error::ENTSO-E authentication failed. Check your entsoe_token secret. "
309-
"Get a free token at https://transparency.entsoe.eu/ → Account Settings → "
310-
"Web API Security Token."
314+
"::error::ENTSO-E authentication failed. "
315+
f"{ci_secret_hint('entsoe_token').capitalize()}. "
316+
f"Get a free token at {reg_url}."
311317
)
312318
return None, None
313319

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "carbon-aware-dispatcher"
7-
version = "1.9.2"
7+
version = "1.9.3"
88
description = "Run CI/CD only when the energy grid is clean. Free, zero-config carbon-aware scheduling for US, UK and more"
99
readme = "README.md"
1010
license = "MIT"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)