Skip to content
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
30 changes: 30 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: test-linux
on:
pull_request:
push:
branches:
- master
tags:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: False

name: "[test] [linux]"
steps:
# ------------------------------------------------------------
# Setup
# ------------------------------------------------------------
- name: Checkout repository
uses: actions/checkout@v2

# ------------------------------------------------------------
# Tests: Behaviour
# ------------------------------------------------------------
- name: test
shell: bash
run: |
make test
30 changes: 30 additions & 0 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: test-macos
on:
pull_request:
push:
branches:
- master
tags:

jobs:
test:
runs-on: macos-latest
strategy:
fail-fast: False

name: "[test] [macos]"
steps:
# ------------------------------------------------------------
# Setup
# ------------------------------------------------------------
- name: Checkout repository
uses: actions/checkout@v2

# ------------------------------------------------------------
# Tests: Behaviour
# ------------------------------------------------------------
- name: test
shell: bash
run: |
make test
30 changes: 30 additions & 0 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: test-windows
on:
pull_request:
push:
branches:
- master
tags:

jobs:
test:
runs-on: windows-latest
strategy:
fail-fast: False

name: "[test] [windows]"
steps:
# ------------------------------------------------------------
# Setup
# ------------------------------------------------------------
- name: Checkout repository
uses: actions/checkout@v2

# ------------------------------------------------------------
# Tests: Behaviour
# ------------------------------------------------------------
- name: test
shell: bash
run: |
make test
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ endif
# -------------------------------------------------------------------------------------------------
# Default configuration
# -------------------------------------------------------------------------------------------------
.PHONY: help lint
.PHONY: help lint test

FL_VERSION = 0.3
FL_IGNORES = .git/,.github/
Expand All @@ -16,6 +16,7 @@ FL_IGNORES = .git/,.github/
# -------------------------------------------------------------------------------------------------
help:
@echo "lint Lint repository"
@echo "test Run integration tests"


# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -43,3 +44,10 @@ _lint-shell:
@echo "# Shellcheck"
@echo "# -------------------------------------------------------------------- #"
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/mnt -w /mnt koalaman/shellcheck:stable watcherd


# -------------------------------------------------------------------------------------------------
# Test Targets
# -------------------------------------------------------------------------------------------------
test:
./test/01.sh
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# watcherd

![tag](https://img.shields.io/github/v/tag/devilbox/watcherd.svg?colorB=orange&sort=semver)
[![linting](https://github.com/devilbox/watcherd/workflows/linting/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Alinting)
[![test-linux](https://github.com/devilbox/watcherd/workflows/test-linux/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Atest-linux)
[![test-macos](https://github.com/devilbox/watcherd/workflows/test-macos/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Atest-macos)
[![test-windows](https://github.com/devilbox/watcherd/workflows/test-windows/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Atest-windows)

**[watcherd](https://github.com/devilbox/watcherp/blob/master/watcherd)** will look for directory changes (added and deleted directories) under the specified path (`-p`) and will execute specified commands or shell scripts (`-a`, `-d`) depending on the event.
Once all events have happened during one round (`-i`), a trigger command can be executed (`-t`).
Expand Down
73 changes: 73 additions & 0 deletions test/01.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

SCRIPT_PATH="$( cd "$(dirname "$0")" && pwd -P )"

BIN_PATH="${SCRIPT_PATH}/.."
DIR_PATH="${SCRIPT_PATH}/dirs"



cleanup() {
rm -rf "${DIR_PATH}" || true
rm -rf "${SCRIPT_PATH}/01.actual" || true
rm -rf "${SCRIPT_PATH}/01.expected" || true
}


###
### 01. Clean and create test dirs
###
cleanup
mkdir -p "${DIR_PATH}/dir 1"
mkdir -p "${DIR_PATH}/dir 2"
mkdir -p "${DIR_PATH}/dir 3"
mkdir -p "${DIR_PATH}/dir 4"
mkdir -p "${DIR_PATH}/dir 4/subdir"
touch "${DIR_PATH}/file 1"
touch "${DIR_PATH}/file 2"


###
### 02. Setup expected
###
{
echo "add: ./dir 1";
echo "add: ./dir 2";
echo "add: ./dir 3";
echo "add: ./dir 4";
} > "${SCRIPT_PATH}/01.expected"


###
### 03. Run watcherd
###
cd "${DIR_PATH}"
"${BIN_PATH}/watcherd" -p "." -a "echo 'add: %p'" -d "echo 'del: %p'" > "${SCRIPT_PATH}/01.actual" &
watch_pid="${!}"
echo "Started watcherd with pid: ${watch_pid}"
echo "Waiting 5 sec."
sleep 5



###
### 04 .Compare results and shutdown
###
echo "Diff results"
if ! diff "${SCRIPT_PATH}/01.actual" "${SCRIPT_PATH}/01.expected"; then
echo "[ERR] Results did not equal"
echo "Killing watcherd"
kill "${watch_pid}" || true
cleanup
exit 1
fi

echo "[OK] Results equal."
echo "Killing watcherd"
kill "${watch_pid}" || true
cleanup
exit 0
23 changes: 17 additions & 6 deletions watcherd
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ IFS=$'\n'

# Versioning
MY_NAME="watcherd"
MY_DATE="2017-09-30"
MY_DATE="2020-12-11"
MY_URL="https://github.com/devilbox/watcherd"
MY_AUTHOR="cytopia <cytopia@everythingcli.org>"
MY_GPGKEY="0xA02C56F0"
MY_VERSION="0.1"
MY_VERSION="1.0.2"
MY_LICENSE="MIT"

# Default settings
Expand Down Expand Up @@ -100,10 +100,21 @@ function print_version() {
function get_subdirs() {
local path="${1}"
# shellcheck disable=SC2016
(find "${path}" || true) \
| grep -Ev "^${path}\$" \
| grep -Ev "^${path}/.+/" \
| xargs -n1 sh -c 'if [ -d "${1}" ]; then echo "${1}"; fi' -- \
#(find "${path}" -type d -print0 || true) \
# | xargs -0 -n1 sh -c 'if [ -d "${1}" ]; then echo "${1}"; fi' -- \
# | grep -Ev "^${path}\$" \
# | grep -Ev "^${path}/.+/" \
# | sort
path="${path%/}/"
(ls -1 -a "${path}" || true) \
| tr '\r\n' '\000' \
| tr '\n' '\000' \
| tr '\r' '\000' \
| xargs \
-0 \
-P"$(getconf _NPROCESSORS_ONLN)" \
-n1 \
sh -c "if [ -d \"${path}\${1}\" ] && [ \"\${1}\" != \".\" ] && [ \"\${1}\" != \"..\" ]; then echo \"${path}\${1}\"; fi" -- \
| sort
}

Expand Down