This commit is contained in:
parent
3aa7f9e722
commit
f4cb6c77f6
4 changed files with 53 additions and 1 deletions
37
.githooks/pre-commit
Executable file
37
.githooks/pre-commit
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
badge_file="badges/tests.json"
|
||||
|
||||
write_badge() {
|
||||
local status="$1" color="$2"
|
||||
mkdir -p badges
|
||||
cat > "$badge_file" <<EOF
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"label": "tests",
|
||||
"message": "$status",
|
||||
"color": "$color"
|
||||
}
|
||||
EOF
|
||||
git add "$badge_file"
|
||||
}
|
||||
|
||||
echo "Running ShellCheck..."
|
||||
if ! shellcheck systab; then
|
||||
write_badge "failing" "red"
|
||||
echo "ShellCheck failed — commit blocked."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Running tests..."
|
||||
if output=$(./test.sh 2>&1); then
|
||||
echo "$output"
|
||||
count=$(sed -n 's/.*\([0-9]\+\) tests: \([0-9]\+\) passed.*/\2 passed/p' <<< "$output")
|
||||
write_badge "${count:-passing}" "brightgreen"
|
||||
else
|
||||
echo "$output"
|
||||
write_badge "failing" "red"
|
||||
echo "Tests failed — commit blocked."
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -37,7 +37,9 @@ Key functions: `parse_time` (time spec → OnCalendar), `_write_unit_files` (sha
|
|||
|
||||
Runs 58 tests against real systemd user timers covering job creation, job names, status, logs, disable/enable, notifications, time format parsing, error cases, and cleanup. All test jobs are cleaned up automatically via trap.
|
||||
|
||||
Tests require a real systemd user session (`systemctl --user`) and cannot run in containers. CI runs ShellCheck only; tests must be run locally before submitting changes.
|
||||
Tests require a real systemd user session (`systemctl --user`) and cannot run in containers. CI runs ShellCheck only; tests are enforced locally via a pre-commit hook that also updates `badges/tests.json`.
|
||||
|
||||
After cloning, enable the hooks: `git config core.hooksPath .githooks`
|
||||
|
||||
## Notes
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# systab
|
||||
|
||||
[](https://code.opennomad.com/opennomad/systab/actions?workflow=ci.yml)
|
||||
[](badges/tests.json)
|
||||
[](LICENSE)
|
||||
|
||||
A cron/at-like interface for systemd user timers. Create, manage, and monitor scheduled jobs without writing unit files by hand.
|
||||
|
|
@ -186,6 +187,12 @@ The primary repository is hosted on [Forgejo](https://code.opennomad.com/opennom
|
|||
|
||||
Contributions (issues and pull requests) are welcome on GitHub.
|
||||
|
||||
After cloning, enable the pre-commit hook (runs ShellCheck + tests):
|
||||
|
||||
```bash
|
||||
git config core.hooksPath .githooks
|
||||
```
|
||||
|
||||
## FAQ
|
||||
|
||||
**What's the difference between `-c` and `-f`?**
|
||||
|
|
|
|||
6
badges/tests.json
Normal file
6
badges/tests.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"label": "tests",
|
||||
"message": "58 passed",
|
||||
"color": "brightgreen"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue