A bash script that automatically updates Swift Package Manager dependencies to their latest versions by fetching information from the GitHub API.
- Automatically detects GitHub dependencies in Package.swift files
- Fetches the latest release versions from GitHub API
- Falls back to latest tags if no releases are available
- Handles both HTTPS and SSH GitHub URLs (converts SSH to HTTPS for API access)
- Normalizes version numbers (removes 'v' prefix if present)
- Creates a backup and safely updates the original file
./update_dependencies.sh <path_to_Package.swift>./update_dependencies.sh /path/to/your/Package.swift- bash
- curl (for GitHub API calls)
- sed (for file modifications)
- grep (for pattern matching)
-
Parse Package.swift: The script reads the Package.swift file and identifies GitHub dependencies using regex patterns.
-
Extract Repository Information: For each dependency, it extracts the repository URL and current version.
-
Fetch Latest Version: It queries the GitHub API to get the latest release. If no releases are found, it falls back to the latest tag.
-
Version Comparison: The script compares the current version with the latest version (normalizing both by removing 'v' prefixes).
-
Update File: If a newer version is available, it updates the Package.swift file with the new version.
https://github.com/owner/repo.githttps://github.com/owner/repo[email protected]:owner/repo.git
Updating dependencies in Package.swift...
Processing: https://github.com/vapor/vapor.git
Current version: 4.115.0
Latest version: 4.115.0
✓ Already up to date
Processing: https://github.com/vapor/fluent.git
Current version: 4.11.0
Latest version: 4.12.0
✓ Updating to 4.12.0
Processing: [email protected]:owner/repo.git
Current version: 1.0.0
(Converted SSH URL to HTTPS for API access)
Latest version: 1.2.0
✓ Updating to 1.2.0
Dependencies update completed!
Updated file: Package.swift
- The script creates a temporary backup during the update process
- SSH URLs are automatically converted to HTTPS format for GitHub API access
- GitHub API rate limits may apply for repositories with many dependencies
- If a repository is not found, private, or has no releases/tags, the script will display an error message and continue with other dependencies
- If the GitHub API is unavailable, individual dependency updates will fail but the script will continue
- The original file is only replaced if the update process completes successfully