Skip to content

Commit 6e94c4e

Browse files
committed
add semgrep test
1 parent 3ee0c75 commit 6e94c4e

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

.github/workflows/it-test.yml

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
tool: [pylint, semgrep]
15-
fail-fast: false
16-
1712
steps:
1813
- name: Checkout code
1914
uses: actions/checkout@v4
@@ -29,24 +24,32 @@ jobs:
2924
go build -o cli-v2 ./cli-v2.go
3025
chmod +x cli-v2
3126
32-
- name: Run ${{ matrix.tool }} plugin tests
27+
- name: Run plugin tests
3328
run: |
34-
# Store the path to the CLI
35-
CLI_PATH="$(pwd)/cli-v2"
36-
# Change to test directory
37-
cd plugins/tools/${{ matrix.tool }}/test/src
38-
# Install the plugin
39-
"$CLI_PATH" install
40-
# Run analysis
41-
"$CLI_PATH" analyze --tool ${{ matrix.tool }} --format sarif --output actual.sarif
42-
# Convert absolute paths to relative paths in the output
43-
sed -i 's|file:///home/runner/work/codacy-cli-v2/codacy-cli-v2/|file:///|g' actual.sarif
44-
# Compare with expected output
45-
if [ "${{ matrix.tool }}" = "pylint" ]; then
46-
jq --sort-keys . expected.sarif > expected.sorted.json
47-
jq --sort-keys . actual.sarif > actual.sorted.json
48-
else
49-
jq --sort-keys '.runs[0].tool.driver.rules |= if . then sort_by(.id) else . end' expected.sarif > expected.sorted.json
50-
jq --sort-keys '.runs[0].tool.driver.rules |= if . then sort_by(.id) else . end' actual.sarif > actual.sorted.json
51-
fi
52-
diff expected.sorted.json actual.sorted.json
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"

0 commit comments

Comments
 (0)