aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Macku <jamacku@redhat.com>2021-09-29 14:51:21 +0200
committerGitHub <noreply@github.com>2021-09-29 14:51:21 +0200
commiteabf4010bf1eb709365f00a90d46c29dd995dddf (patch)
tree4cc0c9af7b5fb0a9aea5dc4226b1d284f7c51e34
parent90c4a1e83c342b9ea08d7c6ead728c33be0d9cc8 (diff)
downloadinitscripts-eabf4010bf1eb709365f00a90d46c29dd995dddf.tar
initscripts-eabf4010bf1eb709365f00a90d46c29dd995dddf.tar.gz
initscripts-eabf4010bf1eb709365f00a90d46c29dd995dddf.tar.bz2
initscripts-eabf4010bf1eb709365f00a90d46c29dd995dddf.tar.xz
initscripts-eabf4010bf1eb709365f00a90d46c29dd995dddf.zip
ci: Output shellcheck results using PR comments (#393)
-rwxr-xr-x.github/workflows/check-shell.sh21
-rw-r--r--.github/workflows/functions.sh15
-rw-r--r--.github/workflows/shellcheck_test.yml29
3 files changed, 53 insertions, 12 deletions
diff --git a/.github/workflows/check-shell.sh b/.github/workflows/check-shell.sh
index e250142c..76e95bb0 100755
--- a/.github/workflows/check-shell.sh
+++ b/.github/workflows/check-shell.sh
@@ -29,6 +29,9 @@ for file in "${list_of_changes[@]}"; do
check_shebang "$file" && list_of_changed_scripts+=("./${file}")
done
+# Expose list_of_changed_scripts[*] for use inside GA workflow
+echo "LIST_OF_SCRIPTS=${list_of_changed_scripts[*]}" >> "$GITHUB_ENV"
+
# Get list of exceptions
list_of_exceptions=()
file_to_array "$SCRIPT_DIR/exception-list.txt" "list_of_exceptions" 1
@@ -68,10 +71,16 @@ echo -e "::: ${WHITE}Validation Output${NOCOLOR} :::"
echo ":::::::::::::::::::::::::"
echo -e "\n"
+
# Check output for Fixes
csdiff --fixed "../dest-br-shellcheck.err" "../pr-br-shellcheck.err" > ../fixes.log
+
+# Expose number of solved issues for use inside GA workflow
+no_fixes=$(grep -Eo "[0-9]*" < <(csgrep --mode=stat ../fixes.log))
+echo "NUMBER_OF_SOLVED_ISSUES=${no_fixes:-0}" >> "$GITHUB_ENV"
+
if [ "$(cat ../fixes.log | wc -l)" -ne 0 ]; then
- echo -e "${GREEN}Fixed bugs:${NOCOLOR}"
+ echo -e "${GREEN}Fixed bugs:${NOCOLOR}"
csgrep ../fixes.log
echo "---------------------"
else
@@ -80,15 +89,21 @@ else
fi
echo -e "\n"
+
# Check output for added bugs
csdiff --fixed "../pr-br-shellcheck.err" "../dest-br-shellcheck.err" > ../bugs.log
+
+# Expose number of added issues for use inside GA workflow
+no_issues=$(grep -Eo "[0-9]*" < <(csgrep --mode=stat ../bugs.log))
+echo "NUMBER_OF_ADDED_ISSUES=${no_issues:-0}" >> "$GITHUB_ENV"
+
if [ "$(cat ../bugs.log | wc -l)" -ne 0 ]; then
- echo -e "${RED}Added bugs, NEED INSPECTION:${NOCOLOR}"
+ echo -e "${RED}Added bugs, NEED INSPECTION:${NOCOLOR}"
csgrep ../bugs.log
echo "---------------------"
exitstatus=1
else
- echo -e "${GREEN}No bugs added Yay!${NOCOLOR}"
+ echo -e "${GREEN}No bugs added Yay!${NOCOLOR}"
echo "---------------------"
exitstatus=0
fi
diff --git a/.github/workflows/functions.sh b/.github/workflows/functions.sh
index cbe00874..d6128486 100644
--- a/.github/workflows/functions.sh
+++ b/.github/workflows/functions.sh
@@ -1,3 +1,4 @@
+# shellcheck shell=bash
# Function to check whether input param is on list of shell scripts
# $1 - <string> absolute path to file
# $@ - <array of strings> list of strings to compare with
@@ -83,10 +84,10 @@ clean_array () {
}
# Color aliases use echo -e to use them
-NOCOLOR='\033[0m'
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-ORANGE='\033[0;33m'
-BLUE='\033[0;34m'
-YELLOW='\033[1;33m'
-WHITE='\033[1;37m'
+export NOCOLOR='\033[0m'
+export RED='\033[0;31m'
+export GREEN='\033[0;32m'
+export ORANGE='\033[0;33m'
+export BLUE='\033[0;34m'
+export YELLOW='\033[1;33m'
+export WHITE='\033[1;37m'
diff --git a/.github/workflows/shellcheck_test.yml b/.github/workflows/shellcheck_test.yml
index 6ad63a58..47dbaea1 100644
--- a/.github/workflows/shellcheck_test.yml
+++ b/.github/workflows/shellcheck_test.yml
@@ -1,10 +1,12 @@
-# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# GA doc: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# github-script doc: https://github.com/marketplace/actions/github-script
name: Shellcheck test
on:
pull_request:
branches:
- master
- rhel*-branch
+ - new-feature-actions-PR-comments
jobs:
shellCheck:
@@ -12,17 +14,40 @@ jobs:
defaults:
run:
shell: bash
+
steps:
- name: Install dependencies
run: sudo apt update && sudo apt-get install -y cmake help2man libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev tree
+
- name: Clone csdiff repository
run: cd ../ && git clone --depth=1 https://github.com/csutils/csdiff.git && cd -
+
- name: Build and install csdiff
run: cd ../csdiff && sudo make && sudo make install && cd -
+
- name: Repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
+
- name: Run shell-check test
- run: bash ./.github/workflows/check-shell.sh ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
+ run: |
+ bash ./.github/workflows/check-shell.sh ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
+
+ - name: Output test results
+ # Run this step even if previous failed
+ if: always()
+ uses: actions/github-script@v5
+ with:
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ # Colored GH comments: https://stackoverflow.com/a/39413824
+ script: |
+ github.rest.issues.createComment({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: '```diff\n@@ Shellcheck test summary @@\n- added issues: ${{ env.NUMBER_OF_ADDED_ISSUES }}\n+ solved issues: ${{ env.NUMBER_OF_SOLVED_ISSUES }}\n\n# list of edited shell scripts:\n${{ env.LIST_OF_SCRIPTS }}\n```'
+ })
+
+ # TODO: Set labels based on env.NUMBER_OF_ADDED_ISSUES and env.NUMBER_OF_SOLVED_ISSUES