Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
- '3.13'
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install requirements
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
uses: rlespinasse/github-slug-action@v5
- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
Expand Down
21 changes: 21 additions & 0 deletions decoder/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,27 @@ def get_environment_assets(job_definition: Dict[str, Any]) -> List[Dict[str, str
return env_assets


def get_environment_constants(job_definition: Dict[str, Any]) -> List[Dict[str, str]]:
"""Given a Job definition this function returns the list of all the
environment-based image constants declared. What's returned is a list
of the environment variable's name and its value.
"""
env_constants: List[Dict[str, str]] = []
# Iterate through the environment block...
environment: List[Dict[str, Any]] = job_definition.get("image", {}).get(
"environment", []
)
env_constants.extend(
{
item["name"]: item["value-from"]["constant"]["value"],
}
for item in environment
if "constant" in item["value-from"]
)

return env_constants


def get_jobs_replaced(job_definition: Dict[str, Any]) -> Optional[List[str]]:
"""Given a Job Definition this function returns the Jobs it replaces.
The returned list is a list of jobs identified by collection and
Expand Down
29 changes: 29 additions & 0 deletions tests/test_get_environment_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Tests for the decoder's get_environment_assets() function.
from typing import Dict

import pytest

pytestmark = pytest.mark.unit

from decoder import decoder


def test_get_environment_constants():
# Arrange
job_definition: Dict = {
"image": {
"environment": [
{
"name": "BLOB",
"value-from": {"constant": {"value": "42"}},
}
],
},
}

# Act
env_assets = decoder.get_environment_constants(job_definition)

# Assert
assert len(env_assets) == 1
assert env_assets[0]["BLOB"] == "42"