Skip to content

Commit 7619319

Browse files
committed
ci: Add a pre-check to detect whitespace
Add a pre-merge check to detect any whitespace and fail the pre-merge if any detected. Signed-off-by: Azhar Shaikh <azhashai@qti.qualcomm.com>
1 parent 7172fb3 commit 7619319

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

.github/workflows/shellcheck.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,27 @@ jobs:
114114
exit "$rc"
115115
' sh < "$files_list"
116116
117+
- name: Check for trailing whitespace in .sh files (pull_request)
118+
if: github.event_name == 'pull_request'
119+
env:
120+
BASE_BRANCH: ${{ github.base_ref }}
121+
run: |
122+
set -eu
123+
124+
if [ -z "$BASE_BRANCH" ]; then
125+
echo "BASE_BRANCH is empty"
126+
exit 1
127+
fi
128+
129+
if ! git check-ref-format --branch "$BASE_BRANCH" >/dev/null 2>&1; then
130+
echo "Invalid base branch name: $BASE_BRANCH"
131+
exit 1
132+
fi
133+
134+
git fetch --no-tags origin "+refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}"
135+
136+
MERGE_BASE="$(git merge-base HEAD "refs/remotes/origin/${BASE_BRANCH}")"
137+
138+
git diff --check "${MERGE_BASE}"...HEAD \
139+
&& echo "No trailing whitespace found." \
140+
|| { echo "ERROR: Trailing whitespace or space/tab conflict found!"; exit 1; }

0 commit comments

Comments
 (0)