Skip to content

Commit

Permalink
Merge pull request #375 from opensafely-core/action-images
Browse files Browse the repository at this point in the history
Add Pipeline.action_images property
  • Loading branch information
bloodearnest authored Feb 7, 2025
2 parents 0bf6ebb + 9702f1d commit b0fb3f6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pipeline/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,19 @@ def all_actions(self) -> list[str]:
than set operators as previously so we preserve the original order.
"""
return [action for action in self.actions.keys() if action != RUN_ALL_COMMAND]

@property
def action_images(self) -> set[str]:
"""
Get all unique action images/version used in this project.
This is useful for tooling to know which image version to support.
"""
images = set()
for action in self.actions.values():
# for hysterical raisins, :latest is actually mapped to v1, not v2 or later.
# We hope to fix this at some point
version = "v1" if action.run.version == "latest" else action.run.version
images.add(f"{action.run.name}:{version}")

return images
35 changes: 35 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,38 @@ def test_action_is_database_action(name, run, is_database_action):

action = Pipeline.build(**data).actions[name]
assert action.is_database_action == is_database_action


def test_action_images():
data = {
"version": 1,
"actions": {
"ehrql": {
"run": "ehrql:v1 ...",
"outputs": {
"highly_sensitive": {"cohort": "output/input.csv"},
},
},
"r1": {
"run": "r:latest 1",
"outputs": {
"highly_sensitive": {"cohort": "output/input.csv"},
},
},
"r2": {
"run": "r:latest 2",
"outputs": {
"highly_sensitive": {"cohort": "output/input.csv"},
},
},
"python": {
"run": "python:v2 ...",
"outputs": {
"highly_sensitive": {"cohort": "output/input.csv"},
},
},
},
}

pipeline = Pipeline.build(**data)
assert pipeline.action_images == set(["ehrql:v1", "r:v1", "python:v2"])

0 comments on commit b0fb3f6

Please sign in to comment.