actions: static/rpm-spec check added
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 19 Jan 2024 07:12:25 +0000 (16:12 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 31 Jan 2024 06:43:46 +0000 (15:43 +0900)
RPM-SPEC runs rpmlint if .spec file is updated.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
.github/workflows/static.check.scripts/rpm-spec.sh [new file with mode: 0644]
.github/workflows/static.check.yml

diff --git a/.github/workflows/static.check.scripts/rpm-spec.sh b/.github/workflows/static.check.scripts/rpm-spec.sh
new file mode 100644 (file)
index 0000000..c07ca08
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/env bash
+
+##
+# Imported from TAOS-CI
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved.
+# Modified for Github-Action in 2024.
+#
+# Argument 1 ($1): the file containing the list of files to be checked
+# Argument 2 ($2): the max number of errors to be tolerated
+
+##
+# @file     rpm-spec.sh
+# @brief    Check the spec file (packaging/*.spec) with rpmlint. Originally pr-prebuild-rpm-spec.sh
+# @see      https://github.com/nnstreamer/TAOS-CI
+# @see      https://github.com/nnstreamer/nnstreamer
+# @author   Geunsik Lim <geunsik.lim@samsung.com>
+# @author   MyungJoo Ham <myungjoo.ham@samsung.com>
+#
+
+if [ -z $1 ]; then
+  echo "::error The argument (file path) is not given."
+  exit 1
+fi
+
+tolerable=0
+if [ -z $2 ]; then
+  echo "Tolarable rpmlint errors = 0"
+else
+  tolerable=$2
+  echo "Tolarable rpmlint errors = $2"
+fi
+
+files=$1
+failed=0
+
+if [ ! -f $files ]; then
+  echo "::error The file $files does not exists."
+  exit 1
+fi
+
+spec_modified="false"
+specfiles=""
+resultfile=$(mktemp)
+
+for file in `cat $files`; do
+  if [[ $file =~ ^obsolete/.* ]]; then
+      continue
+  fi
+  if [[ $file =~ ^external/.* ]]; then
+      continue
+  fi
+  # Handle only spec file in case that there are lots of files in one commit.
+  if [[ `file $file | grep "ASCII text" | wc -l` -gt 0 ]]; then
+    case $file in
+      *.spec)
+        specfiles+=" ${file}"
+        echo "A .spec file found: $file"
+        spec_modified="true"
+        break
+      ;;
+    esac
+  fi
+done
+
+if [[ spec_modified == "true" ]]; then
+  rpmlint $specfiles | aha --line-fix > $resultfile
+  echo "::group::rpmlint result"
+  cat $resultfile
+  echo "::ungroup::"
+
+  count=`grep "[0-9]* errors, [0-9]* warnings." $resultfile | grep -o "[0-9]* errors" | grep -o "[0-9]*"`
+  if [ $count -gt $tolerable ]; then
+    echo "::error RPMLINT reports more errors ($count) than tolerated ($tolerable)."
+    exit 1
+  fi
+else
+  echo "There is no .spec file modified in this PR. RPMLINT is not executed."
+fi
index f2cf29f..fd25529 100644 (file)
@@ -21,7 +21,7 @@ jobs:
           ref: ${{ github.event.pull_request.head.sha }}
           fetch-depth: -${{ github.event.pull_request.commits }}
       - name: Preparing step 2... Installing packages
-        run: sudo apt-get update && sudo apt-get install clang-format git grep gawk exuberant-ctags indent pylint
+        run: sudo apt-get update && sudo apt-get install clang-format git grep gawk exuberant-ctags indent pylint rpmlint aha
       - name: Preparing step 3... Identify changed files
         run: |
           tmpfile_pre=$(mktemp)
@@ -97,3 +97,9 @@ jobs:
         # Originally from "pr-prebuild-newline"
         run: |
           bash .github/workflows/static.check.scripts/newline.sh $changed_file_list
+      - name: /Checker/ RPM Spec
+        # Originally from "pr-prebuild-rpm-spec"
+        # Need "rpmlint", "aha"
+        # Tolerated errors: 40 (make it 0 someday!!!)
+        run: |
+          bash .github/workflows/static.check.scripts/rpm-spec.sh $changed_file_list 40