feat: Working on command-line documentation.
Some checks failed
CI / Ubuntu (push) Has been cancelled

This commit is contained in:
2024-12-27 14:51:55 -05:00
parent 8d73287a60
commit 4420bd428a
28 changed files with 674 additions and 80 deletions

View File

@@ -1,11 +1,15 @@
{
"target" : {
"module" : { "name" : "bump-version" }
},
"strategy" : {
"semvar" : {
"preRelease" : { "strategy": { "gitTag" : {} } },
"strategy" : { "gitTag": { "exactMatch": false } }
"allowPreRelease" : true,
"strategy" : {
"command" : {
"arguments" : [
"my-command",
"--some-option"
]
}
}
}
}
}

1
.prettierignore Normal file
View File

@@ -0,0 +1 @@
**/*.docc/*.md

View File

@@ -1,4 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [CliVersion]
- documentation_targets: [BumpVersion]

View File

@@ -1,42 +0,0 @@
PLATFORM_MACOS = macOS
CONFIG := debug
DOCC_TARGET ?= CliClient
DOCC_BASEPATH = $(shell basename "$(PWD)")
DOCC_DIR ?= ./docs
SWIFT_VERSION ?= "5.10"
clean:
rm -rf .build
build-documentation:
swift package \
--allow-writing-to-directory "$(DOCC_DIR)" \
generate-documentation \
--target "$(DOCC_TARGET)" \
--disable-indexing \
--transform-for-static-hosting \
--hosting-base-path "$(DOCC_BASEPATH)" \
--output-path "$(DOCC_DIR)"
preview-documentation:
swift package \
--disable-sandbox \
preview-documentation \
--target "$(DOCC_TARGET)"
test-linux:
docker run --rm \
--volume "$(PWD):$(PWD)" \
--workdir "$(PWD)" \
"swift:$(SWIFT_VERSION)" \
swift test
test-library:
swift test -c $(CONFIG)
update-version:
swift package \
--disable-sandbox \
--allow-writing-to-package-directory \
update-version \
git-version

View File

@@ -8,7 +8,7 @@ let package = Package(
.macOS(.v13)
],
products: [
.executable(name: "bump-version", targets: ["bump-version"]),
.executable(name: "bump-version", targets: ["BumpVersion"]),
.library(name: "CliClient", targets: ["CliClient"]),
.library(name: "ConfigurationClient", targets: ["ConfigurationClient"]),
.library(name: "FileClient", targets: ["FileClient"]),
@@ -28,7 +28,7 @@ let package = Package(
],
targets: [
.executableTarget(
name: "bump-version",
name: "BumpVersion",
dependencies: [
"CliClient",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
@@ -96,7 +96,7 @@ let package = Package(
name: "BuildWithVersionPlugin",
capability: .buildTool(),
dependencies: [
"bump-version"
"BumpVersion"
]
),
.plugin(
@@ -111,7 +111,7 @@ let package = Package(
]
),
dependencies: [
"bump-version"
"BumpVersion"
]
)
]

View File

@@ -150,6 +150,7 @@ extension ConfigCommand {
}
// TODO: Add verbose.
// TODO: Need to be able to generate a branch style config file.
@dynamicMemberLookup
struct ConfigCommandOptions: ParsableArguments {

View File

@@ -0,0 +1,101 @@
# Basic Configuration
Basic configuration examples.
## Overview
Generating a configuration file for your application is the easiest way to use the command-line
tool. The configuration specifies the location of the version file, either by a path to the file or
by the module that a `Version.swift` file resides in. It also declares the strategy for generating
new versions.
The command-line tool comes with a command to generate the configuration file for you, this should
be ran from the root of your project.
```bash
bump-version config generate --target-module my-tool
```
The above command produces the following in a file named `.bump-version.json` with the generated
default settings. This will generate semvar style version (example: `1.0.0`).
```json
{
"strategy": {
"semvar": {
"allowPreRelease": true,
"strategy": {
"gitTag": {
"exactMatch": false
}
}
}
},
"target": {
"module": {
"name": "my-tool"
}
}
}
```
> Note: The above does not add a pre-release strategy although it "allows" it if you pass an option
> to command later, if you set "allowPreRelease" to false it will ignore any attempts to add a
> pre-release strategy when bumping the version.
Most commands accept the same options for configuration as the above `config generate` command.
Those get merged with your project configuration when calling a command, that allows you to override
any of your defaults depending on your use case. You can also generate several configuration files
and specify them by passing the `-f | --configuration-file` to the command.
## Inspecting parsed configuration.
You can inspect the configuration that get's parsed by using the `config dump` command. The dump
command will print the parsed `json` to `stdout`, which can be helpful in confirming that your
configuration is valid and does not work unexpectedly.
```bash
bump-version config dump <options / overrides>
```
The dump command can also be used to generate a different configuration that is merged with your
default.
```bash
bump-version config dump --pre-release-git-tag-style > .bump-version.prerelease.json
```
Which would produce the following in `.bump-version.prerelease.json`
```json
{
"strategy": {
"semvar": {
"allowPreRelease": true,
"preRelease": {
"strategy": {
"gitTag": {}
}
},
"strategy": {
"gitTag": {
"exactMatch": false
}
}
}
},
"target": {
"module": {
"name": "my-tool"
}
}
}
```
You could then use this file when bumping your version.
```bash
bump-version bump -f .bump-version.prerelease.json
```
> See Also: <doc:ConfigurationReference>

View File

@@ -0,0 +1,108 @@
# Command Reference
Learn about the provided commands.
## Overview
The command-line tool provides the following commands.
> See Also:
>
> 1. <doc:BasicConfiguration>
> 1. <doc:ConfigurationReference>
All commands output the path of the file they generate or write to, to allow them to be piped into
other commands, however this will not work if you specify `--verbose` because then other output is
also written to `stdout`.
### Bump Command
This bumps the version to the next version based on the project configuration or passed in options.
This is the default command when calling the `bump-version` tool, so specifying the `bump` command
is not required, but will be shown in examples below for clarity.
> See Also: <doc:OptionsReference>
The following options are used to declare which part of a semvar to bump to the next version, they
are ignored if your configuration or options specify to use a `branch` strategy.
| Long | Description |
| ------------- | --------------------------------------- |
| --major | Bump the major portion of the semvar |
| --minor | Bump the minor portion of the semvar |
| --patch | Bump the patch portion of the semvar |
| --pre-release | Bump the pre-release suffix of a semvar |
#### Bump Command Usage Examples
```bash
bump-version bump --minor
```
Show the output, but don't update the version file.
```bash
bump-version bump --major --dry-run
```
### Generate Command
This generates a version file based on your configuration, setting it's initial value based on your
projects configuration strategy. This is generally only ran once after setting up a project.
```bash
bump-version generate
```
### Configuration Commands
The following commands are used to work with project configuration.
#### Generate Command
Generates a configuration file based on the passed in options.
> See Also: <doc:OptionsReference>
The following options are used to declare strategy used for deriving the version.
| Long | Description |
| -------- | ------------------------------------------------------- |
| --branch | Use the branch strategy |
| --semvar | Use the semvar strategy (default) |
| --print | Print the output to stdout instead of generating a file |
##### Generate Configuration Example
```bash
bump-version config generate -m my-tool
```
The above generates a configuration file using the default version strategy for a target module
named 'my-tool'.
#### Dump Command
Dumps the parsed configuration to `stdout`.
> See Also: <doc:OptionsReference>
The following options are used to declare what output gets printed.
| Long | Description |
| ------- | -------------------- |
| --json | Print json (default) |
| --swift | Print swift struct |
##### Dump Configuration Example
```bash
bump-version config dump --disable-pre-release
```
This command can also be used to extend a configuration file with new configuration by sending the
output to a new file.
```bash
bump-version config dump --disable-pre-release > .bump-version.prod.json
```

View File

@@ -0,0 +1,225 @@
# Configuration Reference
Learn about the configuration.
## Target
The target declares where a version file lives that can be bumped by the command-line tool.
A target can be specified either as a path from the root of the project to a file that contains the
version or as a module that contains the version file.
> Note: A version file should not contain any other code aside from the version as the entire file
> contents get over written when bumping the version.
### Target - Path Example
```json
{
"target": {
"path": "Sources/my-tool/Version.swift"
}
}
```
### Target - Module Example
When using the module style a file name is not required if you use the default file name of
`Version.swift`, however it can be customized in your target specification.
```json
{
"target": {
"module": {
"fileName": "CustomVersion.swift",
"name": "my-tool"
}
}
}
```
The above will parse the path to the file as `Sources/my-tool/CustomVersion.swift`.
## Strategy
The strategy declares how to generate the next version of your project. There are currently two
strategies, `branch` and `semvar`, that we will discuss.
### Branch Strategy
This is the most basic strategy, which will derive the version via the git branch and optionally the
short version of the commit sha.
An example of this style may look like: `main-8d73287a60`.
```json
{
"strategy": {
"branch": {
"includeCommitSha": true
}
}
}
```
If you set `'"includeCommitSha" : false'` then only the branch name will be used.
### Semvar Strategy
This is the most common strategy to use. It has support for generating the next version using either
`gitTag` or a custom `command` strategy.
#### Git Tag Strategy
The `gitTag` strategy derives the next version using the output of `git describe --tags` command.
This requires a commit to have a semvar style tag in it's history, otherwise we will use `0.0.0` as
the tag until a commit is tagged.
```json
{
"strategy": {
"semvar": {
"allowPreRelease": true,
"strategy": {
"gitTag": {
"exactMatch": false
}
}
}
}
}
```
If you set `'"exactMatch": true'` then bumping the version will fail on commits that are not
specifically tagged.
#### Custom Command Strategy
The custom `command` strategy allows you to call an external command to derive the next version. The
external command should return something that can be parsed as a semvar.
```json
{
"strategy": {
"semvar": {
"allowPreRelease": true,
"strategy": {
"command": {
"arguments": ["my-command", "--some-option", "foo"]
}
}
}
}
}
```
> Note: All arguments to custom commands need to be a separate string in the arguments array
> otherwise they may not get passed appropriately to the command, so
> `"my-command --some-option foo"` will likely not work as expected.
#### Pre-Release
Semvar strategies can also include a pre-release strategy that adds a suffix to the semvar version
that can be used. In order for pre-release suffixes to be allowed the `'"allowPreRelease": true'`
must be set on the semvar strategy, you must also supply a pre-release strategy either when calling
the bump-version command or in your configuration.
Currently there are three pre-release strategies, `branch`, `gitTag`, and custom `command`, which we
will discuss.
A pre-release semvar example: `1.0.0-1-8d73287a60`
##### Branch
This will use the branch and optionally short version of the commit sha in order to derive the
pre-release suffix.
```json
{
"strategy": {
"semvar": {
"allowPreRelease": true,
"preRelease": {
"strategy": {
"branch": {
"includeCommitSha": true
}
}
},
...
}
}
}
```
This would produce something similar to: `1.0.0-main-8d73287a60`
##### Git Tag
This will use the full output of `git describe --tags` to include the pre-release suffix.
```json
{
"strategy" : {
"semvar" : {
"allowPreRelease" : true,
"preRelease" : {
"strategy" : {
"gitTag" : {}
}
},
...
}
}
}
```
This would produce something similar to: `1.0.0-10-8d73287a60`
##### Custom Command
This allows you to call an external command to generate the pre-release suffix. We will use whatever
the output is as the suffix.
```json
{
"strategy": {
"semvar": {
"allowPreRelease": true,
"preRelease": {
"strategy": {
"command": {
"arguments": ["my-command", "--some-option", "foo"]
}
}
}
}
}
}
```
> Note: All arguments to custom commands need to be a separate string in the arguments array
> otherwise they may not get passed appropriately to the command, so
> `"my-command --some-option foo"` will likely not work as expected.
##### Pre-Release Prefixes
All pre-release strategies can also accept a `prefix` that will appended prior to the generated
pre-release suffix. This can also be used without providing a pre-release strategy to only append
the `prefix` to the semvar.
```json
{
"strategy" : {
"semvar" : {
"allowPreRelease" : true,
"preRelease" : {
"prefix": "rc"
},
...
}
}
}
```
This would produce something similar to: `1.0.0-rc`

View File

@@ -0,0 +1,47 @@
# Options Reference
Common options used for the commands.
## Overview
The commands mostly all accept similar options, below is a list of those options and a description
of their usage.
### General Options
| Short | Long | Argument | Description |
| ----- | --------------- | -------- | -------------------------------------------------------------------- |
| N/A | --dry-run | N/A | Perform the command, but don't write any output files |
| N/A | --git-directory | <path> | The path to the root of your project, defaults to current directory |
| -h | --help | N/A | Show help for a command |
| -v | --verbose | N/A | Increase logging level, can be passed multiple times (example: -vvv) |
| N/A | --version | N/A | Show the version of the command line tool |
### Configuration Options
| Short | Long | Argument | Description |
| ----- | ---------------------------------- | ----------- | ---------------------------------------------------------------------------------- |
| -f | --configuration-file | <path> | The path to the configuration to use. |
| -m | --target-module | <name> | The target module name inside your project |
| -n | --target-file-name | <name> | The file name for the version to be found inside the module |
| -p | --target-file-path | <path> | Path to a version file in your project |
| N/A | --enable-git-tag/--disable-git-tag | N/A | Use the git-tag version strategy |
| N/A | --require-exact-match | N/A | Fail if a tag is not specifically set on the commit |
| N/A | --require-existing-semvar | N/A | Fail if an existing semvar is not found in the version file. |
| -c | --custom-command | <arguments> | Use a custom command strategy for the version (any options need to proceed a '--') |
| N/A | --commit-sha/--no-commit-sha | N/A | Use the commit sha with branch version or pre-release strategy |
#### Pre-Release Options
| Short | Long | Argument | Description |
| ----- | ---------------------------- | ----------- | ------------------------------------------------------------ |
| -d | --disable-pre-release | N/A | Disable pre-relase suffixes from being used |
| -b | --pre-release-branch-style | N/A | Use the branch and commit sha style for pre-release suffixes |
| N/A | --commit-sha/--no-commit-sha | N/A | Use the commit sha with branch pre-release strategy |
| -g | --pre-release-git-tag-style | N/A | Use the git tag style for pre-release suffixes |
| N/A | --pre-release-prefix | <prefix> | A prefix to use before a pre-release suffix |
| N/A | --custom-pre-release | <arguments> | Use custom command strategy for pre-release suffix |
> Note: When using one of the `--custom-*` options then any arguments passed will be used for
> arguments when calling your custom strategy, if the external tool you use requires options they
> must proceed a '--' otherwise you will get an error that an 'unexpected option' is being used.

View File

@@ -0,0 +1,77 @@
# Plugins Reference
Learn about using the provided package plugins.
## Overview
There are two provided plugins that can be used, this describes their usage.
### Build with Version
The `BuildWithVersion` plugin uses your project configuration to automatically generate a version
file when swift builds your project. You can use the plugin by declaring it as dependency in your
project.
```swift
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
platforms:[.macOS(.v13)],
dependencies: [
...,
.package(url: "https://github.com/m-housh/swift-bump-version.git", from: "0.2.0")
],
targets: [
.executableTarget(
name: "<target name>",
dependencies: [...],
plugins: [
.plugin(name: "BuildWithVersionPlugin", package: "swift-bump-version")
]
)
]
)
```
### Manual Plugin
There is also a `BumpVersionPlugin` that allows you to run the `bump-version` tool without
installing the command-line tool on your system, however it does make the usage much more verbose.
Include as dependency in your project.
```swift
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
platforms:[.macOS(.v13)],
dependencies: [
...,
.package(url: "https://github.com/m-housh/swift-bump-version.git", from: "0.2.0")
],
targets: [
...
]
)
```
Then you can use the manual plugin.
```
swift package \
--disable-sandbox \
--allow-writing-to-package-directory \
bump-version \
bump \
--minor
```
> Note: Anything after the `'bump-version'` in the above get's passed directly to the bump-version
> command-line tool, so you can use this to run any of the provided commands, the above shows
> bumping the minor semvar as a reference example.
>
> See Also: <doc:CommandReference>

View File

@@ -0,0 +1,62 @@
# ``BumpVersion``
@Metadata {
@DisplayName("bump-version")
@DocumentationExtension(mergeBehavior: override)
}
A command-line tool for managing swift application versions.
## Overview
This tool aims to provide a way to manage application versions in your build
pipeline. It can be used as a stand-alone command-line tool or by using one of
the provided swift package plugins.
## Installation
The command-line tool can be installed via homebrew.
```bash
brew tap m-housh/formula
brew install bump-version
```
## Package Plugins
Package plugins can be used in a swift package manager project.
```swift
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
platforms:[.macOS(.v13)],
dependencies: [
...,
.package(url: "https://github.com/m-housh/swift-bump-version.git", from: "0.2.0")
],
targets: [
.executableTarget(
name: "<target name>",
dependencies: [...],
plugins: [
.plugin(name: "BuildWithVersionPlugin", package: "swift-bump-version")
]
)
]
)
```
> See Also: <doc:PluginsReference>
## Topics
### Articles
- <doc:BasicConfiguration>
- <doc:ConfigurationReference>
- <doc:CommandReference>
- <doc:OptionsReference>
- <doc:PluginsReference>

View File

@@ -9,6 +9,7 @@ import ShellClient
public extension DependencyValues {
/// The cli-client that runs the command line tool commands.
var cliClient: CliClient {
get { self[CliClient.self] }
set { self[CliClient.self] = newValue }
@@ -70,6 +71,7 @@ public struct CliClient: Sendable {
}
extension CliClient: DependencyKey {
public static let testValue: CliClient = Self()
public static func live(environment: [String: String]) -> Self {

View File

@@ -1,12 +1,12 @@
# 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.
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.
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 \
@@ -32,16 +32,17 @@ swift package --disable-sandbox \
## Options
Both manual versions also allow the following options to customize the operation, the
options need to come after the plugin name.
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 \

View File

@@ -1,4 +1,4 @@
# CliClient
# ``CliClient``
Derive a version for a command-line tool from git tags or a git sha.
@@ -9,8 +9,8 @@ Derive a version for a command-line tool from git tags or a git sha.
## Overview
This tool exposes several plugins that can be used to derive a version for a command line program at
build time or by manually running the plugin. The version is derived from git tags and falling back
to the branch and git sha if a tag is not set for the current worktree state.
build time or by manually running the plugin. The version is generally derived from git tags,
however it can be configured to run custom commands.
## Articles

View File

@@ -1,3 +0,0 @@
enum Constants {
static let defaultFileName = "Version.swift"
}

View File

@@ -117,8 +117,8 @@ public extension Configuration {
public init(
allowPreRelease: Bool? = true,
preRelease: PreRelease? = nil,
requireExistingFile: Bool? = true,
requireExistingSemVar: Bool? = true,
requireExistingFile: Bool? = false,
requireExistingSemVar: Bool? = false,
strategy: Strategy? = nil
) {
self.allowPreRelease = allowPreRelease

View File

@@ -1,5 +0,0 @@
# Application
## Articles
- <doc:Installation>

View File

@@ -1,3 +0,0 @@
# Installation
You can install the command-line application by...

View File

@@ -72,3 +72,21 @@ get-release-sha prefix="": (build "release")
stripped="${sha% *}" && \
echo "$stripped" | pbcopy && \
echo "Copied sha to clipboard: $stripped"
# Preview the documentation locally.
preview-documentation target="BumpVersion":
swift package \
--disable-sandbox \
preview-documentation \
--target {{target}}
# Preview the documentation locally.
build-documentation dir="./docs" target="BumpVersion" basePath="bump-version":
swift package \
--allow-writing-to-directory {{dir}} \
generate-documentation \
--target {{target}} \
--disable-indexing \
--transform-for-static-hosting \
--hosting-base-path {{basePath}} \
--output-path {{dir}}