Skip to content

Commit 216f143

Browse files
authored
Combine stable and release docs workflows (#1570)
Currently, these workflows conflict because they both trigger off a tag and try to push the 'gh-pages' branch. Whichever workflow finishes second always fails. Here we change to push to both places from the stable workflow but only push to the top level directory that the release workflow was pushing when the tag appears to be the latest release. Closes #1554
1 parent 2a60acf commit 216f143

File tree

3 files changed

+68
-37
lines changed

3 files changed

+68
-37
lines changed

.github/workflows/docs_release.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/docs_stable.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,16 @@ jobs:
3636
with:
3737
folder: docs/_build/html
3838
target-folder: stable/${{ env.version }}
39+
- name: Check current tag is the latest
40+
id: check-latest
41+
run: |
42+
python tools/check_latest_version.py
43+
continue-on-error: true
44+
- name: Deploy top level
45+
uses: JamesIves/github-pages-deploy-action@v4
46+
with:
47+
folder: docs/_build/html/
48+
clean-exclude: |
49+
stable/*
50+
dev/*
51+
if: steps.check-latest.outcome == "success"

tools/check_latest_version.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)