Skip to content

Commit 7076492

Browse files
committed
[PLUTO-1411] Add script
1 parent ce13b0a commit 7076492

File tree

2 files changed

+47
-30
lines changed

2 files changed

+47
-30
lines changed

.github/workflows/it-test.yml

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,14 @@ jobs:
2626
2727
- name: Run plugin tests
2828
run: |
29-
run_test() {
30-
local tool=$1
31-
local jq_filter=$2
32-
echo "Running $tool tests..."
33-
# Store the path to the CLI
34-
CLI_PATH="$(pwd)/cli-v2"
35-
# Change to test directory
36-
cd plugins/tools/$tool/test/src
37-
# Install the plugin
38-
"$CLI_PATH" install
39-
# Run analysis
40-
"$CLI_PATH" analyze --tool $tool --format sarif --output actual.sarif
41-
# Convert absolute paths to relative paths in the output
42-
sed -i 's|file:///home/runner/work/codacy-cli-v2/codacy-cli-v2/|file:///|g' actual.sarif
43-
# Compare with expected output
44-
jq --sort-keys "$jq_filter" expected.sarif > expected.sorted.json
45-
jq --sort-keys "$jq_filter" actual.sarif > actual.sorted.json
46-
diff expected.sorted.json actual.sorted.json
47-
# Go back to root directory
48-
cd ../../../../..
49-
}
50-
51-
# Run Pylint tests with simple sorting
52-
run_test "pylint" "."
53-
54-
# Run Semgrep tests with rules sorting
55-
run_test "semgrep" ".runs[0].tool.driver.rules |= if . then sort_by(.id) else . end"
56-
57-
# Run PMD tests with rules sorting
58-
run_test "pmd" ".runs[0].tool.driver.rules |= if . then sort_by(.id) else . end"
29+
# Make the script executable
30+
chmod +x run-tool-tests.sh
31+
32+
# Run tests for each tool directory
33+
for tool_dir in plugins/tools/*/; do
34+
tool_name=$(basename "$tool_dir")
35+
if [ -d "$tool_dir/test/src" ]; then
36+
echo "Running tests for $tool_name..."
37+
./run-tool-tests.sh "$tool_name"
38+
fi
39+
done

run-tool-tests.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Check if tool name is provided
4+
if [ -z "$1" ]; then
5+
echo "Usage: $0 <tool_name>"
6+
exit 1
7+
fi
8+
9+
TOOL_NAME=$1
10+
TOOL_DIR="plugins/tools/$TOOL_NAME/test/src"
11+
12+
# Check if tool directory exists
13+
if [ ! -d "$TOOL_DIR" ]; then
14+
echo "Error: Tool directory $TOOL_DIR does not exist"
15+
exit 1
16+
fi
17+
18+
# Change to the tool's test directory
19+
cd "$TOOL_DIR"
20+
21+
# Install the tool
22+
codacy-cli install
23+
24+
# Run analysis
25+
codacy-cli analyze --tool $TOOL_NAME --format sarif --output actual.sarif
26+
27+
# Convert absolute paths to relative paths in the output
28+
sed -i 's|file:///home/runner/work/codacy-cli-v2/codacy-cli-v2/|file:///|g' actual.sarif
29+
30+
# Compare with expected output
31+
jq --sort-keys "." expected.sarif > expected.sorted.json
32+
jq --sort-keys "." actual.sarif > actual.sorted.json
33+
diff expected.sorted.json actual.sorted.json
34+
35+
# Return to original directory
36+
cd ../../../../..

0 commit comments

Comments
 (0)