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.
Package@swift-5.10.swift
Package@swift-5.9.swift
Package@swift-5.8.swift
Package@swift-5.7.swift
Package@swift-5.6.swift
Package@swift-5.5.swift
Package@swift-5.4.swift
Package@swift-5.3.swift
Package@swift-5.2.swift
Package@swift-5.1.swift
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