aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Macku <jamacku@redhat.com>2022-02-01 09:34:02 +0100
committerJan Macku <jamacku@redhat.com>2022-02-01 14:54:25 +0100
commit3eee59032cd3f1793d13fe16dbd609d350d5fbb7 (patch)
tree6cee01eff0289cfc8fab3000569dff94b72eea28
parenta69c0d8cb472399814f2c71b1e6622b628163766 (diff)
downloadinitscripts-3eee59032cd3f1793d13fe16dbd609d350d5fbb7.tar
initscripts-3eee59032cd3f1793d13fe16dbd609d350d5fbb7.tar.gz
initscripts-3eee59032cd3f1793d13fe16dbd609d350d5fbb7.tar.bz2
initscripts-3eee59032cd3f1793d13fe16dbd609d350d5fbb7.tar.xz
initscripts-3eee59032cd3f1793d13fe16dbd609d350d5fbb7.zip
ci: Use Differential ShellCheck action
-rw-r--r--.github/.diff-shellcheck-exceptions.txt (renamed from .github/workflows/exception-list.txt)0
-rw-r--r--.github/.diff.shellcheck-scripts.txt (renamed from .github/workflows/script-list.txt)0
-rwxr-xr-x.github/workflows/check-shell.sh111
-rw-r--r--.github/workflows/functions.sh93
-rw-r--r--.github/workflows/shellcheck_test.yml52
-rw-r--r--README.md4
6 files changed, 13 insertions, 247 deletions
diff --git a/.github/workflows/exception-list.txt b/.github/.diff-shellcheck-exceptions.txt
index 5b093820..5b093820 100644
--- a/.github/workflows/exception-list.txt
+++ b/.github/.diff-shellcheck-exceptions.txt
diff --git a/.github/workflows/script-list.txt b/.github/.diff.shellcheck-scripts.txt
index 053672df..053672df 100644
--- a/.github/workflows/script-list.txt
+++ b/.github/.diff.shellcheck-scripts.txt
diff --git a/.github/workflows/check-shell.sh b/.github/workflows/check-shell.sh
deleted file mode 100755
index 76e95bb0..00000000
--- a/.github/workflows/check-shell.sh
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/bin/bash
-
-SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
-
-. $SCRIPT_DIR/functions.sh
-
-git_base=$1
-git_head=$2
-
-# ------------ #
-# FILE PATHS #
-# ------------ #
-
-# https://github.com/actions/runner/issues/342
-# get names of files from PR (excluding deleted files)
-git diff --name-only --diff-filter=db "$git_base".."$git_head" > ../pr-changes.txt
-
-# Find modified shell scripts
-list_of_changes=()
-file_to_array "../pr-changes.txt" "list_of_changes" 0
-list_of_scripts=()
-file_to_array "$SCRIPT_DIR/script-list.txt" "list_of_scripts" 1
-
-# Create list of scripts for testing
-list_of_changed_scripts=()
-for file in "${list_of_changes[@]}"; do
- is_it_script "$file" "${list_of_scripts[@]}" && list_of_changed_scripts+=("./${file}") && continue
- check_extension "$file" && list_of_changed_scripts+=("./${file}") && continue
- 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
-string_of_exceptions=$(join_by , "${list_of_exceptions[@]}")
-
-echo -e "\n"
-echo ":::::::::::::::::::::"
-echo -e "::: ${WHITE}Shellcheck CI${NOCOLOR} :::"
-echo ":::::::::::::::::::::"
-echo -e "\n"
-
-echo -e "${WHITE}Changed shell scripts:${NOCOLOR}"
-echo "${list_of_changed_scripts[@]}"
-echo -e "${WHITE}List of shellcheck exceptions:${NOCOLOR}"
-echo "${string_of_exceptions}"
-echo -e "\n"
-
-# ------------ #
-# SHELLCHECK #
-# ------------ #
-
-# sed part is to edit shellcheck output so csdiff/csgrep knows it is shellcheck output (--format=gcc)
-shellcheck --format=gcc --exclude="${string_of_exceptions}" "${list_of_changed_scripts[@]}" 2> /dev/null | sed -e 's|$| <--[shellcheck]|' > ../pr-br-shellcheck.err
-
-# make destination branch
-git checkout -q -b ci_br_dest "$git_base"
-
-shellcheck --format=gcc --exclude="${string_of_exceptions}" "${list_of_changed_scripts[@]}" 2> /dev/null | sed -e 's|$| <--[shellcheck]|' > ../dest-br-shellcheck.err
-
-# ------------ #
-# VALIDATION #
-# ------------ #
-
-exitstatus=0
-echo ":::::::::::::::::::::::::"
-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}"
- csgrep ../fixes.log
- echo "---------------------"
-else
- echo -e "${YELLOW}No Fixes!${NOCOLOR}"
- echo "---------------------"
-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}"
- csgrep ../bugs.log
- echo "---------------------"
- exitstatus=1
-else
- echo -e "${GREEN}No bugs added Yay!${NOCOLOR}"
- echo "---------------------"
- exitstatus=0
-fi
-
-exit $exitstatus
diff --git a/.github/workflows/functions.sh b/.github/workflows/functions.sh
deleted file mode 100644
index d6128486..00000000
--- a/.github/workflows/functions.sh
+++ /dev/null
@@ -1,93 +0,0 @@
-# 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
-# $? - return value - 0 when succes
-is_it_script () {
- [ $# -le 1 ] && return 1
- local file="$1"
- shift
- local scripts=("$@")
-
- [[ " ${scripts[*]} " =~ " ${file} " ]] && return 0 || return 2
-}
-
-# Function to check if given file has .sh extension
-# https://stackoverflow.com/a/407229
-# $1 - <string> absolute path to file
-# $? - return value - 0 when succes
-check_extension () {
- [ $# -le 0 ] && return 1
- local file="$1"
-
- [ "${file: -3}" == ".sh" ] && return 0 || return 2
-}
-
-# Function to check if given file contain shell shebang (bash or sh)
-# https://unix.stackexchange.com/a/406939
-# $1 - <string> absolute path to file
-# $? - return value - 0 when succes
-check_shebang () {
- [ $# -le 0 ] && return 1
- local file="$1"
-
- if IFS= read -r line < "./${file}" ; then
- case $line in
- "#!/bin/bash") return 0;;
- "#!/bin/sh") return 0;;
- *) return 1
- esac
- fi
-}
-
-# Function to prepare string from array of strings where first argument specify one character separator
-# https://stackoverflow.com/a/17841619
-# $1 - <char> Character used to join elements of array
-# $@ - <array of string> list of strings
-# return value - string
-join_by () {
- local IFS="$1"
- shift
- echo "$*"
-}
-
-# Function to get rid of comments represented by '#'
-# $1 - file path
-# $2 - name of variable where will be stored result array
-# $3 - value 1|0 - does file content inline comments?
-# $? - return value - 0 when succes
-file_to_array () {
- [ $# -le 2 ] && return 1
- local output=()
-
- [ "$3" -eq 0 ] && readarray output < <(grep -v "^#.*" "$1") # fetch array with lines from file while excluding '#' comments
- [ "$3" -eq 1 ] && readarray output < <(cut -d ' ' -f 1 < <(grep -v "^#.*" "$1")) # fetch array with lines from file while excluding '#' comments
- clean_array "$2" "${output[@]}" && return 0
-}
-
-# Function to get rid of spaces and new lines from array elements
-# https://stackoverflow.com/a/9715377
-# https://stackoverflow.com/a/19347380
-# https://unix.stackexchange.com/a/225517
-# $1 - name of variable where will be stored result array
-# $@ - source array
-# $? - return value - 0 when succes
-clean_array () {
- [ $# -le 2 ] && return 1
- local output="$1"
- shift
- local input=("$@")
-
- for i in "${input[@]}"; do
- eval $output+=\("${i//[$'\t\r\n ']}"\)
- done
-}
-
-# Color aliases use echo -e to use them
-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 073a5b29..bc5f3452 100644
--- a/.github/workflows/shellcheck_test.yml
+++ b/.github/workflows/shellcheck_test.yml
@@ -1,53 +1,23 @@
-# 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
+name: Differential ShellCheck
on:
+ push:
+ branches: [master, rhel*-branch]
pull_request:
- branches:
- - master
- - rhel*-branch
+ branches: [master, rhel*-branch]
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
+ steps:
+ - name: 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 }}
-
- # ! Disable Output, since there is a problem with permissions and GITHUB_TOKEN
- # ! https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/
- # TODO: possible solution is to use probot framework to build github app/action
- # TODO: Set labels based on env.NUMBER_OF_ADDED_ISSUES and env.NUMBER_OF_SOLVED_ISSUES
- # - name: Output test results
- # # Run this step even if previous failed
- # if: always()
- # uses: actions/github-script@v5
- # with:
- # # 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```'
- # })
+ - name: Differential ShellCheck
+ uses: redhat-plumbers-in-action/differential-shellcheck@v1
+ with:
+ ignored-codes: .github/.diff-shellcheck-exceptions.txt
+ shell-scripts: .github/.diff.shellcheck-scripts.txt
diff --git a/README.md b/README.md
index bf491a71..4d4daa18 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-# initscripts | [![Build Status](https://github.com/fedora-sysv/initscripts/workflows/Integration%20test/badge.svg)](https://github.com/fedora-sysv/initscripts/actions?query=workflow%3AIntegration+test) [![Shellcheck Status](https://github.com/fedora-sysv/initscripts/workflows/Shellcheck%20test/badge.svg)](https://github.com/fedora-sysv/initscripts/actions?query=workflow%3AShellcheck+test)
+# initscripts
-[![Total alerts](https://img.shields.io/lgtm/alerts/g/fedora-sysv/initscripts.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/fedora-sysv/initscripts/alerts/) [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/fedora-sysv/initscripts.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/fedora-sysv/initscripts/context:python) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/fedora-sysv/initscripts.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/fedora-sysv/initscripts/context:cpp) [![Mergify Status][mergify-status]][mergify]
+[![Build Status](https://github.com/fedora-sysv/initscripts/workflows/Integration%20test/badge.svg)](https://github.com/fedora-sysv/initscripts/actions?query=workflow%3AIntegration+test) [![Differential ShellCheck](https://github.com/fedora-sysv/initscripts/actions/workflows/shellcheck_test.yml/badge.svg)](https://github.com/fedora-sysv/initscripts/actions/workflows/shellcheck_test.yml) [![Total alerts](https://img.shields.io/lgtm/alerts/g/fedora-sysv/initscripts.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/fedora-sysv/initscripts/alerts/) [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/fedora-sysv/initscripts.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/fedora-sysv/initscripts/context:python) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/fedora-sysv/initscripts.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/fedora-sysv/initscripts/context:cpp) [![Mergify Status][mergify-status]][mergify]
[mergify]: https://mergify.io
[mergify-status]: https://img.shields.io/endpoint.svg?url=https://dashboard.mergify.io/badges/fedora-sysv/initscripts&style=flat