Skip to content

Commit c91cf27

Browse files
sherry-yuanpcolberg
authored andcommitted
Display fixed klocwork issue in pull request
Currently the klocwork pull request flow does not show the klocwork issues that are fixed, making it hard for reviewer to know which issues are fixed when the pull request is aiming to fix existin klocwork issues. The current approach is to diff between the issue id between parent and child build, the ids that exist only in child build but not parent are new issues, the ones that appear only in parent but not child is the fixed issues. The issue ids are concatenated and fed into kwcheck list to list these issues in detail.
1 parent 721e055 commit c91cf27

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

.github/workflows/klocwork-pull-request.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ jobs:
4646
run: sudo chown -R klocwork:klocwork .
4747

4848
- name: create local Klocwork project
49-
run: kwcheck create --project-dir /home/klocwork/.kwlp --settings-dir /home/klocwork/.kwps
49+
run: |
50+
mkdir -p /home/klocwork/parent
51+
kwcheck create --project-dir /home/klocwork/parent/.kwlp --settings-dir /home/klocwork/parent/.kwps
5052
5153
- name: checkout base ref
5254
uses: actions/checkout@v2
@@ -62,12 +64,16 @@ jobs:
6264
run: kwinject --output kwinject.out ninja -C build -v -k0
6365

6466
- name: fully analyze build of base ref
65-
run: kwcheck run --build-spec kwinject.out -F scriptable --report issues.txt --project-dir /home/klocwork/.kwlp --settings-dir /home/klocwork/.kwps
67+
run: kwcheck run --build-spec kwinject.out -F scriptable --report /home/klocwork/parent_issues.txt --project-dir /home/klocwork/parent/.kwlp --settings-dir /home/klocwork/parent/.kwps
6668

67-
- name: ignore issues of base ref
69+
# Use non numeric sort because `comm` expects default sorting order
70+
- name: get parent issue ids
71+
run: awk -F ';' '{print $1}' /home/klocwork/parent_issues.txt | sort > /home/klocwork/parent_issues_ids.txt
72+
73+
- name: copy parent klocwork project
6874
run: |
69-
count=$(wc -l < issues.txt)
70-
test "$count" = "0" || kwcheck set-status 1-"$count" --status ignore --project-dir /home/klocwork/.kwlp
75+
mkdir -p /home/klocwork/child
76+
cp -r /home/klocwork/parent/.kwlp /home/klocwork/parent/.kwps /home/klocwork/child
7177
7278
- name: checkout head ref
7379
uses: actions/checkout@v2
@@ -81,13 +87,31 @@ jobs:
8187
run: kwinject --output kwinject.out ninja -C build -v -k0
8288

8389
- name: incrementally analyze build of head ref
84-
run: kwcheck run --build-spec kwinject.out -F scriptable --report issues.txt --project-dir /home/klocwork/.kwlp --settings-dir /home/klocwork/.kwps
90+
run: kwcheck run --build-spec kwinject.out -F scriptable --report /home/klocwork/child_issues.txt --project-dir /home/klocwork/child/.kwlp --settings-dir /home/klocwork/child/.kwps
91+
92+
# Klocwork incremental scans will suppress the issues that were fixed in head ref (while preserving their issue id)
93+
# Any new issue will have id will be larger than the max id in scan of base ref.
94+
# For example, if base ref scan produced issue ids 1-5, and in head ref issue 4 was resolved but also introduced a new issue
95+
# then the resulting issue ids for head ref scan will be 1,2,3,5,6.
96+
- name: get child issue ids
97+
run: awk -F ';' '{print $1}' /home/klocwork/child_issues.txt | sort > /home/klocwork/child_issues_ids.txt
98+
99+
- name: list issues fixed in head ref
100+
run: |
101+
FIXED_ISSUE_ID=$(comm -13 /home/klocwork/child_issues_ids.txt /home/klocwork/parent_issues_ids.txt | paste -sd,)
102+
if [ -n "$FIXED_ISSUE_ID" ]
103+
then
104+
kwcheck list --id "$FIXED_ISSUE_ID" -F detailed --project-dir /home/klocwork/parent/.kwlp --settings-dir /home/klocwork/parent/.kwps
105+
fi
85106
86107
- name: ensure no new issues have been found in head ref
87108
run: |
88-
kwcheck list -F detailed --project-dir /home/klocwork/.kwlp --settings-dir /home/klocwork/.kwps
89-
size=$(stat --printf=%s issues.txt)
90-
test "$size" = "0"
109+
NEW_ISSUE_ID=$(comm -13 /home/klocwork/parent_issues_ids.txt /home/klocwork/child_issues_ids.txt | paste -sd,)
110+
if [ -n "$NEW_ISSUE_ID" ]
111+
then
112+
kwcheck list --id "$NEW_ISSUE_ID" -F detailed --project-dir /home/klocwork/child/.kwlp --settings-dir /home/klocwork/child/.kwps
113+
fi
114+
test -z "$NEW_ISSUE_ID"
91115
92116
- name: revert ownership of workspace to root
93117
run: sudo chown -R root:root .

0 commit comments

Comments
 (0)