Swift Registry
Cloudsmith provides public & private registries for Swift
The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies. Cloudsmith is fully compatible as a Swift registry.
With Swift, developers can create, share, and manage packages for their projects.
For more information on Swift, please see:
- Swift: The official website for Swift
- The Swift registry is a HTML catalog of Swift Packages which helps direct users to third-party Git repositories. It does not host swift packages.
- The Swift package manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
- Creating a Swift package: Creating a Swift package
More detailed information about registry configuration can be found at: Package Registry Usage.
In the following examples:
Identifier | Description |
---|---|
OWNER | Your Cloudsmith account name or organization name (namespace) |
REPOSITORY | Your Cloudsmith Repository name (also called "slug") |
GIT_REPOSITORY_URL | GIT repository URL |
TOKEN | Your Cloudsmith Entitlement Token (see Entitlements for more details) |
USERNAME | Your Cloudsmith username |
PASSWORD | Your Cloudsmith password |
API-KEY | Your Cloudsmith API Key |
PACKAGE_NAME | The name of your package |
APP_NAME | The name of your application |
VERSION | The version number of your package |
SCOPE | Namespaces for package names |
Configure Cloudsmith as your Swift Registry
Create a Cloudsmith Repository
If you haven't already, create a repository in Cloudsmith where you'll publish your package. Note down the repository URL, which should resemble:
https://swift.cloudsmith.io/ORGANIZATION/REPOSITORY
Replace ORGANIZATION with your Cloudsmith organization name and REPOSITORY with the name of your repository.
Creating a Swift package
If you haven't created a package already, Swift can create a new package
swift package init --name PACKAGE_NAME --type executable
Creating executable package: your-package
Creating Package.swift
Creating .gitignore
Creating Sources/
Creating Sources/main.swift
Create the Swift package by using the swift package archive-source
command:
swift package archive-source
The terminals will output Created PACKAGE_NAME.zip
if successful.
Configure Cloudsmith as your Swift Registry
Use Swift version 5.9 or above to publish Swift package to Cloudsmith using the Swift Package Manager. You can verify by running swift -version
Set your Cloudsmith repository for the project.
swift package-registry set https://swift.cloudsmith.io/OWNER/REPOSITORY/
This creates a configuration file at .swiftpm/configuration/registries.json
that looks like this:
{
"authentication" : {
},
"registries" : {
"[default]" : {
"supportsAvailability" : false,
"url" : "https://swift.cloudsmith.io/cloudsmith-test/buildkite-demo"
}
},
"version" : 1
Login to your private Cloudsmith Swift registry
swift package-registry login https://swift.cloudsmith.io/OWNER/REPOSITORY/ --username USERNAME --password API-KEY
swift package-registry login --token API-KEY
Note: the
swift package-registry set
command sets the registry for your current project. However, it is possible to configure this registry as Swift's global package registry using the --global flag. It will write the registry configuration into the user configuration file at~/.swiftpm/configuration/registries.json
.
Upload a Package
Upload using Swift Package Manager
A Swift package consists of Swift source files and a manifest file. The manifest file, called Package.swift, defines the package’s name and its contents using the PackageDescription module.
Navigate to the Swift project directory that contains the Package.swift file for your package.
swift package-registry publish SCOPE.PACKAGE_NAME VERSION
replace SCOPE, PACKAGE_NAME and VERSION with the scope of the package, package name and package version respectively.
- Note, replace SCOPE below with the scope you want to use to publish the package with. In Swift, scope's are namespaces for package names. You can publish any scope to your Cloudsmith repository.
- Package scopes are case-insensitive (for example, mona ≍ MONA).
- Version numbers should follow semantic versioning
Verification
After publishing, You should receive a confirmation message similar to the following:
PACKAGE_NAME version VERSION was successfully published to <https://swift.cloudsmith.io/ORGANIZATION/REPOSITORY> and is available at <https://swift.cloudsmith.io/ORGANIZATION/REPOSITORY/SCOPE/PACKAGE_NAME/VERSION`>
You can verify that your package is available in your Cloudsmith repository by navigating to the repository URL in your browser or using Cloudsmith's CLI tools.
Upload via the Cloudsmith CLI
For full details of how to install and setup the Cloudsmith CLI, see Command Line Interface.
To upload via the Cloudsmith CLI / API, you'll need to generate your package first. You can do this with:
swift package archive-source
This will generate a zip file likeyour-package.zip
that you can upload.
The command to upload a swift package via the Cloudsmith CLI is:
cloudsmith push swift OWNER/REPOSITORY PACKAGE_NAME.zip --name PACKAGE_NAME --version VERSION --scope SCOPE
Example:
cloudsmith push swift cloudsmith-test-org/cloudsmith-test-repo MyCLI.zip --version 1.0.0 --name MyCLI --scope swift
Upload via Cloudsmith Website
Please see Upload a Package for details of how to upload via the Website UI.
Republish a git project to Cloudsmith
This guide may help you in this process https://github.com/spqw/swift-package-registry-demo/blob/main/README.md
To configure your existing Git project to publish Swift packages to Cloudsmith do the following:
Clone the Repository
git clone GIT_REPOSITORY_URL --depth 1
cd GIT_REPOSITORY_URL
Replace GIT_REPOSITORY_URL with the projects git repository url.
Checkout the Desired Version
Before publishing your package, ensure that you're on the correct version tag or commit hash that you want to publish. If you have a specific release tag, you can fetch and checkout that tag using Git commands:
# Fetch the desired version tag
git fetch --depth 1 origin tag VERSION
# Checkout the specific tag
git checkout VERSION
Replace VERSION with the tag of the version you intend to publish.
Prepare the sub modules
If your project has submodules, you would need to update them
git submodule update --init
Prepare Package Metadata
Create a file named package-metadata.json in the root of your repository and fill it with package metadata. Here's an example:
{
"author": {
"name": "Your Name",
"email": "[email protected]",
"organization": {
"name": "Your Organization"
}
},
"description": "Your package description",
"licenseURL": "https://github.com/your_organization/your_repository/blob/main/LICENSE",
"readmeURL": "https://github.com/your_organization/your_repository/blob/main/README.md",
"repositoryURLs": [
"https://github.com/your_organization/your_repository.git",
"[email protected]:your_organization/your_repository.git"
]
}
Configure Cloudsmith URL
Follow the steps in Configure Cloudsmith as your Swift Registry to configure Cloudsmith as your Swift registry.
Publish the Package
swift package-registry publish PACKAGE_NAME VERSION --metadata-path ${HOME}/path/to/package-metadata.json
Replace PACKAGE_NAME with the name of your package and VERSION with the git tag version number.
Download / Install a Package
Configure Cloudsmith
Follow the steps in Configure Cloudsmith as your Swift Registry to configure Cloudsmith as your Swift registry.
Add a swift package from Cloudsmith as a dependancy
Follow the instructions below to configure the Swift Package Manager to consume Swift packages from a Cloudsmith Swift registry.
Configure your dependancies
A package dependency is declared in Package.swift. Edit the Package.swift file in your application project folder to update the package dependencies to be used by your project.
- In the dependencies section of Package.swift, add the package you want to use by adding its package identifier. The package identifier consists of the scope and package name separated by a period. See the code snippet following a later step for an example.
- In the targets section of Package.swift, add the targets that will need to use the dependency.
The following is an example showing configured dependencies and targets sections in a Package.swift file:
...
],
dependencies: [
.package(id: "SCOPE.PACKAGE_NAME", from: "1.0.0")
],
targets: [
.target(
name: "APP_NAME",
dependencies: ["SCOPE.PACKGE_NAME"]
),...
],
...
(Optional) Clear Build Products and Cache
swift package reset
swift package purge-cache
Resolve Dependencies
Now, resolve dependencies for your project using the following command to download the package dependencies from Cloudsmith.
swift package resolve
Verify Dependency Resolution
You should see the following printed out when resolving dependancies
Fetching <dependency_url>
Computing version for <dependency_name>
Fetched <dependency_name> (<version>) (<time>)
Removing Setup
If you no longer want to install packages from the repository, you can remove it with:
swift package-registry unset
Security Scanning
Supported
Please see our Security Scanning documentation for further information.
Upstream Proxying / Caching
Configurable Proxying Caching
You can configure to proxy a private or public swift registry you wish to use for packages that are not available in your current Cloudsmith repository e.g. you can point to another Cloudsmith repository. In addition, you can also choose to cache any requested packages for future use.
There is currently no public swift repository
HTML catalogs of Swift Packages such as Swift Package Registry that point to third-party Git repositories do not host any actual packages and so can't be added as an upstream.
Please see our Upstream Proxying documentation for further instructions.
Key Signing Support
Not supported
Troubleshooting
Please see the Troubleshooting page for further help and information.
Updated 7 months ago