Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/basic-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ jobs:
UPGRADE_MPROCS: "false"
UPGRADE_PROTOC: "false"
UPGRADE_OPENAPI_GENERATOR: "false"
UPGRADE_COOLDOWN_DAYS: "4"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test-airflow-release-commands:
Expand Down
41 changes: 41 additions & 0 deletions scripts/ci/prek/upgrade_important_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def get_env_bool(name: str, default: bool = True) -> bool:

VERBOSE: bool = os.environ.get("VERBOSE", "false") == "true"
UPGRADE_ALL_BY_DEFAULT: bool = os.environ.get("UPGRADE_ALL_BY_DEFAULT", "true") == "true"
UPGRADE_COOLDOWN_DAYS: int = int(os.environ.get("UPGRADE_COOLDOWN_DAYS", "0"))

if UPGRADE_ALL_BY_DEFAULT and VERBOSE:
console.print("[bright_blue]Upgrading all important versions")
Expand Down Expand Up @@ -850,6 +851,40 @@ def _replace_requires(m: re.Match[str], _new: str = new_requires_array) -> str:
return changed


def is_within_cooldown(cooldown_days: int) -> bool:
"""Check if there was a version upgrade commit within the cooldown period.

Looks for commits matching the 'Upgrade important' pattern in the git log
within the last ``cooldown_days`` days. If found, the upgrade check should
not fail because someone recently addressed the versions.
"""
try:
result = subprocess.run(
[
"git",
"log",
f"--since={cooldown_days} days ago",
"--all",
"--oneline",
"--grep=Upgrade important",
],
capture_output=True,
text=True,
check=True,
cwd=AIRFLOW_ROOT_PATH,
)
if result.stdout.strip():
if VERBOSE:
console.print(
f"[bright_blue]Found recent upgrade commits within {cooldown_days} days:\n"
f"{result.stdout.strip()}"
)
return True
return False
except subprocess.CalledProcessError:
return False


def main() -> None:
"""Main entry point for the version upgrade script."""
retrieve_gh_token(description="airflow-upgrade-important-versions", scopes="public_repo")
Expand Down Expand Up @@ -877,6 +912,12 @@ def main() -> None:
sync_breeze_lock_file()
if not os.environ.get("CI"):
console.print("[bright_blue]Please commit the changes")
if UPGRADE_COOLDOWN_DAYS > 0 and is_within_cooldown(UPGRADE_COOLDOWN_DAYS):
console.print(
f"[bright_yellow]Versions are outdated but within {UPGRADE_COOLDOWN_DAYS}-day "
f"cooldown period (recent upgrade commit found). Not failing."
)
sys.exit(0)
sys.exit(1)


Expand Down
Loading