Hasan Iqbal commited on
Commit
790a3cd
1 Parent(s): eb7660a

Added script to bookkeep doc versions

Browse files
docs/scripts/bumpversion.sh ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ source "${BASH_SOURCE%/*}/../../scripts/common.sh"
4
+
5
+ # Configurable variables
6
+ ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")/../..")
7
+ WEBSITE_HOME="https://openfactcheck.readthedocs.io/en"
8
+ DOCS_HOME="docs"
9
+ DOCS_LATEST="latest"
10
+ DOCS_ROOT="$ROOT/$DOCS_HOME"
11
+ DOCS_DEST="$ROOT/public"
12
+ VERSION_FILE="$DOCS_ROOT/src/_static/versions.json"
13
+
14
+ # Formats a version entry
15
+ function format_version_entry {
16
+ local version=$1
17
+ echo "{\"name\": \"$version\", \"version\": \"v$version\", \"url\": \"$WEBSITE_HOME/$version/\"}"
18
+ }
19
+
20
+ # Formats the development version entry
21
+ function format_dev_version_entry {
22
+ echo "{\"version\": \"dev\", \"url\": \"$WEBSITE_HOME/latest/\"}"
23
+ }
24
+
25
+ # Formats the stable version entry
26
+ function format_stable_version_entry {
27
+ local version=$1
28
+ echo "{\"name\": \"$version (stable)\", \"version\": \"v$version\", \"url\": \"$WEBSITE_HOME/stable/\", \"preferred\": true}"
29
+ }
30
+
31
+ # Retrieves versions from versions.json
32
+ function get_versions {
33
+ jq -r '.[] | .name' "$VERSION_FILE"
34
+ }
35
+
36
+ # Generate the version.json file
37
+ function generate_versions_file {
38
+ local versions=$(get_versions)
39
+ local entries=($(format_dev_version_entry))
40
+
41
+ for version in $versions; do
42
+ entries+=($(format_version_entry "$version"))
43
+ done
44
+
45
+ echo "${entries[@]}" | jq -s '.' > "$DOCS_DEST/version.json"
46
+ }
47
+
48
+ # Initialize default values
49
+ dry_run=0
50
+ new_version=""
51
+
52
+ # Function to show help message
53
+ function show_help {
54
+ echo "Usage: $0 [-d|--dryrun] -n|--new-version <version>"
55
+ echo " -d, --dryrun: Dry run; do not write any changes, just print the output."
56
+ echo " -n, --new-version: Specify the new version to be added. This is a required argument."
57
+ }
58
+
59
+ # Manual parsing of command-line options
60
+ while [[ $# -gt 0 ]]; do
61
+ case "$1" in
62
+ (-d|--dryrun)
63
+ dry_run=1
64
+ shift
65
+ ;;
66
+ (-n|--new-version)
67
+ if [[ -n "$2" ]]; then
68
+ new_version="$2"
69
+ shift 2
70
+ else
71
+ echo "Error: Argument for $1 is missing."
72
+ show_help
73
+ exit 1
74
+ fi
75
+ ;;
76
+ (-h|--help)
77
+ show_help
78
+ exit 0
79
+ ;;
80
+ (*)
81
+ echo "Invalid option: $1"
82
+ show_help
83
+ exit 1
84
+ ;;
85
+ esac
86
+ done
87
+
88
+ # Check if new version was specified
89
+ if [[ -z "$new_version" ]]; then
90
+ echo "Error: -n|--new-version is required."
91
+ show_help
92
+ exit 1
93
+ fi
94
+
95
+ # Check if new version was specified
96
+ if [[ -z "$new_version" ]]; then
97
+ echo "Error: -n new_version is required."
98
+ show_help
99
+ exit 1
100
+ fi
101
+
102
+ # Check the last stable version
103
+ current_versions=$(get_versions)
104
+ stable_version=$(echo "$current_versions" | tail -n +2 | head -n 1 | cut -d' ' -f1)
105
+ echo "Last Stable version: $stable_version"
106
+
107
+ # Check the old versions
108
+ old_versions=($(echo "$current_versions" | tail -n +3))
109
+ old_versions+=("$stable_version")
110
+ old_versions=($(printf '%s\n' "${old_versions[@]}" | tac))
111
+ echo "Old versions: ${old_versions[*]}"
112
+
113
+ # Create new version entry
114
+ if echo "${old_versions[@]}" | grep -q "$new_version"; then
115
+ echo "Version $new_version already exists in versions.json"
116
+ exit 1
117
+ fi
118
+
119
+ entries=( $(format_dev_version_entry) $(format_stable_version_entry "$new_version") )
120
+ for version in ${old_versions[@]}; do
121
+ entries+=( $(format_version_entry "$version") )
122
+ done
123
+
124
+ if [ "$dry_run" -eq 1 ]; then
125
+ echo "$(echo ${entries[@]} | jq -s '.')"
126
+ else
127
+ echo "Writing to versions.json"
128
+ echo "$(echo ${entries[@]} | jq -s '.')" > "$VERSION_FILE"
129
+ fi
docs/src/_static/versions.json CHANGED
@@ -1,12 +1,12 @@
1
  [
2
- {
3
- "version": "dev",
4
- "url": "https://openfactcheck.readthedocs.io/en/latest/"
5
- },
6
- {
7
- "name": "0.2.2 (stable)",
8
- "version": "v0.2.2",
9
- "url": "https://openfactcheck.readthedocs.io/en/stable/",
10
- "preferred": true
11
- }
12
  ]
 
1
  [
2
+ {
3
+ "version": "dev",
4
+ "url": "https://openfactcheck.readthedocs.io/en/latest/"
5
+ },
6
+ {
7
+ "name": "0.2.2 (stable)",
8
+ "version": "v0.2.2",
9
+ "url": "https://openfactcheck.readthedocs.io/en/stable/",
10
+ "preferred": true
11
+ }
12
  ]
docs/src/conf.py CHANGED
@@ -127,6 +127,7 @@ json_url = "https://openfactcheck.readthedocs.io/en/latest/_static/versions.json
127
  # Define the version we use for matching in the version switcher.
128
  version_match = os.environ.get("READTHEDOCS_VERSION")
129
  release = openfactcheck.__version__
 
130
  # If READTHEDOCS_VERSION doesn't exist, we're not on RTD
131
  # If it is an integer, we're in a PR build and the version isn't correct.
132
  # If it's "latest" → change to "dev" (that's what we want the switcher to call it)
@@ -136,7 +137,7 @@ if not version_match or version_match.isdigit() or version_match == "latest":
136
  version_match = "dev"
137
  # We want to keep the relative reference if we are in dev mode
138
  # but we want the whole url if we are effectively in a released version
139
- json_url = "_static/switcher.json"
140
  else:
141
  version_match = f"v{release}"
142
  elif version_match == "stable":
@@ -174,7 +175,7 @@ html_theme_options = {
174
  "navbar_align": "left", # [left, content, right] For testing that the navbar items align properly
175
  # "show_nav_level": 2,
176
  # "announcement": "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/_templates/custom-template.html",
177
- # "show_version_warning_banner": True,
178
  # "navbar_center": ["navbar-nav"],
179
  # "navbar_start": ["navbar-logo"],
180
  "navbar_end": ["version-switcher", "theme-switcher", "navbar-icon-links"],
 
127
  # Define the version we use for matching in the version switcher.
128
  version_match = os.environ.get("READTHEDOCS_VERSION")
129
  release = openfactcheck.__version__
130
+
131
  # If READTHEDOCS_VERSION doesn't exist, we're not on RTD
132
  # If it is an integer, we're in a PR build and the version isn't correct.
133
  # If it's "latest" → change to "dev" (that's what we want the switcher to call it)
 
137
  version_match = "dev"
138
  # We want to keep the relative reference if we are in dev mode
139
  # but we want the whole url if we are effectively in a released version
140
+ json_url = "_static/versions.json"
141
  else:
142
  version_match = f"v{release}"
143
  elif version_match == "stable":
 
175
  "navbar_align": "left", # [left, content, right] For testing that the navbar items align properly
176
  # "show_nav_level": 2,
177
  # "announcement": "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/_templates/custom-template.html",
178
+ "show_version_warning_banner": True,
179
  # "navbar_center": ["navbar-nav"],
180
  # "navbar_start": ["navbar-logo"],
181
  "navbar_end": ["version-switcher", "theme-switcher", "navbar-icon-links"],
docs/versions.py DELETED
@@ -1,42 +0,0 @@
1
- """Module for generating switch.json file."""
2
-
3
- #!/usr/bin/env python3
4
- from __future__ import annotations
5
-
6
- import json
7
- import os
8
-
9
- ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
10
- WEBSITE_HOME = "https://openfactcheck.readthedocs.io/en/"
11
- DOCS_HOME = "docs"
12
- DOCS_LATEST = "latest"
13
- DOCS_ROOT = os.path.join(ROOT, DOCS_HOME)
14
- DOCS_DEST = os.path.join(ROOT, "public")
15
- VERSION_FILE = os.path.join(DOCS_ROOT, "src", "_static", "versions.json")
16
-
17
-
18
- def format_version_entry(version: str) -> dict[str, str]:
19
- """Format a single entry of switcher.json, as expected by `pydata-sphinx-theme`."""
20
- return {
21
- "url": "/".join((WEBSITE_HOME, version, "")),
22
- "version": version,
23
- }
24
-
25
-
26
- def validate_docs_folder(path: str) -> bool:
27
- """Check that folder with path specified contains valid documentation."""
28
- return os.path.isdir(path) and os.path.isfile(os.path.join(path, "index.html"))
29
-
30
-
31
- def get_versions() -> list[str]:
32
- """List available versions of the package in the expected order."""
33
- with open(VERSION_FILE) as infile:
34
- versions = json.load(infile)
35
-
36
- print("Available versions:")
37
- for version in versions:
38
- print(f" - {version}")
39
-
40
-
41
- if __name__ == "__main__":
42
- get_versions()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/release.sh CHANGED
@@ -104,6 +104,7 @@ echo
104
  # Modify the VERSION file
105
  printf "$VERSION" > ./VERSION
106
  bump2version patch --new-version $VERSION_BUMP --allow-dirty --verbose
 
107
 
108
  # Commit and tag the release
109
  git add ./VERSION
@@ -111,6 +112,7 @@ git add ./.bumpversion.cfg
111
  git add ./pyproject.toml
112
  git add ./pre-requirements.txt
113
  git add ./src/openfactcheck/__init__.py
 
114
  git commit -m "🚀 $MESSAGE"
115
  git tag $VERSION
116
  git push origin $BRANCH
 
104
  # Modify the VERSION file
105
  printf "$VERSION" > ./VERSION
106
  bump2version patch --new-version $VERSION_BUMP --allow-dirty --verbose
107
+ ./docs/scripts/bumpversion.sh --new-version $VERSION_BUMP
108
 
109
  # Commit and tag the release
110
  git add ./VERSION
 
112
  git add ./pyproject.toml
113
  git add ./pre-requirements.txt
114
  git add ./src/openfactcheck/__init__.py
115
+ git add ./docs/src/_static/versions.json
116
  git commit -m "🚀 $MESSAGE"
117
  git tag $VERSION
118
  git push origin $BRANCH