Skip to content

A bash script that automatically updates Swift Package Manager dependencies to their latest versions by fetching release information from GitHub API

Notifications You must be signed in to change notification settings

diegotl/Swift-Package-Dependencies-Updater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Swift Package Dependencies Updater

A bash script that automatically updates Swift Package Manager dependencies to their latest versions by fetching information from the GitHub API.

Features

  • 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

Usage

./update_dependencies.sh <path_to_Package.swift>

Example

./update_dependencies.sh /path/to/your/Package.swift

Requirements

  • bash
  • curl (for GitHub API calls)
  • sed (for file modifications)
  • grep (for pattern matching)

How it works

  1. Parse Package.swift: The script reads the Package.swift file and identifies GitHub dependencies using regex patterns.

  2. Extract Repository Information: For each dependency, it extracts the repository URL and current version.

  3. 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.

  4. Version Comparison: The script compares the current version with the latest version (normalizing both by removing 'v' prefixes).

  5. Update File: If a newer version is available, it updates the Package.swift file with the new version.

Supported URL Formats

  • https://github.com/owner/repo.git
  • https://github.com/owner/repo
  • [email protected]:owner/repo.git

Example Output

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

Notes

  • 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

Error Handling

  • 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

About

A bash script that automatically updates Swift Package Manager dependencies to their latest versions by fetching release information from GitHub API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages