Skip to content

Commit 00c0301

Browse files
authored
Use highest version as baseline (#11714)
Use highest version as baseline Merge branch 'master' into sarahchen6/tweak-instrumentation-automation Co-authored-by: sarah.chen <sarah.chen@datadoghq.com>
1 parent 8206fbc commit 00c0301

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

.github/scripts/dependency_age.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def validate_lockfiles(args: argparse.Namespace) -> int:
439439
elif published_at > cutoff:
440440
hours_remaining = int((published_at - cutoff).total_seconds() / 3600) + 1
441441
group_id, artifact_id, version = gav.split(":", 2)
442-
baseline_version = next((c[len(f"{group_id}:{artifact_id}:"):] for c in baseline_coords if c.startswith(f"{group_id}:{artifact_id}:")), None)
442+
baseline_version = highest_baseline_version(baseline_coords, group_id, artifact_id)
443443
eligible = find_eligible_version(
444444
group_id=group_id, artifact_id=artifact_id,
445445
too_new_version=version, baseline_version=baseline_version,
@@ -678,6 +678,15 @@ def fetch_available_versions(group_id: str, artifact_id: str, repo_urls: list[st
678678
return []
679679

680680

681+
# select the highest baseline version of group:artifact present in a lockfile.
682+
def highest_baseline_version(baseline_coords: set[str], group_id: str, artifact_id: str) -> str | None:
683+
prefix = f"{group_id}:{artifact_id}:"
684+
versions = [coord[len(prefix):] for coord in baseline_coords if coord.startswith(prefix)]
685+
if not versions:
686+
return None
687+
return max(versions, key=_version_sort_key)
688+
689+
681690
# for a too-new coordinate, walk backward through available versions to find the newest one
682691
# that meets the age cutoff and is newer than the baseline version
683692
def find_eligible_version(

.github/scripts/tests/test_dependency_age.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import argparse
2+
import contextlib
3+
import io
14
import json
25
import os
36
import re
@@ -6,7 +9,9 @@
69
import sys
710
import tempfile
811
import unittest
12+
from datetime import datetime, timezone
913
from pathlib import Path
14+
from unittest import mock
1015

1116
REPO_ROOT = Path(__file__).resolve().parents[3]
1217
SCRIPT = REPO_ROOT / ".github/scripts/dependency_age.py"
@@ -469,6 +474,24 @@ def test_summary_groups_outcomes_into_sections(self) -> None:
469474
self.assertIn("com.example:update-lib:4.0.0", updated_block)
470475
self.assertIn("updated to `3.9.0`", updated_block)
471476

477+
def test_highest_baseline_version_picks_newest_of_coexisting_pins(self) -> None:
478+
# A single lockfile can pin the same artifact at several versions (one per Gradle
479+
# configuration). The baseline should be the newest so that only versions higher than
480+
# the highest existing version are considered upgrades.
481+
baseline_coords = {
482+
"ch.qos.logback:logback-core:1.1.11",
483+
"ch.qos.logback:logback-core:1.2.13",
484+
"ch.qos.logback:logback-core:1.5.34",
485+
"com.example:unrelated:9.9.9",
486+
}
487+
self.assertEqual(
488+
dependency_age.highest_baseline_version(baseline_coords, "ch.qos.logback", "logback-core"),
489+
"1.5.34",
490+
)
491+
self.assertIsNone(
492+
dependency_age.highest_baseline_version(baseline_coords, "ch.qos.logback", "logback-classic")
493+
)
494+
472495
def test_summary_omits_empty_sections(self) -> None:
473496
# only too-new violations -> only the "reverted" section should appear
474497
summary = dependency_age.build_validation_summary(

0 commit comments

Comments
 (0)