action: add check if rebuild required module
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 13 Jun 2024 04:23:33 +0000 (13:23 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 19 Jun 2024 10:18:57 +0000 (19:18 +0900)
Import check-if-rebuild-requires module from nnstreamer.git

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
.github/actions/check-rebuild/action.yml [new file with mode: 0644]
.github/actions/check-rebuild/check_if_rebuild_requires.sh [new file with mode: 0644]

diff --git a/.github/actions/check-rebuild/action.yml b/.github/actions/check-rebuild/action.yml
new file mode 100644 (file)
index 0000000..cdf20e9
--- /dev/null
@@ -0,0 +1,20 @@
+name: Check if rebuild required
+description:
+
+inputs:
+  mode:
+    description: build mode to be checked
+    required: false
+    default: build
+
+runs:
+  using: composite
+  steps:
+    - run: |
+        tmpfile=$(mktemp)
+        git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile}
+        echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV"
+        rebuild=`bash .github/actions/check-rebuild/check_if_rebuild_requires.sh ${tmpfile} ${{ inputs.mode }} | grep "REBUILD=YES" | wc -l`
+        echo "Rebuild required: ${rebuild}"
+        echo "rebuild=${rebuild}" >> "$GITHUB_ENV"
+      shell: sh
diff --git a/.github/actions/check-rebuild/check_if_rebuild_requires.sh b/.github/actions/check-rebuild/check_if_rebuild_requires.sh
new file mode 100644 (file)
index 0000000..3114c2f
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/env bash
+
+##
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+# @file: check_if_rebuild_requires.sh
+# @brief    Check if rebuild & unit-test is required with the given PR.
+# @see      https://github.com/nnstreamer/nnstreamer
+# @author   MyungJoo Ham <myungjoo.ham@samsung.com>
+#
+# Argument 1 ($1): the file containing list of files to be checked.
+# Argument 2 ($2): build mode to be checked
+#                  gbs: check if Tizen GBS build is required
+#                  debian: check if pdebuild is required
+#                  android: check if jni rebuild is required
+#                  build (default): check if general meson rebuild is required.
+
+if [ -z $1 ]; then
+  echo "::error The argument (file path) is not given."
+  exit 1
+fi
+
+if [ -z $2 ]; then
+  mode="build"
+else
+  mode=$2
+fi
+
+rebuild=0
+regbs=0
+redebian=0
+reandroid=0
+
+for file in `cat $1`; do
+  case $file in
+    *.md|*.png|*.webp|*.css|*.html )
+    ;;
+    packaging/* )
+      regbs='1'
+      ;;
+    debian/* )
+      redebian='1'
+      ;;
+    jni/* )
+      reandroid='1'
+      ;;
+    * )
+      rebuild='1'
+      regbs='1'
+      redebian='1'
+      reandroid='1'
+      ;;
+  esac
+done
+
+case $mode in
+  gbs)
+    if [[ "$regbs" == "1" ]]; then
+      echo "REBUILD=YES"
+      exit 0
+    fi
+    ;;
+  debian)
+    if [[ "$redebian" == "1" ]]; then
+      echo "REBUILD=YES"
+      exit 0
+    fi
+    ;;
+  android)
+    if [[ "$reandroid" == "1" ]]; then
+      echo "REBUILD=YES"
+      exit 0
+    fi
+    ;;
+  *)
+    if [[ "$rebuild" == "1" ]]; then
+      echo "REBUILD=YES"
+      exit 0
+    fi
+    ;;
+esac
+
+echo "REBUILD=NO"