|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# This code is part of Qiskit Experiments. |
| 4 | +# |
| 5 | +# (C) Copyright IBM 2025. |
| 6 | +# |
| 7 | +# This code is licensed under the Apache License, Version 2.0. You may |
| 8 | +# obtain a copy of this license in the LICENSE.txt file in the root directory |
| 9 | +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. |
| 10 | +# |
| 11 | +# Any modifications or derivative works of this code must retain this |
| 12 | +# copyright notice, and modified files need to carry a notice indicating |
| 13 | +# that they have been altered from the originals. |
| 14 | + |
| 15 | +"""Check that the highest git version tag on the repo matches the current version""" |
| 16 | + |
| 17 | +import re |
| 18 | +import subprocess |
| 19 | +import sys |
| 20 | +from pathlib import Path |
| 21 | + |
| 22 | + |
| 23 | +version_pattern = re.compile(r"^\d+(\.\d+)*$") |
| 24 | + |
| 25 | + |
| 26 | +def _main(): |
| 27 | + """Return True if VERSION.txt matches a tag higher than any other version tag |
| 28 | +
|
| 29 | + NOTE: this function is primarily intended for the docs publishing automated |
| 30 | + workflow. It retruns true even if the current commit is not tagged with the |
| 31 | + latest version tag. It works this way so that a follow up commit can be |
| 32 | + pushed to fix a possible error in the docs publishing workflow without |
| 33 | + needing to tag again with a higher verison number just for the docs. |
| 34 | + """ |
| 35 | + proc = subprocess.run( |
| 36 | + ["git", "rev-parse", "--show-toplevel"], check=True, text=True, capture_output=True |
| 37 | + ) |
| 38 | + repo_base = Path(proc.stdout.strip()) |
| 39 | + |
| 40 | + proc = subprocess.run(["git", "tag", "--list"], check=True, text=True, capture_output=True) |
| 41 | + all_tags = [t.strip() for t in proc.stdout.splitlines()] |
| 42 | + all_tags = [t for t in all_tags if version_pattern.match(t)] |
| 43 | + highest_version = max(all_tags, key=lambda t: tuple(int(p) for p in t.split("."))) |
| 44 | + |
| 45 | + version = (repo_base / "qiskit_experiments/VERSION.txt").read_text().strip() |
| 46 | + |
| 47 | + if version != highest_version: |
| 48 | + return False |
| 49 | + |
| 50 | + return True |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + if not _main(): |
| 55 | + sys.exit(1) |
0 commit comments