Skip to content

Commit

Permalink
Rename and Prepare for Release (#8)
Browse files Browse the repository at this point in the history
* Add MIT license

* Add emojis, and “Alternatives” section

* Add documentation

* Add SPI manifest

* Rename targets

* DirectoryWatcher -> Watcher

* DirectoryWatcherCore -> WatcherCore

* DirectoryWatcherCoreTests -> WatcherCoreTests

* Update README

* DirectoryWatcherError -> WatcherError

* Update template

* Update Makefile, build docs

* Fix tests

* Add test workflow

* Fix runner image

* Update triggers, dependencies

* Remove verbose

* Support version option

* Add documentation for the release process

* Implement workflows

* Update SPI manifest doc targets

* Fix target

* Add configuration article

* Add installation article

* Rename workflow; update docs

* Test before release

* Add release configuration

* Exclude automated PRs

* Create release with workflow

* Workflow fixes and improvements

* Upgrade swift-version-file-plugin

* Upgrade action dependency
  • Loading branch information
mgacy authored Dec 7, 2023
1 parent 3c0bedd commit 8dfa086
Show file tree
Hide file tree
Showing 37 changed files with 409 additions and 93 deletions.
25 changes: 25 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuration-options
changelog:
exclude:
labels:
- ci
- ignore-for-release
authors:
- github-actions
- octocat
categories:
- title: Breaking Changes 🛠
labels:
- semver/major
- breaking-change
- title: New Features 🎉
labels:
- semver/minor
- enhancement
- title: Bug Fixes 🐛
labels:
- semver/patch
- bug
- title: Other Changes
labels:
- "*"
53 changes: 53 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release
on:
pull_request:
types:
- closed
branches:
- 'main'

jobs:
test:
name: Test
if: github.event.pull_request.merged == true && github.head_ref == 'release'
uses: mobelux/Watcher/.github/workflows/test.yml@main

release:
name: Release
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && github.head_ref == 'release'
needs: test
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@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ env.current-version }}',
sha: '${{ github.sha }}'
})
- name: Create release
uses: actions/github-script@v7
with:
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ env.current-version }}',
generate_release_notes: true,
draft: false,
prerelease: false
})
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
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on:
workflow_call:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
unit_tests:
if: github.event.pull_request.draft == false
name: Run Tests
runs-on: macos-13

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build
run: swift build

- name: Run tests
run: swift test
4 changes: 4 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [watcher, WatcherCore]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>FILEHEADER</key>
<string>
// ___FILENAME___
// DirectoryWatcher
// Watcher
//
// Created by ___FULLUSERNAME___ on ___DATE___.
//</string>
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Mobelux LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build:
swift build -c release

install: build
install .build/release/directory-watcher /usr/local/bin/directory-watcher
install .build/release/watcher /usr/local/bin/watcher

clean:
rm -rf .build
Expand Down
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" : "b1f5cee4453f0c6e838d28b2ea8c25f0f9604407",
"version" : "0.2.0"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
Expand Down
19 changes: 10 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
import PackageDescription

let package = Package(
name: "DirectoryWatcher",
name: "Watcher",
platforms: [
.macOS(.v13),
],
products: [
.executable(name: "directory-watcher", targets: ["DirectoryWatcher"]),
.library(name: "DirectoryWatcherCore", targets: ["DirectoryWatcherCore"])
.executable(name: "watcher", targets: ["watcher"]),
.library(name: "WatcherCore", targets: ["WatcherCore"])
],
dependencies: [
.package(url: "https://github.com/ChimeHQ/GlobPattern.git", from: "0.1.0"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"),
.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.2.0")
],
targets: [
.executableTarget(
name: "DirectoryWatcher",
name: "watcher",
dependencies: [
"DirectoryWatcherCore",
"WatcherCore",
.product(name: "ArgumentParser", package: "swift-argument-parser")
]
),
.target(
name: "DirectoryWatcherCore",
name: "WatcherCore",
dependencies: [
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "FileWatcher", package: "FileWatcher"),
Expand All @@ -39,8 +40,8 @@ let package = Package(
]
),
.testTarget(
name: "DirectoryWatcherCoreTests",
dependencies: ["DirectoryWatcherCore"]
name: "WatcherCoreTests",
dependencies: ["WatcherCore"]
)
]
)
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# DirectoryWatcher
# Watcher

Swift CLI tool to execute commands when watched directories are modified

## Installation
## 🖥 Installation

### Makefile
### 📄 Makefile

You can use the [`Makefile`](Makefile) to build and install:

```
make install
```

### Manual
### 🛠️ Manual

Clone this repo and build the executable:

```
swift build -c release directory-watcher
swift build -c release watcher
```

Copy the resulting binary at `.build/release/directory-watcher` to a location where it can be executed like `/usr/local/bin`
Copy the resulting binary at `.build/release/watcher` to a location where it can be executed like `/usr/local/bin`

## Configuration
## 🎛️ Configuration

DirectoryWatcher uses a `.watcher.yml` file at the root of the watched directory to define commands to execute when files matching a given glob -- and optionally, not matching an `exclude` glob -- are modified:
Watcher uses a `.watcher.yml` file at the root of the watched directory to define commands to execute when files matching a given glob -- and optionally, not matching an `exclude` glob -- are modified:

```yml
- pattern: "/Sources/**/*.swift"
Expand All @@ -37,14 +37,18 @@ DirectoryWatcher uses a `.watcher.yml` file at the root of the watched directory
The optional `name` value is used for terminal output.

## Usage
## ⚙️ Usage

```
USAGE: directory-watcher [--config <config>] [--throttle <throttle>]
USAGE: watcher [--config <config>] [--throttle <throttle>]

OPTIONS:
-c, --config <config> The path to a configuration file.
-t, --throttle <throttle>
The minimum interval, in seconds, between command execution in response to file changes.
-h, --help Show help information.
```
## 🔄 Alternatives
- [watchman](https://github.com/facebook/watchman)
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 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. 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. Add any additional changes related to the release, like updating a changelog, to this PR. Finally, merge the `release` branch into `main` to delete it and trigger the [`Create Release`](.github/workflows/create-release.yml) workflow. This will create a new tag corresponding to the value of the updated Version file and a new release.
26 changes: 0 additions & 26 deletions Sources/DirectoryWatcher/DirectoryWatcher.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Configuration.swift
// DirectoryWatcher
// Watcher
//
// Created by Mathew Gacy on 6/23/23.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Constants.swift
// DirectoryWatcher
// Watcher
//
// Created by Mathew Gacy on 6/23/23.
//
Expand Down
Loading

0 comments on commit 8dfa086

Please sign in to comment.