Skip to content

Commit afbfc31

Browse files
authored
Merge pull request #11 from devilbox/release-1.0.2
Release 1.0.2
2 parents 923ef69 + 39004a1 commit afbfc31

File tree

7 files changed

+193
-7
lines changed

7 files changed

+193
-7
lines changed

.github/workflows/test-linux.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: test-linux
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
tags:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: False
15+
16+
name: "[test] [linux]"
17+
steps:
18+
# ------------------------------------------------------------
19+
# Setup
20+
# ------------------------------------------------------------
21+
- name: Checkout repository
22+
uses: actions/checkout@v2
23+
24+
# ------------------------------------------------------------
25+
# Tests: Behaviour
26+
# ------------------------------------------------------------
27+
- name: test
28+
shell: bash
29+
run: |
30+
make test

.github/workflows/test-macos.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: test-macos
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
tags:
9+
10+
jobs:
11+
test:
12+
runs-on: macos-latest
13+
strategy:
14+
fail-fast: False
15+
16+
name: "[test] [macos]"
17+
steps:
18+
# ------------------------------------------------------------
19+
# Setup
20+
# ------------------------------------------------------------
21+
- name: Checkout repository
22+
uses: actions/checkout@v2
23+
24+
# ------------------------------------------------------------
25+
# Tests: Behaviour
26+
# ------------------------------------------------------------
27+
- name: test
28+
shell: bash
29+
run: |
30+
make test

.github/workflows/test-windows.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: test-windows
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
tags:
9+
10+
jobs:
11+
test:
12+
runs-on: windows-latest
13+
strategy:
14+
fail-fast: False
15+
16+
name: "[test] [windows]"
17+
steps:
18+
# ------------------------------------------------------------
19+
# Setup
20+
# ------------------------------------------------------------
21+
- name: Checkout repository
22+
uses: actions/checkout@v2
23+
24+
# ------------------------------------------------------------
25+
# Tests: Behaviour
26+
# ------------------------------------------------------------
27+
- name: test
28+
shell: bash
29+
run: |
30+
make test

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ endif
55
# -------------------------------------------------------------------------------------------------
66
# Default configuration
77
# -------------------------------------------------------------------------------------------------
8-
.PHONY: help lint
8+
.PHONY: help lint test
99

1010
FL_VERSION = 0.3
1111
FL_IGNORES = .git/,.github/
@@ -16,6 +16,7 @@ FL_IGNORES = .git/,.github/
1616
# -------------------------------------------------------------------------------------------------
1717
help:
1818
@echo "lint Lint repository"
19+
@echo "test Run integration tests"
1920

2021

2122
# -------------------------------------------------------------------------------------------------
@@ -43,3 +44,10 @@ _lint-shell:
4344
@echo "# Shellcheck"
4445
@echo "# -------------------------------------------------------------------- #"
4546
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/mnt -w /mnt koalaman/shellcheck:stable watcherd
47+
48+
49+
# -------------------------------------------------------------------------------------------------
50+
# Test Targets
51+
# -------------------------------------------------------------------------------------------------
52+
test:
53+
./test/01.sh

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# watcherd
22

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

59
**[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.
610
Once all events have happened during one round (`-i`), a trigger command can be executed (`-t`).

test/01.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
SCRIPT_PATH="$( cd "$(dirname "$0")" && pwd -P )"
8+
9+
BIN_PATH="${SCRIPT_PATH}/.."
10+
DIR_PATH="${SCRIPT_PATH}/dirs"
11+
12+
13+
14+
cleanup() {
15+
rm -rf "${DIR_PATH}" || true
16+
rm -rf "${SCRIPT_PATH}/01.actual" || true
17+
rm -rf "${SCRIPT_PATH}/01.expected" || true
18+
}
19+
20+
21+
###
22+
### 01. Clean and create test dirs
23+
###
24+
cleanup
25+
mkdir -p "${DIR_PATH}/dir 1"
26+
mkdir -p "${DIR_PATH}/dir 2"
27+
mkdir -p "${DIR_PATH}/dir 3"
28+
mkdir -p "${DIR_PATH}/dir 4"
29+
mkdir -p "${DIR_PATH}/dir 4/subdir"
30+
touch "${DIR_PATH}/file 1"
31+
touch "${DIR_PATH}/file 2"
32+
33+
34+
###
35+
### 02. Setup expected
36+
###
37+
{
38+
echo "add: ./dir 1";
39+
echo "add: ./dir 2";
40+
echo "add: ./dir 3";
41+
echo "add: ./dir 4";
42+
} > "${SCRIPT_PATH}/01.expected"
43+
44+
45+
###
46+
### 03. Run watcherd
47+
###
48+
cd "${DIR_PATH}"
49+
"${BIN_PATH}/watcherd" -p "." -a "echo 'add: %p'" -d "echo 'del: %p'" > "${SCRIPT_PATH}/01.actual" &
50+
watch_pid="${!}"
51+
echo "Started watcherd with pid: ${watch_pid}"
52+
echo "Waiting 5 sec."
53+
sleep 5
54+
55+
56+
57+
###
58+
### 04 .Compare results and shutdown
59+
###
60+
echo "Diff results"
61+
if ! diff "${SCRIPT_PATH}/01.actual" "${SCRIPT_PATH}/01.expected"; then
62+
echo "[ERR] Results did not equal"
63+
echo "Killing watcherd"
64+
kill "${watch_pid}" || true
65+
cleanup
66+
exit 1
67+
fi
68+
69+
echo "[OK] Results equal."
70+
echo "Killing watcherd"
71+
kill "${watch_pid}" || true
72+
cleanup
73+
exit 0

watcherd

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ IFS=$'\n'
2525

2626
# Versioning
2727
MY_NAME="watcherd"
28-
MY_DATE="2017-09-30"
28+
MY_DATE="2020-12-11"
2929
MY_URL="https://github.com/devilbox/watcherd"
3030
MY_AUTHOR="cytopia <[email protected]>"
3131
MY_GPGKEY="0xA02C56F0"
32-
MY_VERSION="0.1"
32+
MY_VERSION="1.0.2"
3333
MY_LICENSE="MIT"
3434

3535
# Default settings
@@ -100,10 +100,21 @@ function print_version() {
100100
function get_subdirs() {
101101
local path="${1}"
102102
# shellcheck disable=SC2016
103-
(find "${path}" || true) \
104-
| grep -Ev "^${path}\$" \
105-
| grep -Ev "^${path}/.+/" \
106-
| xargs -n1 sh -c 'if [ -d "${1}" ]; then echo "${1}"; fi' -- \
103+
#(find "${path}" -type d -print0 || true) \
104+
# | xargs -0 -n1 sh -c 'if [ -d "${1}" ]; then echo "${1}"; fi' -- \
105+
# | grep -Ev "^${path}\$" \
106+
# | grep -Ev "^${path}/.+/" \
107+
# | sort
108+
path="${path%/}/"
109+
(ls -1 -a "${path}" || true) \
110+
| tr '\r\n' '\000' \
111+
| tr '\n' '\000' \
112+
| tr '\r' '\000' \
113+
| xargs \
114+
-0 \
115+
-P"$(getconf _NPROCESSORS_ONLN)" \
116+
-n1 \
117+
sh -c "if [ -d \"${path}\${1}\" ] && [ \"\${1}\" != \".\" ] && [ \"\${1}\" != \"..\" ]; then echo \"${path}\${1}\"; fi" -- \
107118
| sort
108119
}
109120

0 commit comments

Comments
 (0)