Skip to content

Commit 387abe0

Browse files
authored
chore: Adds version scanner CI/CD upgrades (#17425)
### Summary of Changes This PR contains updates to the automated dependency version scanner tool and its associated CI/CD workflow to support decoupled formatting, clean console logs, and advisory (non-signalling) runs during rollout. #### 1. GitHub Actions (GHA) Workflow Modernization * **Triggers & Scheduling:** * Configured the workflow to run on `main` and any branch matching `'**version-scanner**'` * Set the schedule to run hourly to test how the system behaves if we choose to use it nightly * Added a `workflow_dispatch` button in the GHA tab to simplify ad hoc testing and demos during development. #### 2. Scanner Script Refactoring (Decoupled Formatters) * Decoupled formatting code from reporting code. * Introduced specialized formatters: * `format_for_raw_csv`: Generates clean, unformatted raw data for CSV reporting. * `format_for_spreadsheet`: Wraps matches with Google Sheets formulas (such as `HYPERLINK` and string quotes to prevent float truncation) for Google Sheets upload. * `format_for_console`: Prepares a slim, readable console string for stdout/logs (especially GHA logs). #### 3. Output Simplification * Removed some existing outputs that no longer made sense to to declutter GHA runner logs. * Ensure it prints matches in the clean console format and removed some existing duplicate outputs. #### 4. Advisory Runs (`--soft-fail`) * Added a `--soft-fail` CLI flag to the python script to allow it to exit with code `0` even if version matches are found (allowing the scan to run and report findings in the logs without failing the GHA check and blocking merges during development and prototyping phases). * Integrated `--soft-fail` in the GHA workflow for now to support development.
1 parent b5e0d4b commit 387abe0

4 files changed

Lines changed: 428 additions & 127 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Version Scan
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- '**version-scanner**'
8+
schedule:
9+
- cron: '0 * * * *' # Run hourly at the top of the hour
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
issues: write
15+
16+
jobs:
17+
scan:
18+
name: Version Scan
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v6
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v6
25+
with:
26+
python-version: '3.14'
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install pyyaml
32+
33+
- name: Run Version Scanner
34+
run: |
35+
# Uses -o to output a detailed, raw CSV to a file
36+
# Uses --stdout to print a slim, easier to parse summary to the GitHub Actions UI
37+
# Uses --soft-fail to temporarily limit causing CI/CD failures during the migration to full operation.
38+
python scripts/version_scanner/version_scanner.py -d python -v 3.7 --stdout -o version_scanner_output.csv --soft-fail
39+
40+
- name: Upload CSV Results
41+
if: always()
42+
uses: actions/upload-artifact@v7
43+
with:
44+
name: version-scanner-results
45+
path: version_scanner_output.csv
46+
47+
- name: Create or update issue on finding
48+
if: failure()
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
TITLE="Version Scanner found deprecated dependencies"
53+
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
54+
55+
# Read the first 50 lines to prevent blowing up the issue body if it's massive
56+
CSV_PREVIEW=$(head -n 50 version_scanner_output.csv)
57+
58+
BODY="The [Version Scanner]($RUN_URL) found deprecated dependencies in the repository.
59+
60+
**Matches Found:**
61+
\`\`\`csv
62+
$CSV_PREVIEW
63+
\`\`\`
64+
*(If there are more than 50 matches, see the workflow logs for the full list)*"
65+
66+
# Mirroring regenerate-all.yml: check if an issue already exists to prevent spam
67+
EXISTING_ISSUE=$(gh issue list --state open --search "in:title \"$TITLE\"" --json number --jq '.[0].number')
68+
69+
if [ -z "$EXISTING_ISSUE" ]; then
70+
echo "WOULD HAVE CREATED ISSUE:"
71+
echo "gh issue create --title \"$TITLE\" --body \"$BODY\""
72+
# gh issue create --title "$TITLE" --body "$BODY"
73+
else
74+
echo "Issue #$EXISTING_ISSUE already exists."
75+
echo "WOULD HAVE ADDED COMMENT:"
76+
echo "gh issue comment \"$EXISTING_ISSUE\" --body \"Another scanner run found deprecated dependencies: $RUN_URL\""
77+
# gh issue comment "$EXISTING_ISSUE" --body "Another scanner run found deprecated dependencies: $RUN_URL"
78+
fi

scripts/version_scanner/regex_config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ rules:
5858
- |
5959
sys\.version_info\s*<\s*\(3,\s*{minor_plus_one}\)
6060
- |
61-
sys\.version_info\.minor\s*==\s*{minor}
61+
sys\.version_info\.minor\s*==\s*{minor}(?!\d)
6262
- |
63-
sys\.version_info\.minor\s*>=\s*{minor}
63+
sys\.version_info\.minor\s*>=\s*{minor}(?!\d)
6464
- |
65-
sys\.version_info\.minor\s*<=\s*{minor}
65+
sys\.version_info\.minor\s*<=\s*{minor}(?!\d)
6666
- |
67-
sys\.version_info\.minor\s*>\s*{minor_minus_one}
67+
sys\.version_info\.minor\s*>\s*{minor_minus_one}(?!\d)
6868
- |
69-
sys\.version_info\.minor\s*<\s*{minor_plus_one}
69+
sys\.version_info\.minor\s*<\s*{minor_plus_one}(?!\d)
7070
7171
- name: python_env_short
7272
description: Finds short python environment names often used in tox or nox.
@@ -87,7 +87,7 @@ rules:
8787
- "Python3.7"
8888
rules:
8989
- |
90-
python3\.{minor}
90+
python3\.{minor}(?!\d)
9191
9292
- name: combined_version_string
9393
description: Finds combined version strings often used in class or variable names.
@@ -97,6 +97,6 @@ rules:
9797
- "Python37DeprecationWarning"
9898
rules:
9999
- |
100-
Python{major}{minor}
100+
Python{major}{minor}(?!\d)
101101
102102

0 commit comments

Comments
 (0)