-
Notifications
You must be signed in to change notification settings - Fork 1
Add github workflow and script to auto update vendordeps #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
timtogan
wants to merge
4
commits into
master
Choose a base branch
from
auto-update-vendordeps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7c79975
Add github workflow and script to auto update vendordeps
timtogan ca7725a
Restrict auto update vendordeps to one run at a time
timtogan 914d88a
Add handling for when wpilib vendordep marketplace is down
timtogan b2323c5
Fix docstring in update vendordeps
timtogan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| #!/usr/bin/env python3 | ||
| """Update WPILib vendordep JSON files from the WPILib vendordep marketplace. | ||
|
|
||
| This mirrors what the WPILib VS Code extension's dependency manager does: | ||
| fetch the marketplace manifest for the frcYear, match each local vendordep | ||
| by uuid, and if the marketplace lists a newer version, download that exact | ||
| file. | ||
|
|
||
| Vendordeps whose uuid is not in the marketplace (e.g. WPILibNewCommands, | ||
| which ships with WPILib itself) are reported and left alone. | ||
|
|
||
| Writes a markdown summary of what changed to the path given by | ||
| --summary (used as the pull request body), and prints it to stdout. | ||
| """ | ||
|
|
||
| import argparse | ||
| import json | ||
| import re | ||
| import sys | ||
| import urllib.request | ||
| from pathlib import Path | ||
|
|
||
| MARKETPLACE_ROOT = "https://frcmaven.wpi.edu/artifactory/vendordeps/vendordep-marketplace" | ||
| VENDORDEPS_DIR = Path(__file__).resolve().parents[2] / "vendordeps" | ||
| TIMEOUT_SECONDS = 30 | ||
|
|
||
|
|
||
| def fetch(url: str) -> str: | ||
| req = urllib.request.Request(url) | ||
| with urllib.request.urlopen(req, timeout=TIMEOUT_SECONDS) as resp: | ||
| return resp.read().decode("utf-8") | ||
|
|
||
|
|
||
| def version_key(version: str) -> tuple: | ||
| # Converts version string into a tuple for easier comparison | ||
| return tuple(int(part) for part in re.findall(r"\d+", version)) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--summary", type=Path, help="Path to write the markdown summary to") | ||
| args = parser.parse_args() | ||
|
|
||
| manifests: dict[str, list] = {} | ||
| updated: list[str] = [] | ||
| unchanged: list[str] = [] | ||
| skipped: list[str] = [] | ||
| errors: list[str] = [] | ||
|
|
||
| for path in sorted(VENDORDEPS_DIR.glob("*.json")): | ||
| local = json.loads(path.read_text()) | ||
| name = local.get("name", path.name) | ||
| uuid = local.get("uuid") | ||
| year = local.get("frcYear") | ||
| local_version = local.get("version", "") | ||
|
|
||
| if not uuid or not year: | ||
| skipped.append(f"**{name}** (`{path.name}`): missing uuid or frcYear") | ||
| continue | ||
|
|
||
| if year not in manifests: | ||
| try: | ||
| manifests[year] = json.loads(fetch(f"{MARKETPLACE_ROOT}/{year}.json")) | ||
| except Exception as e: # noqa: BLE001 (network/remote errors; handled and reported below) | ||
| manifests[year] = None | ||
| errors.append(f"Failed to fetch the {year} marketplace manifest ({e})") | ||
|
|
||
| if manifests.get(year) is None: | ||
| skipped.append( | ||
| f"**{name}** (`{path.name}`): skipped because the {year} marketplace manifest could not be fetched" | ||
| ) | ||
| continue | ||
|
|
||
| candidates = [e for e in manifests[year] if e.get("uuid") == uuid] # WPILib repo keeps multiple versions | ||
| if not candidates: | ||
| skipped.append(f"**{name}** (`{path.name}`): not in the {year} marketplace") | ||
| continue | ||
|
|
||
| best = max(candidates, key=lambda e: version_key(e.get("version", ""))) | ||
| best_version = best.get("version", "") | ||
|
|
||
| if version_key(best_version) <= version_key(local_version): | ||
| unchanged.append(f"**{name}**: {local_version}") | ||
| continue | ||
|
|
||
| try: | ||
| new_text = fetch(f"{MARKETPLACE_ROOT}/{best['path']}") | ||
| new_json = json.loads(new_text) | ||
| except Exception as e: # noqa: BLE001 | ||
| errors.append(f"**{name}**: failed to download {best['path']} ({e})") | ||
| continue | ||
|
|
||
| new_path = VENDORDEPS_DIR / new_json.get("fileName", Path(best["path"]).name) | ||
| try: | ||
| new_path.write_text(new_text) | ||
| if new_path != path: | ||
| path.unlink() # delete the old file | ||
| except OSError as e: | ||
| errors.append(f"**{name}**: failed to write `{new_path.name}` ({e})") | ||
| continue | ||
|
|
||
| updated.append(f"**{name}**: {local_version} -> {best_version} (`{new_path.name}`)") | ||
|
|
||
| lines = [] | ||
| if updated: | ||
| lines.append("## Updated") | ||
| lines += [f"- {s}" for s in updated] | ||
| if errors: | ||
| lines.append("\n## Errors (left unchanged)") | ||
| lines += [f"- {s}" for s in errors] | ||
| if unchanged: | ||
| lines.append("\n## Already up to date") | ||
| lines += [f"- {s}" for s in unchanged] | ||
| if skipped: | ||
| lines.append("\n## Skipped") | ||
| lines += [f"- {s}" for s in skipped] | ||
| summary = "\n".join(lines) + "\n" | ||
|
|
||
| print(summary) | ||
| if args.summary: | ||
| args.summary.write_text(summary) | ||
|
|
||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: Update vendordeps | ||
|
|
||
| on: | ||
| schedule: | ||
| # Every Monday at 12:00 UTC | ||
| - cron: '0 12 * * 1' | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: update-vendordeps | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
|
Copilot marked this conversation as resolved.
|
||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| update: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Check for vendordep updates | ||
| run: python3 .github/scripts/update_vendordeps.py --summary /tmp/vendordep-summary.md | ||
|
|
||
| - name: Create pull request | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| token: ${{ secrets.VENDORDEP_UPDATE_TOKEN || github.token }} | ||
| branch: bot/update-vendordeps | ||
| title: Update vendordeps | ||
| body-path: /tmp/vendordep-summary.md | ||
| commit-message: Update vendordeps | ||
| delete-branch: true | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.