Skip to main content

swift-quickstart

Last updated on

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

private registry

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.

Create an upstream proxy

Configure the upstream proxy in your registry


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.

Swift package identity must be scope.name

Every 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.