Skip to content

Commit f6a4cec

Browse files
committed
add error message for action
The error message will appear in the annotation of the github action. Signed-off-by: Inho Oh <inho.oh@sk.com>
1 parent bea6477 commit f6a4cec

File tree

3 files changed

+7
-82
lines changed

3 files changed

+7
-82
lines changed

README.md

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,7 @@ The `checkpatch.pl` is a perl script to verify that your code conforms to the Li
66

77
## Action setup guide
88

9-
### Pull Request from owned repository
10-
11-
.github/workflows/main.yml
12-
13-
```yml
14-
name: checkpatch review
15-
on: [pull_request]
16-
jobs:
17-
my_review:
18-
name: checkpatch review
19-
runs-on: ubuntu-latest
20-
steps:
21-
- uses: actions/checkout@v1
22-
- name: Run checkpatch review
23-
uses: webispy/checkpatch-action@master
24-
env:
25-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26-
```
27-
28-
The checkpatch action will posting comments for error/warning result to the PR conversation.
29-
30-
![check](https://raw.githubusercontent.com/wiki/webispy/checkpatch-action/img/action_conversation_comment.png)
31-
32-
The capture image above shows the comments on the lines of code and the comments on the commit message.
33-
34-
### Pull Request from forked repository
35-
36-
The Github action has a limitation that doesn't have write permission for PR from forked repository. So the action cannot write a comment to the PR.
9+
### Pull Request
3710

3811
.github/workflows/main.yml
3912

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'checkpatch.pl PR review'
2-
description: 'Codew review for PR using checkpatch.pl'
2+
description: 'Code review for PR using checkpatch.pl'
33
branding:
44
icon: 'check-square'
55
color: 'purple'

review.sh

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,14 @@
33
# To debug the current script, please uncomment the following 'set -x' line
44
#set -x
55

6-
# Argument
7-
COMMIT=$1
8-
9-
# Get PR number
10-
PR=${GITHUB_REF#"refs/pull/"}
11-
PRNUM=${PR%"/merge"}
12-
136
# Generate email style commit message
147
PATCHMAIL=$(git show --format=email $1 | checkpatch.pl --no-tree -)
158

16-
# Github REST API endpoints
17-
BODY_URL=https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PRNUM}/comments
18-
CODE_URL=https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PRNUM}/comments
19-
209
# Internal state variables
2110
RESULT=0
2211
FOUND=0
2312
MESSAGE=
2413

25-
# Write message to specific file and line
26-
function post_code_message()
27-
{
28-
echo "POST to ${CODE_URL} with ${MESSAGE}"
29-
curl ${CODE_URL} -s \
30-
-H "Authorization: token ${GITHUB_TOKEN}" \
31-
-H "Content-Type: application/json" \
32-
-X POST --data "$(cat <<EOF
33-
{
34-
"commit_id": "$COMMIT",
35-
"path": "${FILE}",
36-
"position": ${LINE},
37-
"body": "${MESSAGE}"
38-
}
39-
EOF
40-
)"
41-
}
42-
43-
# Write message to pull-request comment
44-
function post_comment_message()
45-
{
46-
echo "POST to ${BODY_URL} with ${MESSAGE}"
47-
curl ${BODY_URL} -s \
48-
-H "Authorization: token ${GITHUB_TOKEN}" \
49-
-H "Content-Type: application/json" \
50-
-X POST --data "$(cat <<EOF
51-
{
52-
"body": ":warning: ${COMMIT} - ${MESSAGE}"
53-
}
54-
EOF
55-
)"
56-
}
57-
5814
#
5915
# checkpatch.pl result format
6016
# ---------------------------
@@ -107,17 +63,13 @@ do
10763
else
10864
# An empty line means the paragraph is over.
10965
if [[ -z $row ]]; then
110-
if [[ ! -z "$GITHUB_TOKEN" ]]; then
111-
echo "Post comment to Github"
112-
if [[ -z $FILE ]]; then
113-
post_comment_message
114-
else
115-
post_code_message
116-
fi
66+
if [[ -z $FILE ]]; then
67+
echo "::error ::${MESSAGE}"
11768
else
118-
# Output empty line
119-
echo
69+
echo "::error file=${FILE},line=${LINE}::${MESSAGE}"
12070
fi
71+
# Output empty line
72+
echo
12173

12274
# Code review found a problem.
12375
RESULT=1

0 commit comments

Comments
 (0)