Renamed to cli version.

This commit is contained in:
2023-03-15 12:44:52 -04:00
parent 8ebfa1975a
commit 742546ec08
21 changed files with 197 additions and 56 deletions

View File

@@ -7,19 +7,26 @@ Learn how to integrate the plugins into your project
Use the plugins by including as a package to your project and declaring in the `plugins` section of
your target.
> Note: You must use swift-tools version 5.6 or greater for package plugins and
> target `macOS(.v10_15)` or greater.
```swift
// swift-tools-version: 5.7
import PackageDescription
let package = Package(
...,
platforms:[.macOS(.v10_15)],
dependencies: [
...,
.package(url: "https://github.com/m-housh/swift-git-version.git", from: "0.1.0")
.package(url: "https://github.com/m-housh/swift-cli-version.git", from: "0.1.0")
],
targets: [
.executableTarget(
name: "<target name>",
dependencies: [...],
plugins: [
.plugin(name: "BuildWithVersionPlugin", package: "swift-git-version")
.plugin(name: "BuildWithVersionPlugin", package: "swift-cli-version")
]
)
]
@@ -47,5 +54,16 @@ struct MyCliTool: ParsableCommand {
}
```
You will have access to the `VERSION` string variable even though it is not declared in your source
files.
After you enable the plugin, you will have access to the `VERSION` string variable even though it is
not declared in your source files.
![Trust & Enable](trust)
> Note: If your `DerivedData` folder lives in a directory that is a mounted volume / or somewhere
> that is not under your home folder then you may get build failures using the build tool
> plugin, it will work if you build from the command line and pass the `--disable-sandbox` flag to the
> build command or use one of the manual methods.
## See Also
<doc:ManualPlugins>

View File

@@ -0,0 +1,68 @@
# Manual Plugins
There are two plugins that are included that can be ran manually, if the build tool plugin does not fit
your use case.
## Generate Version
The `generate-version` plugin will create a `Version.swift` file in the given target. You can
run it by running the following command.
```bash
swift package --disable-sandbox \
--allow-writing-to-package-directory \
generate-version \
<target>
```
> Note: If using the manual version then the `VERSION` variable is an optional string that will be
> `nil`, allowing you to run the `update-version` command in your build pipeline.
## Update Version
The `update-version` plugin can be ran in your build pipeline process to set the version prior to
building for distribution.
```bash
swift package --disable-sandbox \
--allow-writing-to-package-directory \
update-version \
<target>
```
## Options
Both manual versions also allow the following options to customize the operation, the
options need to come after the plugin name.
| Option | Description |
| ------ | ----------- |
| --dry-run | Do not write to any files, but describe where values would be written |
| --filename | Override the file name to be written in the target directory |
| --verbose | Increase the logging output |
### Example with options
```bash
swift package \
--allow-writing-to-package-directory \
generate-version \
--dry-run \
--verbose \
<target>
```
## View the Executable Options
You can also run the following command to view the options in your terminal
```bash
swift run cli-version --help
```
Or
```bash
swift run cli-version <verb> --help
```
Where `verb` is one of, `build`, `generate`, or `update`.

View File

@@ -1,10 +1,10 @@
# ``GitVersion``
# ``CliVersion``
Derive a version for a command line tool from git tags or a git sha.
## Additional Resources
[Github Repo](https://github.com/m-housh/swift-git-version)
[Github Repo](https://github.com/m-housh/swift-cli-version)
## Overview
@@ -15,8 +15,9 @@ the branch and git sha if a tag is not set for the current worktree state.
## Articles
- <doc:GettingStarted>
- <doc:ManualPlugins>
### Api
## Api
- ``FileClient``
- ``GitVersionClient``

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

View File

@@ -1,9 +1,9 @@
import ArgumentParser
import Foundation
import GitVersion
import CliVersion
import ShellClient
extension GitVersionCommand {
extension CliVersionCommand {
struct Build: ParsableCommand {
static var configuration: CommandConfiguration = .init(
abstract: "Used for the build with version plugin.",

View File

@@ -2,10 +2,10 @@ import ArgumentParser
import Foundation
@main
struct GitVersionCommand: ParsableCommand {
struct CliVersionCommand: ParsableCommand {
static var configuration: CommandConfiguration = .init(
commandName: "git-version",
commandName: "cli-version",
version: VERSION ?? "0.0.0",
subcommands: [
Build.self,

View File

@@ -1,10 +1,10 @@
import ArgumentParser
import Dependencies
import Foundation
import GitVersion
import CliVersion
import ShellClient
extension GitVersionCommand {
extension CliVersionCommand {
struct Generate: ParsableCommand {
static var configuration: CommandConfiguration = .init(

View File

@@ -1,9 +1,9 @@
import ArgumentParser
import Foundation
import GitVersion
import CliVersion
import ShellClient
extension GitVersionCommand {
extension CliVersionCommand {
struct Update: ParsableCommand {
static var configuration: CommandConfiguration = .init(