|
1 | | -[![Build Status][build status badge]][build status] |
2 | | -[![Platforms][platforms badge]][platforms] |
3 | | - |
4 | 1 | # XcodeCloudKit |
5 | 2 |
|
6 | 3 | The Swift SDK that makes working with the Xcode Cloud endpoints from the App Store Connect API a breeze! |
7 | 4 |
|
| 5 | +[![Build Status][build status badge]][build status] |
| 6 | +[![Platforms][platforms badge]][platforms] |
| 7 | + |
8 | 8 | [build status]: https://github.com/runway-org/xcode-cloud-kit/actions |
9 | 9 | [build status badge]: https://github.com/runway-org/xcode-cloud-kit/workflows/CI/badge.svg |
10 | 10 | [platforms]: https://swiftpackageindex.com/runway-org/xcode-cloud-kit |
11 | 11 | [platforms badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmattmassicotte%2FPackageTemplate%2Fbadge%3Ftype%3Dplatforms |
12 | 12 |
|
13 | 13 | ## How to use `XcodeCloudKit`? |
14 | 14 |
|
| 15 | +`XcodeCloudKit` relies on [Antoine Van Der Lee's appstoreconnect-swift-sdk](https://github.com/AvdLee/appstoreconnect-swift-sdk), which provides a fantastic Swift interface to interact with the App Store Connect API. |
| 16 | + |
| 17 | +The App Store Connect API requires all network requests to be authenticated and, as it does not support OAuth, you must create an API key from the dashboard. |
| 18 | + |
| 19 | +Once you have generated a key, you must initialise the SDK by using its `Factory` enum: |
| 20 | + |
| 21 | +```swift |
| 22 | +import XcodeCloudKit |
| 23 | + |
| 24 | +let xcodeCloudKit = try Factory.make( |
| 25 | + issuerID: "🙈", |
| 26 | + privateKeyID: "🙈", |
| 27 | + privateKey: "🙈" |
| 28 | +) |
| 29 | +``` |
| 30 | + |
| 31 | +`XcodeCloudKit`'s structure tries to mirror Xcode Cloud's data structure as closely as possible and has three main entities: **products**, **workflows** and **build**s. |
| 32 | + |
| 33 | +**Product**s are the Xcode Cloud representations of your app and you can request a list of them and select one using the SDK: |
| 34 | + |
| 35 | +```swift |
| 36 | +// Get a list of all available products |
| 37 | +let allProducts = try await xcodeCloudKit.allProducts() |
| 38 | +// Get a product by Xcode Cloud ID |
| 39 | +let productById = try await xcodeCloudKit.product(withId: "...") |
| 40 | +// By repository name |
| 41 | +let product = try await xcodeCloudKit.product(withRepositoryName: "NowPlaying") |
| 42 | +``` |
| 43 | + |
| 44 | +Once you have a product, you can access one or all of its **workflows**, which are the blueprints of your CI/CD pipelines, directly on the instance: |
| 45 | + |
| 46 | +```swift |
| 47 | +// Get a list of all available workflows |
| 48 | +let allWorkflows = try await product?.workflows() |
| 49 | +// Get a workflow by Xcode Cloud ID |
| 50 | +let workflowByID = try await product?.workflow(withId: "...") |
| 51 | +// Get a workflow by name |
| 52 | +let workflow = try await product?.workflow(withName: "Test Workflow") |
| 53 | +``` |
| 54 | + |
| 55 | +Once you have a **workflow**, you can access the list of **builds** or workflow runs for a specific workflow: |
| 56 | + |
| 57 | +```swift |
| 58 | +// Get a list of all available builds |
| 59 | +let allBuilds = try await workflow?.allBuilds() |
| 60 | +// Get a build by its number |
| 61 | +let build = try await workflow?.build(withNumber: 32) |
| 62 | +``` |
| 63 | + |
| 64 | +And you can even start a new **build** for a specific workflow at a git reference of your choice: |
| 65 | + |
| 66 | +```swift |
| 67 | +try await workflow?.start(atGitReference: .branch(name: "main")) |
| 68 | +``` |
| 69 | + |
| 70 | +> Note that the SDK's functionalities are limited at the moment and more features will get added in the coming days and months. |
| 71 | +
|
| 72 | +## Installation |
| 73 | + |
| 74 | +As it stands, `XcodeCloudKit` can only be installed via SPM as follows: |
| 75 | + |
| 76 | +```swift |
| 77 | +dependencies: [ |
| 78 | + .package(url: "https://github.com/runway-org/xcode-cloud-kit.git", .upToNextMajor(from: "0.1.0")) |
| 79 | +] |
| 80 | +``` |
| 81 | + |
15 | 82 | ## License |
16 | 83 |
|
17 | 84 | **XcodeCloudKit** is available under the MIT license, and uses source code from open source projects. See the [LICENSE](./LICENSE) file for more info. |
|
0 commit comments