diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e772c7f..e966104 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,4 +9,4 @@ jobs: - name: Run checkpatch review uses: webispy/checkpatch-action@master env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index d8475af..d886908 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,51 @@ From [zephyr](https://github.com/zephyrproject-rtos/zephyr) project: ### Disable warning for "No structs that should be const ..." - https://github.com/nugulinux/docker-devenv/blob/master/patches/0002-ignore_const_struct_warning.patch + +## Action setup guide + +### Pull Request from owned repository + +.github/workflows/main.yml + +```yml +name: checkpatch review +on: [pull_request] +jobs: + my_review: + name: checkpatch review + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Run checkpatch review + uses: webispy/checkpatch-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + +The checkpatch action will posting comments for error/warning result to the PR conversation. + +### Pull Request from forked repository + +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. + +.github/workflows/main.yml + +```yml +name: checkpatch review +on: [pull_request] +jobs: + my_review: + name: checkpatch review + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Run checkpatch review + uses: webispy/checkpatch-action@master +``` + +You can find the error/waring result from Github action console log. + +# License + +Since the `checkpatch.pl` file is a script in the Linux kernel source tree, you must follow the [GPL-2.0](https://github.com/torvalds/linux/blob/master/COPYING) license, which is your kernel license. diff --git a/entrypoint.sh b/entrypoint.sh index 3e8699e..24192cb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,22 +16,40 @@ pwd RESULT=0 -# Get PR number -PR=${GITHUB_REF#"refs/pull/"} -PRNUM=${PR%"/merge"} +# Check the input parameter +echo +if [[ -z "$GITHUB_TOKEN" ]]; then + echo -e "\e[0;34mToken is empty. Review PR without comments.\e[0m" +else + echo -e "\e[0;34mReview PR with comments.\e[0m" +fi # Get commit list using Github API +echo +echo -e "\e[0;34mGet the list of commits included in the PR($GITHUB_REF).\e[0m" +PR=${GITHUB_REF#"refs/pull/"} +PRNUM=${PR%"/merge"} URL=https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PRNUM}/commits -list=$(curl $URL -X GET -s -H "Authorization: token ${GITHUB_TOKEN}" | jq '.[].sha' -r) -echo $list +echo " - API endpoint: $URL" + +list=$(curl $URL -X GET -s | jq '.[].sha' -r) +len=$(echo "$list" | wc -l) +echo " - Commits $len: $list" # Run review.sh on each commit in the PR +echo +echo -e "\e[0;34mStart review for each commits.\e[0m" + +i=1 for sha1 in $list; do - echo "Check - Commit id $sha1" + echo "-------------------------------------------------------------" + echo -e "[$i/$len] Check commit - \e[1;34m$sha1\e[0m" + echo "-------------------------------------------------------------" /review.sh ${sha1} || RESULT=1; - echo "Result: ${RESULT}" + echo + ((i++)) done -echo "Done" +echo -e "\e[1;34mDone\e[0m" exit $RESULT \ No newline at end of file diff --git a/review.sh b/review.sh index b440f67..d215dc1 100755 --- a/review.sh +++ b/review.sh @@ -26,7 +26,9 @@ MESSAGE= function post_code_message() { echo "POST to ${CODE_URL} with ${MESSAGE}" - curl ${CODE_URL} -H "Authorization: token ${GITHUB_TOKEN}" \ + curl ${CODE_URL} -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ -X POST --data "$(cat <> Success\e[0m" +else + echo -e "\e[1;31m>> Failure\e[0m" +fi + exit $RESULT \ No newline at end of file