swift-quickstart
Use a Swift registry to publish and consume Swift packages with Swift Package Manager (SwiftPM). Harness exposes a registry URL compatible with swift package-registry commands for authentication, publishing, and dependency resolution.
Prerequisites
- Swift 5.9 or later with Swift Package Registry support (
swift package-registry --help). - Access to a Harness account with appropriate permissions to create registries and connectors.
Create a Swift Artifact Registry
- Interactive Guide
- Step-by-Step
- Navigate to the Artifact Registry module in your Harness project.
- Click on New Artifact Registry.
- In the Registry Type dropdown, select Swift Registry (or Swift Package Registry).
- Provide a Registry Name.
Your registry name must start with a letter and can include lowercase alphanumerics, _, . and -.
- Optionally, add a Description and Labels for better organization.
- Choose visibility between Public and Private.
- Click Create Registry to finalize.
This registry will serve as your private Swift registry within Harness.
Configure an Upstream Proxy (Optional)
An upstream proxy allows your registry to fetch Swift packages from external sources when they are not available locally.
- Interactive Guide
- Step-by-Step
Create an upstream proxy
Configure the upstream proxy in your registry
Create an upstream proxy
- In the Artifact Registry module, select Upstream Proxy.
- Choose Swift as the proxy type.
- Enter an Upstream Proxy Name. Optionally add a Description and Labels.
- Under Source, enter the Remote Registry URL for the upstream Swift Package Registry.
- Under Authentication, select Anonymous (No credentials required) or Username and Password, depending on whether the upstream requires credentials.
- Click Create Proxy to establish the connection.
Configure the upstream proxy in your registry
- In the Artifact Registry module, select an existing Swift Artifact Registry.
- Select the Configuration tab.
- Under Advanced (Optional), select Configure Upstream.
- Select from the list of compatible proxies to add them to your registry.
- Click Save to save the configuration.
Swift Client Setup
Follow these instructions to configure SwiftPM, publish packages to Harness, and add them as dependencies in your projects.
Configure authentication
1. Generate Identity Token
An identity token serves as the credential for Swift Package Registry operations.
Generate an identity token from Setup Client on your Swift registry, or from your Harness account settings. Use it as <TOKEN> in the commands below.
2. Point SwiftPM at the Harness registry
Set the Swift Package Registry URL for your Harness registry:
swift package-registry set https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/swift
Replace <ACCOUNT_ID> and <REGISTRY_NAME> with your account identifier and registry name. Use the URL shown in Setup Client if it differs.
3. Authenticate with your token
swift package-registry login https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/swift --token <TOKEN>
Use the same registry URL as in step 2 and the <TOKEN> from step 1. Copy the exact URL from Setup Client when it differs from the example host or path.
Publish a package
Publish a package version to your Harness Swift registry.
scope.nameEvery value used for <ARTIFACT_NAME> (the Swift package identity) must be in scope.name form — for example mona.LinkedList or harness.SwiftTestPkg. Both scope and name start with a letter and may contain letters, digits, hyphens, and underscores. Harness rejects identifiers that are missing the dot, contain more than one dot, or use other characters.
Basic publish:
swift package-registry publish <ARTIFACT_NAME> <VERSION>
With metadata (recommended):
swift package-registry publish <ARTIFACT_NAME> <VERSION> --metadata-path metadata.json
With metadata and signatures (optional):
swift package-registry publish <ARTIFACT_NAME> <VERSION> \
--metadata-path metadata.json \
--private-key-path private.key \
--cert-chain-paths certificate.pem
Replace <ARTIFACT_NAME> and <VERSION> with your package identity and semantic version. Prepare metadata.json and signing paths as required by your signing policy.
Install a package
1. Add a package dependency in Package.swift
Add a package-level dependency:
dependencies: [
.package(id: "<ARTIFACT_NAME>", from: "<VERSION>"),
],
2. Add a target dependency
Reference the product from your library or executable target:
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "<PRODUCT_NAME>", package: "<ARTIFACT_NAME>")
]
)
]
Replace <PRODUCT_NAME> with the product name exposed by the package.
3. Resolve dependencies
Fetch and resolve packages:
swift package resolve
4. (Optional) Fetch packages from the registry instead of Git
If your Package.swift still references dependencies by Git URL, you can resolve using the registry:
swift package --replace-scm-with-registry resolve
To complete the in-product flow, click Done in Setup Client if you are following the in-product wizard.