Skip to content

Commit

Permalink
Add CI check for whitespace
Browse files Browse the repository at this point in the history
Change-Id: I7cb38bcb9b632ef73b483207f1ecc7619db653b8
  • Loading branch information
jasonleenaylor committed Mar 27, 2024
1 parent 8095b5e commit fe90192
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/whitespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: check-whitespace

on:
pull_request:
types: [opened, synchronize]

# Avoid unnecessary builds
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-whitespace:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: git log --check
id: check_out
run: |
echo "Starting the script."
baseSha=${{ github.event.pull_request.base.sha }}
git log --check --pretty=format:"---% h% s" ${baseSha}.. | tee check-results.log
problems=()
commit=
commitText=
commitTextmd=
# Use git log --check to look for whitespace errors in each commit of this PR
log_output=$(cat check-results.log)
echo "${log_output}"
# Use a for loop to iterate over lines of log_output
IFS=$'\n'
for line in $log_output; do
(
echo "Line: ${line}"
case "${line}" in
"--- "*)
IFS=' ' read -r _ commit commitText <<< "$line"
commitTextmd="[${commit}](https://github.com/test/commit/${commit}) ${commitText}"
;;
"")
;;
*:[1-9]*:*) # contains file and line number information - This indicates that a whitespace error was found
dash=${line%%:*}
dashend=${line#*:}
dashend=${dashend%:*}
problems+=("${commitTextmd}")
problems+=("[${line}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash}#L${dashend})")
;;
;;
esac
)
done
if test ${#problems[*]} -gt 0; then
echo "⚠️ Please review the Summary output for further information." >> $GITHUB_STEP_SUMMARY
echo "### A whitespace issue was found in one or more of the commits." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Errors:" >> $GITHUB_STEP_SUMMARY
for i in "${problems[@]}"; do
echo "${i}" >> $GITHUB_STEP_SUMMARY
done
exit 1
fi
echo "No problems found"
2 changes: 1 addition & 1 deletion Src/AssemblyInfoForUiIndependentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// reference System.Windows.Forms et al.

// Cleanup all singletons after running tests
[assembly: CleanupSingletons]
[assembly: CleanupSingletons]

// Redirect HKCU if environment variable BUILDAGENT_SUBKEY is set
[assembly: RedirectHKCU]
Expand Down

0 comments on commit fe90192

Please sign in to comment.