88
99jobs :
1010 test :
11- runs-on : ubuntu-latest
11+ runs-on : ${{ matrix.os }}
12+ strategy :
13+ matrix :
14+ os : [ubuntu-latest, macos-latest] # [windows-latest] removed for now
15+ fail-fast : false
1216 steps :
1317 - name : Checkout code
1418 uses : actions/checkout@v4
@@ -19,40 +23,67 @@ jobs:
1923 go-version : ' 1.21'
2024 cache : true
2125
22- - name : Build CLI
26+ - name : Download CLI binaries from go workflow
27+ uses : dawidd6/action-download-artifact@v2
28+ with :
29+ workflow : go.yml
30+ name : cli-binaries
31+ path : .
32+
33+ - name : Select correct binary
34+ shell : bash
35+ run : |
36+ if [ "${{ matrix.os }}" = "windows-latest" ]; then
37+ # Keep the .exe extension for Windows
38+ echo "Using Windows binary with .exe extension"
39+ elif [ "${{ matrix.os }}" = "macos-latest" ]; then
40+ mv cli-v2-macos cli-v2
41+ else
42+ mv cli-v2-linux cli-v2
43+ fi
44+
45+ - name : Make binary executable
46+ if : matrix.os != 'windows-latest'
47+ run : chmod +x cli-v2
48+
49+
50+ - name : Run tool tests
51+ if : matrix.os != 'windows-latest'
52+ id : run_tests
53+ continue-on-error : true
54+ shell : bash
2355 run : |
24- go build -o cli-v2 ./cli-v2.go
25- chmod +x cli-v2
56+ # Make the script executable
57+ chmod +x run-tool-tests.sh
58+
59+ # Initialize failed tools file
60+ rm -f /tmp/failed_tools.txt
61+ touch /tmp/failed_tools.txt
62+
63+ # Run tests for each tool directory
64+ for tool_dir in plugins/tools/*/; do
65+ tool_name=$(basename "$tool_dir")
66+ if [ -d "$tool_dir/test/src" ]; then
67+ echo "Running tests for $tool_name..."
68+ ./run-tool-tests.sh "$tool_name" || {
69+ echo "❌ Test failed for $tool_name"
70+ echo "$tool_name" >> /tmp/failed_tools.txt
71+ }
72+ fi
73+ done
74+
75+ # Check if any tools failed
76+ if [ -s /tmp/failed_tools.txt ] && [ "$(wc -l < /tmp/failed_tools.txt)" -gt 0 ]; then
77+ echo -e "\n❌ The following tools failed their tests:"
78+ cat /tmp/failed_tools.txt
79+ echo "::error::Some tool tests failed. Please check the logs above for details."
80+ exit 1
81+ else
82+ echo "✅ All tool tests passed successfully!"
83+ fi
2684
27- - name : Run plugin tests
85+ - name : Check test results
86+ if : steps.run_tests.outcome == 'failure'
2887 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 Enigma tests with simple sorting
55- run_test "codacy-enigma-cli" "."
56-
57- # Run Semgrep tests with rules sorting
58- run_test "semgrep" ".runs[0].tool.driver.rules |= if . then sort_by(.id) else . end"
88+ echo "Job failed because some tool tests failed. Please check the logs above for details."
89+ exit 1
0 commit comments