From b374096cdc841e1d5f03944fab48d8f13981902b Mon Sep 17 00:00:00 2001 From: MyungJoo Ham Date: Fri, 19 Jan 2024 16:12:25 +0900 Subject: [PATCH] actions: static/rpm-spec check added RPM-SPEC runs rpmlint if .spec file is updated. Signed-off-by: MyungJoo Ham --- .github/workflows/static.check.scripts/rpm-spec.sh | 78 ++++++++++++++++++++++ .github/workflows/static.check.yml | 8 ++- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/static.check.scripts/rpm-spec.sh diff --git a/.github/workflows/static.check.scripts/rpm-spec.sh b/.github/workflows/static.check.scripts/rpm-spec.sh new file mode 100644 index 0000000..c07ca08 --- /dev/null +++ b/.github/workflows/static.check.scripts/rpm-spec.sh @@ -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 +# @author MyungJoo Ham +# + +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 diff --git a/.github/workflows/static.check.yml b/.github/workflows/static.check.yml index f2cf29f..fd25529 100644 --- a/.github/workflows/static.check.yml +++ b/.github/workflows/static.check.yml @@ -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 -- 2.7.4