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

Rename and Prepare for Release #8

Merged
merged 37 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
73c251b
Add MIT license
mgacy Dec 2, 2023
0f1cce3
Add emojis, and “Alternatives” section
mgacy Dec 2, 2023
498fbfd
Add documentation
mgacy Dec 2, 2023
cb4426e
Add SPI manifest
mgacy Dec 2, 2023
0250e8a
Rename targets
mgacy Dec 3, 2023
529c267
DirectoryWatcher -> Watcher
mgacy Dec 3, 2023
e3efa9e
DirectoryWatcherCore -> WatcherCore
mgacy Dec 3, 2023
e49d21e
DirectoryWatcherCoreTests -> WatcherCoreTests
mgacy Dec 3, 2023
f7dadf7
Update README
mgacy Dec 3, 2023
e1b089b
DirectoryWatcherError -> WatcherError
mgacy Dec 3, 2023
5d61c55
Update template
mgacy Dec 3, 2023
37fd3e0
Update Makefile, build docs
mgacy Dec 3, 2023
102b4dd
Fix tests
mgacy Dec 3, 2023
56c576c
Add test workflow
mgacy Dec 3, 2023
e31821a
Fix runner image
mgacy Dec 3, 2023
9f329fa
Update triggers, dependencies
mgacy Dec 3, 2023
bd9c15f
Remove verbose
mgacy Dec 3, 2023
0484465
Support version option
mgacy Dec 3, 2023
c70c472
Add documentation for the release process
mgacy Dec 3, 2023
1d71681
Implement workflows
mgacy Dec 3, 2023
9cccc8d
Update SPI manifest doc targets
mgacy Dec 3, 2023
856403b
Merge pull request #4 from Mobelux/refactor/release-prep/1-initial
mgacy Dec 4, 2023
066d7ff
Merge pull request #5 from Mobelux/refactor/release-prep/2-rename
mgacy Dec 4, 2023
41d4a36
Merge pull request #6 from Mobelux/refactor/release-prep/3-ci
mgacy Dec 4, 2023
f1b663c
Fix target
mgacy Dec 4, 2023
19df257
Merge pull request #7 from Mobelux/refactor/release-prep/4-version-su…
mgacy Dec 4, 2023
d5907bc
Add configuration article
mgacy Dec 7, 2023
fe5d033
Add installation article
mgacy Dec 7, 2023
bb1c87d
Rename workflow; update docs
mgacy Dec 7, 2023
e214c17
Test before release
mgacy Dec 7, 2023
aedf04b
Add release configuration
mgacy Dec 7, 2023
1f753a6
Exclude automated PRs
mgacy Dec 7, 2023
bf73c65
Create release with workflow
mgacy Dec 7, 2023
669faa9
Workflow fixes and improvements
mgacy Dec 7, 2023
ca8d9b8
Upgrade swift-version-file-plugin
mgacy Dec 7, 2023
b4b374f
Upgrade action dependency
mgacy Dec 7, 2023
2d2f19c
Merge pull request #9 from Mobelux/refactor/release-prep/5-remaining
mgacy Dec 7, 2023
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
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