This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow-site.git
The following commit(s) were added to refs/heads/main by this push:
new 65b06b0677 Add automatic version bumping for sphinx_airflow_theme
(#1464)
65b06b0677 is described below
commit 65b06b0677b7beea48309da7d3968abe84e6f942
Author: Jarek Potiuk <[email protected]>
AuthorDate: Mon Mar 16 23:25:47 2026 +0100
Add automatic version bumping for sphinx_airflow_theme (#1464)
* Add automatic version bumping for sphinx_airflow_theme
Add a pre-commit hook that detects changes to theme files and
automatically bumps the patch version. The CI workflow is updated
to skip theme build/upload/publish when the version is unchanged,
avoiding unnecessary work on non-theme commits.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Rewrite check_and_bump_version in Python with inline script metadata
Replace the bash script with a Python script using PEP 723 inline
script metadata and uv run shebang. Prek handles this natively with
language: script.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
---
.github/workflows/build.yml | 23 +++-
.pre-commit-config.yaml | 6 +
sphinx_airflow_theme/.theme_files_hash | 1 +
sphinx_airflow_theme/LATEST_VERSION.txt | 1 +
sphinx_airflow_theme/check_and_bump_version.py | 128 +++++++++++++++++++++
.../sphinx_airflow_theme/__init__.py | 2 +-
6 files changed, 159 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e85b818620..34472a8cf8 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -160,14 +160,32 @@ jobs:
- name: π§ Copy files from site to theme
run: |
./site.sh prepare-theme
+ - name: π Check if sphinx_airflow_theme changed
+ id: check-theme
+ run: |
+ NEW_VERSION=$(cat sphinx_airflow_theme/LATEST_VERSION.txt | tr -d
'[:space:]')
+ PUBLISHED_VERSION=""
+ if [ -f dist/sphinx-airflow-theme/LATEST_VERSION.txt ]; then
+ PUBLISHED_VERSION=$(cat
dist/sphinx-airflow-theme/LATEST_VERSION.txt | tr -d '[:space:]')
+ fi
+ if [ "${NEW_VERSION}" != "${PUBLISHED_VERSION}" ]; then
+ echo "theme_changed=true" >> "${GITHUB_OUTPUT}"
+ echo "sphinx_airflow_theme version changed: ${PUBLISHED_VERSION}
-> ${NEW_VERSION}"
+ else
+ echo "theme_changed=false" >> "${GITHUB_OUTPUT}"
+ echo "sphinx_airflow_theme version unchanged (${NEW_VERSION}),
skipping theme upload"
+ fi
- name: π§ Prepare sphinx_airflow_theme package οΈ
+ if: steps.check-theme.outputs.theme_changed == 'true'
working-directory: sphinx_airflow_theme
run: |
uv build
- name: π¦ Copy sphinx_airflow_theme package to dist
+ if: steps.check-theme.outputs.theme_changed == 'true'
run: |
mkdir -p dist/sphinx-airflow-theme
cp sphinx_airflow_theme/dist/* dist/sphinx-airflow-theme/
+ cp sphinx_airflow_theme/LATEST_VERSION.txt dist/sphinx-airflow-theme/
- name: πRefresh PMC/COMMITTERS profiles
env:
PMC_COMMITTERS_FILES:
landing-pages/site/data/committers.json,landing-pages/site/data/pmc.json
@@ -194,6 +212,7 @@ jobs:
echo "Running git push to ${PUBLISH_BRANCH} branch"
git push origin ${PUBLISH_BRANCH}
- name: π Upload sphinx_airflow_theme package as artifact
+ if: steps.check-theme.outputs.theme_changed == 'true'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
# v7.0.0
with:
name: airflow-sphinx-theme
@@ -201,12 +220,14 @@ jobs:
if-no-files-found: error
retention-days: 14
- name: π§ Build theme demo
+ if: steps.check-theme.outputs.theme_changed == 'true'
working-directory: sphinx_airflow_theme
run: |
pip install ./dist/sphinx_airflow_theme-*.whl
cd demo
./docs.sh build
- name: π Upload sphinx_airflow_theme demo as artifact
+ if: steps.check-theme.outputs.theme_changed == 'true'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
# v7.0.0
with:
name: airflow-sphinx-theme-demo
@@ -219,7 +240,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_COMMIT: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
- if: env.PROD_PUBLISH_REQUIRED != 'false' ||
env.STAGING_PUBLISH_REQUIRED != 'false'
+ if: steps.check-theme.outputs.theme_changed == 'true' &&
(env.PROD_PUBLISH_REQUIRED != 'false' || env.STAGING_PUBLISH_REQUIRED !=
'false')
run: |
set -x
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index cc90f867a6..0e35322fee 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -136,6 +136,12 @@ repos:
- --fuzzy-match-generates-todo
- repo: local
hooks:
+ - id: check-sphinx-theme-version
+ name: Check and bump sphinx_airflow_theme version if files changed
+ language: script
+ entry: sphinx_airflow_theme/check_and_bump_version.py
+ files: ^sphinx_airflow_theme/
+ pass_filenames: false
- id: shellcheck
name: Check Shell scripts syntax correctness
language: docker_image
diff --git a/sphinx_airflow_theme/.theme_files_hash
b/sphinx_airflow_theme/.theme_files_hash
new file mode 100644
index 0000000000..c3dfc8db26
--- /dev/null
+++ b/sphinx_airflow_theme/.theme_files_hash
@@ -0,0 +1 @@
+07df2243846a413e643fa9ea4ba7faa06cb8431317caa58243b93a011017c0f2
diff --git a/sphinx_airflow_theme/LATEST_VERSION.txt
b/sphinx_airflow_theme/LATEST_VERSION.txt
new file mode 100644
index 0000000000..d15723fbe8
--- /dev/null
+++ b/sphinx_airflow_theme/LATEST_VERSION.txt
@@ -0,0 +1 @@
+0.3.2
diff --git a/sphinx_airflow_theme/check_and_bump_version.py
b/sphinx_airflow_theme/check_and_bump_version.py
new file mode 100755
index 0000000000..09f9b62212
--- /dev/null
+++ b/sphinx_airflow_theme/check_and_bump_version.py
@@ -0,0 +1,128 @@
+#!/usr/bin/env uv run
+# /// script
+# requires-python = ">=3.10"
+# ///
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Pre-commit hook that checks if sphinx_airflow_theme files have changed.
+
+If they have, it bumps the patch version and updates the stored hash.
+"""
+from __future__ import annotations
+
+import hashlib
+import re
+import subprocess
+import sys
+from pathlib import Path
+
+REPO_ROOT = Path(
+ subprocess.check_output(["git", "rev-parse", "--show-toplevel"],
text=True).strip()
+)
+THEME_DIR = REPO_ROOT / "sphinx_airflow_theme"
+THEME_MODULE = THEME_DIR / "sphinx_airflow_theme"
+HASH_FILE = THEME_DIR / ".theme_files_hash"
+VERSION_FILE = THEME_DIR / "LATEST_VERSION.txt"
+INIT_FILE = THEME_MODULE / "__init__.py"
+
+
+def compute_theme_hash() -> str:
+ """Hash all theme files (excluding version lines in __init__.py) plus
pyproject.toml.
+
+ File paths are included as relative paths so the hash is stable regardless
of working directory.
+ """
+ h = hashlib.sha256()
+ for f in sorted(THEME_MODULE.rglob("*")):
+ if not f.is_file():
+ continue
+ relative = f.relative_to(REPO_ROOT)
+ h.update(f"{relative}\n".encode())
+ if f == INIT_FILE:
+ content = "".join(
+ line
+ for line in f.read_text().splitlines(keepends=True)
+ if not line.startswith("__version__") and not
line.startswith("__version_full__")
+ )
+ h.update(hashlib.sha256(content.encode()).hexdigest().encode())
+ h.update(b"\n")
+ else:
+ h.update(hashlib.sha256(f.read_bytes()).hexdigest().encode())
+ h.update(b"\n")
+ pyproject = THEME_DIR / "pyproject.toml"
+ h.update(f"{pyproject.relative_to(REPO_ROOT)}\n".encode())
+ h.update(hashlib.sha256(pyproject.read_bytes()).hexdigest().encode())
+ h.update(b"\n")
+ return h.hexdigest()
+
+
+def get_current_version() -> str:
+ text = INIT_FILE.read_text()
+ match = re.search(r"^__version__ = ['\"]([^'\"]+)['\"]", text,
re.MULTILINE)
+ if not match:
+ raise SystemExit("Could not find __version__ in __init__.py")
+ return match.group(1)
+
+
+def bump_version(version: str) -> str:
+ major, minor, patch = version.split(".")
+ return f"{major}.{minor}.{int(patch) + 1}"
+
+
+def git_add(*paths: Path) -> None:
+ subprocess.check_call(["git", "add", *(str(p) for p in paths)])
+
+
+def main() -> int:
+ current_hash = compute_theme_hash()
+ stored_hash = HASH_FILE.read_text().strip() if HASH_FILE.exists() else ""
+
+ if current_hash == stored_hash:
+ # No changes β just verify version file is in sync
+ current_version = get_current_version()
+ stored_version = VERSION_FILE.read_text().strip() if
VERSION_FILE.exists() else ""
+ if current_version != stored_version:
+ VERSION_FILE.write_text(f"{current_version}\n")
+ git_add(VERSION_FILE)
+ print(f"sphinx_airflow_theme: synced LATEST_VERSION.txt to
{current_version}")
+ return 0
+
+ # Hash changed β bump the patch version
+ current_version = get_current_version()
+ new_version = bump_version(current_version)
+ print(f"sphinx_airflow_theme: files changed, bumping version
{current_version} -> {new_version}")
+
+ # Update __init__.py
+ init_text = INIT_FILE.read_text()
+ init_text = re.sub(r"^__version__ = .*", f"__version__ = '{new_version}'",
init_text, flags=re.MULTILINE)
+ init_text = re.sub(r"^__version_full__ = .*", "__version_full__ =
__version__", init_text, flags=re.MULTILINE)
+ INIT_FILE.write_text(init_text)
+
+ # Recompute hash after version bump (version lines are excluded from hash)
+ new_hash = compute_theme_hash()
+
+ # Update stored hash and version
+ HASH_FILE.write_text(f"{new_hash}\n")
+ VERSION_FILE.write_text(f"{new_version}\n")
+
+ # Stage the modified files
+ git_add(INIT_FILE, HASH_FILE, VERSION_FILE)
+ print("sphinx_airflow_theme: updated hash and version files")
+ return 1
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
b/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
index d71e298020..74c21d4d4a 100644
--- a/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
+++ b/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
@@ -18,7 +18,7 @@
from os import path
from sphinx.application import Sphinx
-__version__ = '0.3.1'
+__version__ = '0.3.2'
__version_full__ = __version__