Skip to content

Commit 74760d6

Browse files
committed
Add GitHub Actions CI workflow and Dependabot configuration
- Add ci.yml workflow with shellcheck, shfmt, and BATS testing - Configure automated checks on push and pull request events - Add Dependabot for GitHub Actions dependency updates - Pin action versions to specific commits for reproducibility - Fix shellcheck SC2015 in common.sh (replace && || with if)
1 parent aaa1ed9 commit 74760d6

5 files changed

Lines changed: 83 additions & 4 deletions

File tree

.github/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
commit-message:
8+
prefix: "ci"
9+
include: "scope"

.github/workflows/ci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["*"]
6+
pull_request:
7+
branches: ["*"]
8+
9+
jobs:
10+
shell-quality:
11+
name: Shell Code Quality
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
18+
- name: Install shellcheck
19+
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # v2.0.0
20+
with:
21+
ignore_paths: >-
22+
**/.git/**
23+
**/.github/**
24+
25+
- name: Install shfmt and bats
26+
run: |
27+
sudo apt-get update
28+
sudo apt-get install -y shfmt bats
29+
30+
- name: Find all shell scripts
31+
id: find-scripts
32+
run: |
33+
scripts=$(find opt/monitoring -name "*.sh" -type f | tr '\n' ' ')
34+
echo "scripts=${scripts}" >> $GITHUB_OUTPUT
35+
echo "Found scripts: ${scripts}"
36+
37+
- name: Check formatting with shfmt
38+
run: |
39+
scripts="${{ steps.find-scripts.outputs.scripts }}"
40+
if [ -n "${scripts}" ]; then
41+
shfmt -d -s -i 2 ${scripts}
42+
else
43+
echo "No shell scripts found to check"
44+
fi
45+
46+
- name: Run shellcheck
47+
run: |
48+
scripts="${{ steps.find-scripts.outputs.scripts }}"
49+
if [ -n "${scripts}" ]; then
50+
shellcheck --enable=all -x ${scripts}
51+
else
52+
echo "No shell scripts found to lint"
53+
fi
54+
55+
- name: Run BATS tests
56+
run: |
57+
if [ -d "tests" ] && [ "$(find tests -name '*.bats' -type f | wc -l)" -gt 0 ]; then
58+
bats tests/
59+
else
60+
echo "No BATS tests found to run"
61+
fi

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# bash-sys-monitor
22

3+
[![ShellCheck Lint](https://github.com/underhax/bash-sys-monitor/actions/workflows/ci.yml/badge.svg)](https://github.com/underhax/bash-sys-monitor/actions/workflows/ci.yml)
4+
[![GitHub last commit](https://img.shields.io/github/last-commit/underhax/bash-sys-monitor)](https://github.com/underhax/bash-sys-monitor/commits/main)
5+
[![GitHub issues](https://img.shields.io/github/issues/underhax/bash-sys-monitor)](https://github.com/underhax/bash-sys-monitor/issues)
6+
[![GitHub repo size](https://img.shields.io/github/repo-size/underhax/bash-sys-monitor)](https://github.com/underhax/bash-sys-monitor)
7+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8+
39
**bash-sys-monitor** is a lightweight, security-hardened, and modular suite of shell scripts designed for high-availability monitoring of Ubuntu Server 24+ (and compatible Linux distributions). It provides real-time system performance monitoring and security auditing with multi-channel alerting.
410

511
## Overview

opt/monitoring/lib/common.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ info() {
1010
}
1111

1212
debug() {
13-
[[ ${VERBOSE:-0} -eq 1 ]] && printf "DEBUG: %s\n" "$*" >&2 || true
13+
if [[ ${VERBOSE:-0} -eq 1 ]]; then
14+
printf "DEBUG: %s\n" "$*" >&2
15+
fi
1416
}
1517

1618
check_deps() {

tests/login.bats

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,16 @@ setup() {
378378
esac
379379
}
380380

381-
process_logins
382-
383381
stat() {
384382
if [[ "$1" == "-c" && "$2" == "%a" ]]; then
385-
command stat -f "%Lp" "$3"
383+
printf "600\n"
386384
else
387385
command stat "$@"
388386
fi
389387
}
388+
389+
process_logins
390+
390391
local perms
391392
perms=$(stat -c "%a" "${STATE_FILE}")
392393
[ "$perms" = "600" ]

0 commit comments

Comments
 (0)