Skip to content

Commit

Permalink
Merge pull request #70 from 5152Alotobots/patchMentions
Browse files Browse the repository at this point in the history
Patch mentions
  • Loading branch information
SeanErn authored Jan 11, 2025
2 parents e9ae82d + a705cd5 commit 4fbfe45
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
54 changes: 29 additions & 25 deletions .github/scripts/check_vendordeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from typing import Dict, Optional
from packaging import version
import sys

class VendorDepChecker:
def __init__(self):
Expand Down Expand Up @@ -41,20 +42,21 @@ def sanitize_text(self, text: str) -> str:

def get_github_latest(self, repo_url: str, is_wpilib: bool = False) -> Optional[Dict]:
"""Get latest release version from GitHub, including betas."""
import sys
try:
print(f"\nChecking releases from: {repo_url}")
print(f"\nChecking releases from: {repo_url}", file=sys.stderr)
response = requests.get(repo_url, headers=self.headers)
response.raise_for_status()
releases = response.json()

print(f"Found {len(releases)} total releases")
print(f"Found {len(releases)} total releases", file=sys.stderr)

# For WPILib, filter releases to only include current year
if is_wpilib:
releases = [r for r in releases if '2025' in r['tag_name']]
print(f"Found {len(releases)} 2025 releases")
print(f"Found {len(releases)} 2025 releases", file=sys.stderr)
for r in releases[:5]: # Show first 5
print(f"Release: {r['name']} (Tag: {r['tag_name']})")
print(f"Release: {r['name']} (Tag: {r['tag_name']})", file=sys.stderr)

# Convert all versions to comparable objects
parsed_releases = []
Expand All @@ -68,27 +70,27 @@ def get_github_latest(self, repo_url: str, is_wpilib: bool = False) -> Optional[
'is_beta': release.get('prerelease', False) or 'beta' in tag.lower(),
'url': release['html_url']
})
print(f"Successfully parsed version: {tag} -> {ver}")
print(f"Successfully parsed version: {tag} -> {ver}", file=sys.stderr)
except version.InvalidVersion:
print(f"Skipping invalid version: {tag}")
print(f"Skipping invalid version: {tag}", file=sys.stderr)
continue

# Sort by version, highest first
parsed_releases.sort(key=lambda x: x['version'], reverse=True)

if parsed_releases:
latest = parsed_releases[0]
print(f"\nSelected latest version: {latest['tag']} (Beta: {latest['is_beta']})")
print(f"\nSelected latest version: {latest['tag']} (Beta: {latest['is_beta']})", file=sys.stderr)
return {
'version': latest['tag'],
'is_beta': latest['is_beta'],
'url': latest['url']
}
print("No valid releases found")
print("No valid releases found", file=sys.stderr)
return None

except Exception as e:
print(f"Error fetching from GitHub: {e}")
print(f"Error fetching from GitHub: {e}", file=sys.stderr)
return None

def get_current_version(self, file_path: Path) -> Dict:
Expand Down Expand Up @@ -128,52 +130,54 @@ def get_wpilib_current_version(self) -> Dict:

def is_newer_version(self, current: Dict, latest: Dict) -> bool:
"""Compare versions, considering betas as newer than releases."""
import sys
current_ver = self.parse_version(current['version'])
latest_ver = self.parse_version(latest['version'])

print(f"\nComparing versions:")
print(f"Current: {current['version']} (Beta: {current['is_beta']}) -> Parsed as: {current_ver}")
print(f"Latest: {latest['version']} (Beta: {latest['is_beta']}) -> Parsed as: {latest_ver}")
print(f"\nComparing versions:", file=sys.stderr)
print(f"Current: {current['version']} (Beta: {current['is_beta']}) -> Parsed as: {current_ver}", file=sys.stderr)
print(f"Latest: {latest['version']} (Beta: {latest['is_beta']}) -> Parsed as: {latest_ver}", file=sys.stderr)

