|
| 1 | +--- |
| 2 | +date: "2023-01-10T00:00:00+00:00" |
| 3 | +title: "Swift Packages Repository" |
| 4 | +slug: "packages/swift" |
| 5 | +draft: false |
| 6 | +toc: false |
| 7 | +menu: |
| 8 | + sidebar: |
| 9 | + parent: "packages" |
| 10 | + name: "Swift" |
| 11 | + weight: 95 |
| 12 | + identifier: "swift" |
| 13 | +--- |
| 14 | + |
| 15 | +# Swift Packages Repository |
| 16 | + |
| 17 | +Publish [Swift](hhttps://www.swift.org/) packages for your user or organization. |
| 18 | + |
| 19 | +**Table of Contents** |
| 20 | + |
| 21 | +{{< toc >}} |
| 22 | + |
| 23 | +## Requirements |
| 24 | + |
| 25 | +To work with the Swift package registry, you need to use [swift](https://www.swift.org/getting-started/) to consume and a HTTP client (like `curl`) to publish packages. |
| 26 | + |
| 27 | +## Configuring the package registry |
| 28 | + |
| 29 | +To register the package registry and provide credentials, execute: |
| 30 | + |
| 31 | +```shell |
| 32 | +swift package-registry set https://gitea.example.com/api/packages/{owner}/swift -login {username} -password {password} |
| 33 | +``` |
| 34 | + |
| 35 | +| Placeholder | Description | |
| 36 | +| ------------ | ----------- | |
| 37 | +| `owner` | The owner of the package. | |
| 38 | +| `username` | Your Gitea username. | |
| 39 | +| `password` | Your Gitea password. If you are using 2FA or OAuth use a [personal access token]({{< relref "doc/developers/api-usage.en-us.md#authentication" >}}) instead of the password. | |
| 40 | + |
| 41 | +The login is optional and only needed if the package registry is private. |
| 42 | + |
| 43 | +## Publish a package |
| 44 | + |
| 45 | +First you have to pack the contents of your package: |
| 46 | + |
| 47 | +```shell |
| 48 | +swift package archive-source |
| 49 | +``` |
| 50 | + |
| 51 | +To publish the package perform a HTTP PUT request with the package content in the request body. |
| 52 | + |
| 53 | +```shell --user your_username:your_password_or_token \ |
| 54 | +curl -X PUT --user {username}:{password} \ |
| 55 | + -H "Accept: application/vnd.swift.registry.v1+json" \ |
| 56 | + -F source-archive=@/path/to/package.zip \ |
| 57 | + -F metadata={metadata} \ |
| 58 | + https://gitea.example.com/api/packages/{owner}/swift/{scope}/{name}/{version} |
| 59 | +``` |
| 60 | + |
| 61 | +| Placeholder | Description | |
| 62 | +| ----------- | ----------- | |
| 63 | +| `username` | Your Gitea username. | |
| 64 | +| `password` | Your Gitea password. If you are using 2FA or OAuth use a [personal access token]({{< relref "doc/developers/api-usage.en-us.md#authentication" >}}) instead of the password. | |
| 65 | +| `owner` | The owner of the package. | |
| 66 | +| `scope` | The package scope. | |
| 67 | +| `name` | The package name. | |
| 68 | +| `version` | The package version. | |
| 69 | +| `metadata` | (Optional) The metadata of the package. JSON encoded subset of https://schema.org/SoftwareSourceCode | |
| 70 | + |
| 71 | +You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first. |
| 72 | + |
| 73 | +## Install a package |
| 74 | + |
| 75 | +To install a Swift package from the package registry, add it in the `Package.swift` file dependencies list: |
| 76 | + |
| 77 | +``` |
| 78 | +dependencies: [ |
| 79 | + .package(id: "{scope}.{name}", from:"{version}") |
| 80 | +] |
| 81 | +``` |
| 82 | + |
| 83 | +| Parameter | Description | |
| 84 | +| ----------- | ----------- | |
| 85 | +| `scope` | The package scope. | |
| 86 | +| `name` | The package name. | |
| 87 | +| `version` | The package version. | |
| 88 | + |
| 89 | +Afterwards execute the following command to install it: |
| 90 | + |
| 91 | +```shell |
| 92 | +swift package resolve |
| 93 | +``` |
0 commit comments