Skip to content

Commit 5cb23d9

Browse files
author
Dima Birenbaum
committed
fix(ci): sort -V for guardian binary, semver sort for config dirs, per-tool regex fallback
1 parent b70a26e commit 5cb23d9

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

.github/workflows/toolchain-version-probe.yml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Run guardian init (cache hit)
6262
if: steps.cache.outputs.cache-hit == 'true'
6363
run: |
64-
guardian=$(find /home/runner/work/_msdo/versions -maxdepth 4 -name 'guardian' -type f 2>/dev/null | sort | tail -1)
64+
guardian=$(find /home/runner/work/_msdo/versions -maxdepth 4 -name 'guardian' -type f 2>/dev/null | sort -V | tail -1)
6565
if [[ -z "$guardian" ]]; then
6666
echo "::error::guardian binary not found in cache — cache may be corrupt"
6767
exit 1
@@ -83,7 +83,12 @@ jobs:
8383
8484
# Tools.Configuration is installed inside the CLI package directory:
8585
# _msdo/versions/Microsoft.Security.Devops.Cli.linux-x64.{ver}/tools/Config/Tools/
86-
config_dirs = sorted(versions_base.glob('*/tools/Config/Tools'))
86+
def cli_version(p):
87+
# Extract semver tuple from path e.g. .../Cli.linux-x64.0.215.0/tools/Config/Tools
88+
m = re.search(r'\.(\d+)\.(\d+)\.(\d+)[/\\]', str(p))
89+
return tuple(int(x) for x in m.groups()) if m else (0, 0, 0)
90+
91+
config_dirs = sorted(versions_base.glob('*/tools/Config/Tools'), key=cli_version)
8792
if not config_dirs:
8893
print('ERROR: Config/Tools not found — guardian init may not have run', file=sys.stderr)
8994
gh_out = os.environ.get('GITHUB_OUTPUT', '')
@@ -154,21 +159,20 @@ jobs:
154159
except ET.ParseError:
155160
pass
156161
157-
# --- Strategy 3: regex fallback on raw XML text ---
158-
# Handles malformed XML or unexpected schemas
159-
if not any(t in tools for t in PKG_TO_TOOL.values()):
160-
for pkg_lower, canonical in PKG_TO_TOOL.items():
161-
if canonical in tools:
162-
continue
163-
# Look for the package name (case-insensitive) near a version
164-
if pkg_lower in content.lower():
165-
m = re.search(
166-
re.escape(pkg_lower) + r'[^"\'<>]*["\'>][\s\S]{0,200}?' +
167-
r'(\d+\.\d+(?:\.\d+)*)',
168-
content.lower()
169-
)
170-
if m:
171-
tools[canonical] = m.group(1)
162+
# --- Strategy 3: regex fallback on raw XML text (per-tool) ---
163+
# Runs for each tool not yet resolved, regardless of other tools.
164+
# Handles malformed XML or unexpected schemas.
165+
for pkg_lower, canonical in PKG_TO_TOOL.items():
166+
if canonical in tools:
167+
continue
168+
if pkg_lower in content.lower():
169+
m = re.search(
170+
re.escape(pkg_lower) + r'[^"\'<>]*["\'>][\s\S]{0,200}?' +
171+
r'(\d+\.\d+(?:\.\d+)*)',
172+
content.lower()
173+
)
174+
if m:
175+
tools[canonical] = m.group(1)
172176
173177
# eslint: installed via npm — version is in the npm package spec inside
174178
# the .gdntool for eslint. Try to find it from the raw XML dump.

0 commit comments

Comments
 (0)