# If versions are equal, prefer beta over stable
if current_ver == latest_ver:
result = latest['is_beta'] and not current['is_beta']
print(f"Versions equal, checking beta status -> Update needed: {result}")
print(f"Versions equal, checking beta status -> Update needed: {result}", file=sys.stderr)
return result

result = latest_ver > current_ver
print(f"Comparing versions -> Update needed: {result}")
print(f"Comparing versions -> Update needed: {result}", file=sys.stderr)
return result

def check_all_updates(self):
"""Check all vendordeps for updates."""
import sys
updates = []
vendordeps_dir = Path('vendordeps')

print("Starting dependency check...")
print("Starting dependency check...", file=sys.stderr)

# Check all GitHub-based vendordeps (including Phoenix6)
for name, url in self.github_sources.items():
print(f"\nChecking {name}...")
print(f"\nChecking {name}...", file=sys.stderr)

if name == 'WPILib':
current = self.get_wpilib_current_version()
latest = self.get_github_latest(url, is_wpilib=True)
else:
current_file = next(vendordeps_dir.glob(f"{name}*.json"), None)
if not current_file:
print(f"No vendordep file found for {name}")
print(f"No vendordep file found for {name}", file=sys.stderr)
continue
print(f"Found vendordep file: {current_file}")
print(f"Found vendordep file: {current_file}", file=sys.stderr)
current = self.get_current_version(current_file)
latest = self.get_github_latest(url)

if current and latest:
print(f"Current version: {current['version']}")
print(f"Latest version: {latest['version']}")
print(f"Current version: {current['version']}", file=sys.stderr)
print(f"Latest version: {latest['version']}", file=sys.stderr)

if self.is_newer_version(current, latest):
print(f"Update available for {name}")
print(f"Update available for {name}", file=sys.stderr)
updates.append({
'name': name,
'current': current['version'],
Expand All @@ -184,7 +188,7 @@ def check_all_updates(self):
'url': latest.get('url')
})
else:
print(f"Failed to get version info for {name}")
print(f"Failed to get version info for {name}", file=sys.stderr)

return updates

Expand All @@ -194,9 +198,9 @@ def check_all_updates(self):

# Set output for GitHub Actions
if updates:
print("\nFound updates:")
print("\nFound updates:", file=sys.stderr)
for update in updates:
print(f"- {update['name']}: {update['current']} -> {update['latest']}")
print(f"- {update['name']}: {update['current']} -> {update['latest']}", file=sys.stderr)

# GitHub Actions output syntax
result = {
Expand All @@ -205,7 +209,7 @@ def check_all_updates(self):
}
print(json.dumps(result))
else:
print("\nNo updates found.")
print("\nNo updates found.", file=sys.stderr)
result = {
"has_updates": False,
"updates": []
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/check_vendordeps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,39 @@ on:
schedule:
- cron: '0 12 */2 * *' # Run at noon UTC every other day
workflow_dispatch: # Allow manual triggers

jobs:
check-updates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: pip install requests packaging

- name: Check for updates
id: check
run: |
echo "UPDATES_OUTPUT=$(python .github/scripts/check_vendordeps.py)" >> $GITHUB_OUTPUT
# Run script and capture only the JSON output
UPDATES_OUTPUT=$(python .github/scripts/check_vendordeps.py 2> >(tee check_deps.log >&2))
echo "UPDATES_OUTPUT=$UPDATES_OUTPUT" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Handle Update Issues
if: fromJSON(steps.check.outputs.UPDATES_OUTPUT).has_updates
uses: actions/github-script@v6
env:
UPDATES_JSON: ${{ fromJSON(steps.check.outputs.UPDATES_OUTPUT).updates }}
UPDATES_JSON: ${{ steps.check.outputs.UPDATES_OUTPUT }}
with:
script: |
try {
const updates = JSON.parse(process.env.UPDATES_JSON);
const updates = JSON.parse(process.env.UPDATES_JSON).updates;
// Search for existing open issues
const issues = await github.rest.issues.listForRepo({
Expand Down

0 comments on commit 4fbfe45

Please sign in to comment.