-
Notifications
You must be signed in to change notification settings - Fork 183
/
subworkflow_version.py
53 lines (43 loc) · 2.15 KB
/
subworkflow_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Verify that a subworkflow has a correct entry in the modules.json file
"""
import logging
from pathlib import Path
import nf_core
import nf_core.modules.modules_repo
import nf_core.modules.modules_utils
log = logging.getLogger(__name__)
def subworkflow_version(subworkflow_lint_object, subworkflow):
"""
Verifies that the subworkflow has a version specified in the ``modules.json`` file
It checks whether the subworkflow has an entry in the ``modules.json`` file
containing a commit SHA. If that is true, it verifies that there are no
newer version of the subworkflow available.
"""
modules_json_path = Path(subworkflow_lint_object.dir, "modules.json")
# Verify that a git_sha exists in the `modules.json` file for this module
version = subworkflow_lint_object.modules_json.get_subworkflow_version(
subworkflow.component_name, subworkflow.repo_url, subworkflow.org
)
if version is None:
subworkflow.failed.append(("git_sha", "No git_sha entry in `modules.json`", modules_json_path))
return
subworkflow.git_sha = version
subworkflow.passed.append(("git_sha", "Found git_sha entry in `modules.json`", modules_json_path))
# Check whether a new version is available
try:
subworkflow.branch = subworkflow_lint_object.modules_json.get_component_branch(
"subworkflows", subworkflow.component_name, subworkflow.repo_url, subworkflow.org
)
modules_repo = nf_core.modules.modules_repo.ModulesRepo(
remote_url=subworkflow.repo_url, branch=subworkflow.branch
)
subworkflow_git_log = modules_repo.get_component_git_log(subworkflow.component_name, "subworkflows")
if version == next(subworkflow_git_log)["git_sha"]:
subworkflow.passed.append(
("subworkflow_version", "Subworkflow is in the latest version", subworkflow.component_dir)
)
else:
subworkflow.warned.append(("subworkflow_version", "New version available", subworkflow.component_dir))
except UserWarning:
subworkflow.warned.append(("subworkflow_version", "Failed to fetch git log", subworkflow.component_dir))