/
version_consistency.py
63 lines (46 loc) · 2.52 KB
/
version_consistency.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
54
55
56
57
58
59
60
61
62
63
import os
def version_consistency(self):
"""Pipeline and container version number consistency.
.. note:: This test only runs when the ``--release`` flag is set for ``nf-core lint``,
or ``$GITHUB_REF`` is equal to ``master``.
This lint fetches the pipeline version number from three possible locations:
* The pipeline config, ``manifest.version``
* The docker container in the pipeline config, ``process.container``
* Some pipelines may not have this set on a pipeline level. If it is not found, it is ignored.
* ``$GITHUB_REF``, if it looks like a release tag (``refs/tags/<something>``)
The test then checks that:
* The container name has a tag specified (eg. ``nfcore/pipeline:version``)
* The pipeline version number is numeric (contains only numbers and dots)
* That the version numbers all match one another
"""
passed = []
failed = []
# Get the version definitions
# Get version from nextflow.config
versions = {}
versions["manifest.version"] = self.nf_config.get("manifest.version", "").strip(" '\"")
# Get version from the docker tag
if self.nf_config.get("process.container", "") and ":" not in self.nf_config.get("process.container", ""):
failed.append(f"Docker slug seems not to have a version tag: {self.nf_config.get('process.container', '')}")
# Get config container tag (if set; one container per workflow)
if self.nf_config.get("process.container", ""):
versions["process.container"] = self.nf_config.get("process.container", "").strip(" '\"").split(":")[-1]
# Get version from the $GITHUB_REF env var if this is a release
if (
os.environ.get("GITHUB_REF", "").startswith("refs/tags/")
and os.environ.get("GITHUB_REPOSITORY", "") != "nf-core/tools"
):
versions["GITHUB_REF"] = os.path.basename(os.environ["GITHUB_REF"].strip(" '\""))
# Check if they are all numeric
for v_type, version in versions.items():
if not version.replace(".", "").isdigit():
failed.append(f"{v_type} was not numeric: {version}!")
# Check if they are consistent
if len(set(versions.values())) != 1:
failed.append(
"The versioning is not consistent between container, release tag " "and config. Found {}".format(
", ".join([f"{k} = {v}" for k, v in versions.items()])
)
)
passed.append("Version tags are numeric and consistent between container, release tag and config.")
return {"passed": passed, "failed": failed}