Skip to content

Commit

Permalink
ci: Output shellcheck results using PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Sep 29, 2021
1 parent 90c4a1e commit 9ad6678
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/check-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/functions.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'
30 changes: 28 additions & 2 deletions .github/workflows/shellcheck_test.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
# 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:
runs-on: ubuntu-20.04
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

0 comments on commit 9ad6678

Please sign in to comment.