Any way to automate adding libraries in Xcode from Swift Package Manager (SPM)?

Hi all,

I’m looking for a way to automate the process of adding Swift Package dependencies (SPM) into an Xcode project.

Right now, I’m doing this manually via:

Xcode → Project → Swift Packages → Add Package Dependency...

But I’d like to script this step — ideally as part of a CI/CD pipeline or a setup script. I explored the xcodeproj Ruby gem, but it doesn’t support adding SPM packages, and there's no official support for editing the .xcodeproj structure related to Swift Packages.

So my question is:

Is there any Apple-supported or community-supported way to programmatically add Swift Package dependencies to an Xcode project or workspace?

Would love to know if anyone has:

Used xcodebuild, xcodegen, or other tools for this

Explored editing project files directly (like project.pbxproj or Package.resolved)

Found any API or CLI hooks from Apple for this

Thanks in advance!