How to detect a SwiftPM project without cloning full repo?

i am building a tool that needs to be able to detect if an arbitrary git repository (possibly) contains a SwiftPM project. i would like the tool to be able to do this without performing a full clone (takes forever) or a shallow clone (it is hard on GitHub). this is because i am expecting a high percentage (>95%) of these queries to fail.

my first idea was to poll GitHub to see if a file named Package.swift exists at the expected location. but this would not account for packages that use version-specific manifests exclusively. i might scrape all the possibilities going back to Swift 4.

  1. Package@swift-5.10.swift
  2. Package@swift-5.9.swift
  3. Package@swift-5.8.swift
  4. Package@swift-5.7.swift
  5. Package@swift-5.6.swift
  6. Package@swift-5.5.swift
  7. Package@swift-5.4.swift
  8. Package@swift-5.3.swift
  9. Package@swift-5.2.swift
  10. Package@swift-5.1.swift
  11. Package@swift-5.0.swift

but this feels spammy and not particularly scalable.

If the repositories are located on GitHub, you could possibly use the GitHub API to get the top-level directory contents for a repository and then check the results for the package files you are looking for.

2 Likes