Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --version Option + CI #7

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Prepare Release
on:
workflow_dispatch:
inputs:
release_type:
description: Type of release
type: choice
required: true
options:
- patch
- minor
- major

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4

- name: Bump Version file
id: bump
run: |
echo "version=$(swift package --allow-writing-to-package-directory version-file --target watcher --bump ${{ inputs.release_type }})" >> $GITHUB_OUTPUT

- name: Create pull request
id: cpr
uses: peter-evans/create-pull-request@v4
with:
commit-message: Bump Version.swift -> ${{ steps.bump.outputs.version }}
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
branch: release
delete-branch: true
title: '[CI] Prepare Version ${{ steps.bump.outputs.version }} Release'
body: |
Update `Version.swift` with bumped version number
draft: false
34 changes: 34 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Tag Release
on:
pull_request:
types:
- closed
branches:
- 'main'

jobs:
tag:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && github.head_ref == 'release'
steps:
- name: Git checkout
uses: actions/checkout@v4

- name: Get version
id: get-version
shell: bash
run: |
VERSION=$(grep -Eo '([0-9]+\.*)+' ${{ vars.VERSION_FILE_PATH }})
echo "current-version=$VERSION" >> $GITHUB_ENV

- name: Push tag
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ env.current-version }}',
sha: '${{ github.sha }}'
})
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
"version" : "1.0.4"
}
},
{
"identity" : "swift-version-file-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mobelux/swift-version-file-plugin",
"state" : {
"revision" : "b5bb65e2166ecf927ad20643e86501d5607f9cfc",
"version" : "0.1.0"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ let package = Package(
.package(url: "https://github.com/apple/swift-async-algorithms", from: "0.1.0"),
.package(url: "https://github.com/eonist/FileWatcher.git", from: "0.2.3"),
.package(url: "https://github.com/johnsundell/shellout.git", from: "2.3.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.4")
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.4"),
.package(url: "https://github.com/mobelux/swift-version-file-plugin", from: "0.1.0")
],
targets: [
.executableTarget(
Expand Down
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release Instructions

This tool uses the [swift-version-file-plugin](https://github.com/Mobelux/swift-version-file-plugin) Swift Package Manager command plugin to maintain a source file--[`Sources/watcher/Version.swift`](Sources/watcher/Version.swift)--supplying the value that is returned when the tool is run with the `--version` option. To ensure that this is properly maintained, releases should only be created using the [`Prepare Release`](http://github.com/Mobelux/Watcher/actions/workflows/prepare-release.yml) workflow.

To prepare a new release, run the workflow using `workflow_dispatch` event trigger from the `main` branch with the appropriate release type. This will create a new PR on a `release` branch containing an update to the Version file. Any additional changes related to the release, like updating a changelog, should be added to this PR. Merging the `release` branch into `main` will delete it and trigger the [`Tag Release`](.github/workflows/tag-release.yml) workflow to create a new tag corresponding to the value of the updated Version file.
5 changes: 5 additions & 0 deletions Sources/watcher/Version.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file was generated by the `VersionFile` package plugin.

enum Version {
static let number = "0.0.1"
}
5 changes: 5 additions & 0 deletions Sources/watcher/Watcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import WatcherCore
/// The entry point for the `Watcher` command-line tool.
@main
struct Watcher: AsyncParsableCommand {
/// Configuration for this command.
static let configuration = CommandConfiguration(
abstract: "Execute commands when watched directories are modified.",
version: Version.number)

/// The path to a configuration file.
@Option(name: .shortAndLong, help: "The path to a configuration file.")
var config: String? = nil
Expand Down