@@ -56,107 +56,12 @@ jobs:
5656 sudo dpkg -i osquery_5.20.0-1.linux_amd64.deb
5757 osqueryi --version
5858
59- - name : Build workspace (including extensions)
59+ - name : Build workspace
6060 run : cargo build --workspace
6161
62- # Run osqueryd and tests in a SINGLE step to keep env vars and background process in same shell
63- - name : Run coverage with osqueryd
62+ - name : Run coverage with osquery
6463 id : coverage
65- run : |
66- set -e
67-
68- # Create directories
69- sudo mkdir -p /var/osquery /etc/osquery
70-
71- # Create .ext symlinks - osquery requires extensions to end in .ext for autoload
72- ln -sf "$PWD/target/debug/config_static" "$PWD/target/debug/config_static.ext"
73- ln -sf "$PWD/target/debug/logger-file" "$PWD/target/debug/logger-file.ext"
74- ln -sf "$PWD/target/debug/two-tables" "$PWD/target/debug/two-tables.ext"
75-
76- # Create extensions.load file pointing to our built extensions
77- echo "$PWD/target/debug/config_static.ext" | sudo tee /etc/osquery/extensions.load
78- echo "$PWD/target/debug/logger-file.ext" | sudo tee -a /etc/osquery/extensions.load
79- echo "$PWD/target/debug/two-tables.ext" | sudo tee -a /etc/osquery/extensions.load
80-
81- # Set up test environment - these MUST be exported before osqueryd starts
82- export FILE_LOGGER_PATH=/tmp/test_logger.log
83- export TEST_LOGGER_FILE=/tmp/test_logger.log
84- export TEST_CONFIG_MARKER_FILE=/tmp/test_config_marker
85- export OSQUERY_SOCKET=/var/osquery/osquery.em
86-
87- # Create log file with correct permissions
88- touch "$TEST_LOGGER_FILE"
89- chmod 666 "$TEST_LOGGER_FILE"
90-
91- # Start osqueryd in background (same shell, env vars persist)
92- sudo -E osqueryd --ephemeral \
93- --disable_extensions=false \
94- --extensions_socket=/var/osquery/osquery.em \
95- --extensions_autoload=/etc/osquery/extensions.load \
96- --config_plugin=static_config \
97- --logger_plugin=file_logger \
98- --database_path=/tmp/osquery.db \
99- --disable_watchdog \
100- --allow_unsafe \
101- --force &
102-
103- OSQUERY_PID=$!
104- echo "Started osqueryd with PID: $OSQUERY_PID"
105-
106- # Wait for socket with timeout
107- for i in $(seq 1 30); do
108- if [ -S /var/osquery/osquery.em ]; then
109- echo "osquery socket ready"
110- sudo chmod 777 /var/osquery/osquery.em
111- break
112- fi
113- if [ $i -eq 30 ]; then
114- echo "ERROR: osquery socket not ready after 30s"
115- exit 1
116- fi
117- sleep 1
118- done
119-
120- # Wait for extensions to register and verify osqueryd is still running
121- sleep 5
122- if ! kill -0 $OSQUERY_PID 2>/dev/null; then
123- echo "ERROR: osqueryd died after starting"
124- exit 1
125- fi
126-
127- # Verify extensions registered
128- echo "Checking extensions..."
129- osqueryi --socket /var/osquery/osquery.em "SELECT name FROM osquery_extensions WHERE name != 'core';"
130-
131- # Verify logger file has content
132- echo "Logger file contents:"
133- cat "$TEST_LOGGER_FILE" || echo "(empty)"
134-
135- # Run coverage
136- cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info --ignore-filename-regex "_osquery"
137-
138- # Calculate coverage
139- if [ -f lcov.info ]; then
140- LINES_HIT=$(grep -E "^LH:" lcov.info | cut -d: -f2 | paste -sd+ | bc)
141- LINES_FOUND=$(grep -E "^LF:" lcov.info | cut -d: -f2 | paste -sd+ | bc)
142- if [ "$LINES_FOUND" -gt 0 ]; then
143- COVERAGE=$(echo "scale=1; $LINES_HIT * 100 / $LINES_FOUND" | bc)
144- else
145- COVERAGE="0.0"
146- fi
147- else
148- echo "ERROR: lcov.info not found"
149- exit 1
150- fi
151-
152- echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
153- echo "Coverage: $COVERAGE%"
154-
155- # Enforce 90% threshold
156- if [ $(echo "$COVERAGE < 90" | bc) -eq 1 ]; then
157- echo "ERROR: Coverage $COVERAGE% is below 90% threshold"
158- exit 1
159- fi
64+ run : ./scripts/ci-test.sh --coverage
16065
16166 - name : Update coverage badge
16267 if : github.event_name == 'push' && github.ref == 'refs/heads/main'
0 commit comments