Skip to content

Commit

Permalink
Add build tools plugin option
Browse files Browse the repository at this point in the history
  • Loading branch information
sidepelican committed Apr 19, 2024
1 parent 6a253e1 commit 6323242
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ jobs:
body: |
```swift
.binaryTarget(
name: "mockolo",
url: "https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/mockolo.artifactbundle.zip",
checksum: "${{ needs.make-artifact-bundle.outputs.checksum }}"
name: "mockolo",
url: "https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/mockolo.artifactbundle.zip",
checksum: "${{ needs.make-artifact-bundle.outputs.checksum }}"
),
```
append_body: true
Expand Down
78 changes: 62 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,82 @@ Option 2: [Homebrew](https://brew.sh/)
$ brew install mockolo
```

Option 3: Use the binary
Option 3: Use as Build Tools Plugin with [Swift Package Manager](https://swift.org/package-manager/)

Go to the Release tab and download/install the binary directly.
Add binaryTarget and plugin definition to your `Package.swift`.
Binary url and checksum can be found in the [releases](https://github.com/uber/mockolo/releases) page.

```swift
targets: [
...
.plugin(
name: "RunMockolo",
capability: .buildTool(),
dependencies: [.target(name: "mockolo")]
),
.binaryTarget(
name: "mockolo",
url: "...",
checksum: "..."
),
```

Option 4: Clone and build/run
Implement the plugin and specify necessary directories in the arguments.

```
$ git clone https://github.com/uber/mockolo.git
$ cd mockolo
$ swift build -c release
$ .build/release/mockolo -h // see commandline input options below
- `Plugins/RunMockolo/RunMockoloPlugin.swift`

```swift
import PackagePlugin

@main struct RunMockoloPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
let generatedSourcePath = context.pluginWorkDirectory.appending("GeneratedMocks.swift")
let packageRoot = context.package.directory

return [
.prebuildCommand(
displayName: "Run mockolo",
executable: try context.tool(named: "mockolo").path,
arguments: [
"-s", packageRoot.appending("Sources", "MyModule").string,
"-d", generatedSourcePath,
],
outputFilesDirectory: context.pluginWorkDirectory
),
]
}
}
```

To call mockolo from any location, copy the executable into a directory that is part of your `PATH` environment variable.
Finally, add the plugin to the target requiring mockolo.

```swift
.target(
name: "MyTarget",
dependencies: [
...
],
plugins: [
.plugin(name: "RunMockolo"),
]
),
```

To check out a specific version,
Option 4: Use the binary

```
$ git tag -l
$ git checkout [tag]
```
Go to the Release tab and download/install the binary directly.

To use Xcode to build and run,
Option 5: Clone and build/run

```
$ swift package generate-xcodeproj
$ git clone https://github.com/uber/mockolo.git
$ cd mockolo
$ swift build -c release
$ .build/release/mockolo -h // see commandline input options below
```

To call mockolo from any location, copy the executable into a directory that is part of your `PATH` environment variable.

## Run

`Mockolo` is a commandline executable. To run it, pass in a list of the source file directories or file paths of a build target, and the destination filepath for the mock output. To see other arguments to the commandline, run `mockolo --help`.
Expand Down

0 comments on commit 6323242

Please sign in to comment.