From ccf295a6bbec09a87d0241fce488d30800875ae4 Mon Sep 17 00:00:00 2001 From: Jason Naylor Date: Tue, 26 Mar 2024 15:05:04 -0700 Subject: [PATCH] Add CI check for whitespace Change-Id: I7cb38bcb9b632ef73b483207f1ecc7619db653b8 --- .github/workflows/whitespace.yml | 71 ++++++++++++++++++++++++ Src/AssemblyInfoForUiIndependentTests.cs | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/whitespace.yml diff --git a/.github/workflows/whitespace.yml b/.github/workflows/whitespace.yml new file mode 100644 index 0000000000..ce24a4ca48 --- /dev/null +++ b/.github/workflows/whitespace.yml @@ -0,0 +1,71 @@ +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 + "--- "*) + commit="${line#--- }" + commitText="${commit}" + commitTextmd="[${commit}](https://github.com/${{ github.repository }}/commit/${commit})" + ;; + "") + ;; + *:[1-9]*:) # contains file and line number information - This indicates that a whitespace error was found + dash=${line%%:*} + dashend=${line#*:} + dashend=${dashend%:*} + problems+=("[${line}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash}#L${dashend}) ${commit}") + ;; + *) + if test -n "${commit}"; then + problems+=("1) --- ${commitTextmd}") + echo "" + echo "--- ${commitText}" + commit= + fi + ;; + 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" diff --git a/Src/AssemblyInfoForUiIndependentTests.cs b/Src/AssemblyInfoForUiIndependentTests.cs index e827eb58a9..4714c389e3 100644 --- a/Src/AssemblyInfoForUiIndependentTests.cs +++ b/Src/AssemblyInfoForUiIndependentTests.cs @@ -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]