Skip to content

Remove duplicate transition rule file. #1681

Remove duplicate transition rule file.

Remove duplicate transition rule file. #1681

name: Code Integrity
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]
jobs:
code_integrity_checks:
name: Static Code Analysis
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 2
- name: Install clang-format-19
shell: bash
run: |
# 14s to install from apt, getting 19.1.1
# Getting it from LLVM takes 1min13s
# sudo apt-get update && apt-get install -y wget gnupg lsb-release software-properties-common
# wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg
# echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-19 main" | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt-get update -qq
sudo apt-get install -y -q clang-format-19
clang-format-19 --version
- name: Run clang-format against C++ files touched by the PR
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
clang-format-19 --version
begin_group() { echo -e "::group::\033[93m$1\033[0m"; }
begin_group "Find changed files"
echo "GITHUB_REF=$GITHUB_REF GITHUB_BASE_REF=$GITHUB_BASE_REF GITHUB_HEAD_REF=$GITHUB_HEAD_REF"
# too slow on E+: git fetch --all --quiet
# first find if any files changed
# HEAD^ works in PRs because actions/checkout checks out a merge commit by default in PR contexts
# and I specified a fetch-depth of 2
readarray -t changed_files < <(git diff --name-only --diff-filter=AM HEAD^ HEAD src/ tst/ | /bin/grep -E '\.(cpp|cc|c|hpp|hh|h)$')
file_count=${#changed_files[@]}
if [ $file_count -eq 0 ]; then
echo "No files of type (cpp, c, hpp, h) changed. Skipping clang-formatting"
exit 0
else
begin_group "Found $file_count C/C++ changed files"
for file in "${changed_files[@]}"; do
echo "$file"
done
echo "::endgroup::"
fi
echo "::endgroup::"
begin_group "Run clang-format for changes files"
# Using \0 as a terminator in case we'd ever have files with spaces
git diff -z --diff-filter=AM --name-only HEAD^ HEAD src/ tst/ \
| /bin/grep -z -E '\.(cpp|cc|c|hpp|hh|h)$' \
| xargs -0 -P "$(nproc)" -n 1 clang-format-19 -style=file -i -fallback-style=none --verbose
# clang-format will auto correct files so prepare the diff and use this as artifact
git diff > clang_format.patch
echo "::endgroup::"
# Delete if nothing otherwise exit 1 to indicate a failed job
if [ ! -s clang_format.patch ]; then
rm clang_format.patch
exit 0
else
incorrect_count=$(git diff --name-only | wc -l)
incorrect_percent=$(awk "BEGIN { printf \"%.2f\", ($incorrect_count/$file_count)*100 }")
begin_group "clang-format auto corrected $incorrect_count files:"
git diff --name-only
echo "::endgroup::"
echo "::error title=Clang Format Check Failed::Formatting issues detected in $incorrect_count files"
echo -e "\nPlease correct these files by running clang-format-19 locally, or download the artifact "
echo 'and run `patch -p1 < /path/to/clang_format.patch`'
{
echo "| Item | Value |"
echo "|---------------------------------------|-----------|"
echo "| Number of Files Analyzed | $file_count |"
echo "| Number of Files Incorrectly Formatted | $incorrect_count |"
echo "| % Files Incorrectly Formatted | ${incorrect_percent}% |"
} >> "$GITHUB_STEP_SUMMARY"
exit 1
fi
- name: Run clang-format for entire codebase
if: ${{ github.event_name == 'push' }}
shell: bash
run: |
clang-format-19 --version
begin_group() { echo -e "::group::\033[93m$1\033[0m"; }
begin_group "Run clang-format"
find src tst \( -name "*.hpp" -o -name "*.h" -o -name "*.hh" -o -name "*.cc" -o -name "*.cpp" -o -name "*.c" \) \
-print0 | xargs -0 -P "$(nproc)" -n 1 clang-format-19 -style=file -i -fallback-style=none --verbose
# clang-format will auto correct files so prepare the diff and use this as artifact
git diff > clang_format.patch
echo "::endgroup::"
# Delete if nothing otherwise exit 1 to indicate a failed job
if [ ! -s clang_format.patch ]; then
rm clang_format.patch
exit 0
else
file_count=$(find src tst \( -name "*.hpp" -o -name "*.h" -o -name "*.hh" -o -name "*.cc" -o -name "*.cpp" -o -name "*.c" \) | wc -l)
incorrect_count=$(git diff --name-only | wc -l)
incorrect_percent=$(awk "BEGIN { printf \"%.2f\", ($incorrect_count/$file_count)*100 }")
begin_group "clang-format auto corrected $incorrect_count files:"
git diff --name-only
echo "::endgroup::"
echo "::error title=Clang Format Check Failed::Formatting issues detected in $incorrect_count files"
{
echo "| Item | Value |"
echo "|---------------------------------------|-----------|"
echo "| Number of Files Analyzed | $file_count |"
echo "| Number of Files Incorrectly Formatted | $incorrect_count |"
echo "| % Files Incorrectly Formatted | ${incorrect_percent}% |"
} >> "$GITHUB_STEP_SUMMARY"
exit 1
fi
- name: Upload clang-format patch as artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: EnergyPlus-${{ github.sha }}-clang_format.patch
path: clang_format.patch
- name: Commit Auto-corrections
shell: bash
if: ${{ always() && github.event_name == 'push' }}
run: |
git add -u
if [[ $(git diff --cached --exit-code) ]]; then
echo "Commiting Lint Autocorrects"
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git config --global user.name 'github-actions[bot]'
git commit -m "[chore] Commit clang-format autocorrects"
echo '' >> .git-blame-ignore-revs
git log -n1 --pretty='format:# %C(auto)%s [%an, %as]%n%H%n' >> .git-blame-ignore-revs
git add .git-blame-ignore-revs
git commit -m "Add clang-format autocorrects to git-blame-ignore-revs"
git push
else
echo "No Autocorrect needed"
fi
- name: Custom Check
if: always()
run: ./scripts/dev/custom_check.sh .
- name: Install cppcheck
if: always()
run: sudo apt-get install cppcheck
- name: Run CppCheck
id: cpp_check_run
if: always()
# TODO: Evaluate the long list of flags here
run: >
cppcheck
-D__cppcheck__ -UEP_Count_Calls -DEP_NO_OPENGL -UGROUND_PLOT -DLINK_WITH_PYTHON -DMSVC_DEBUG -DSKYLINE_MATRIX_REMOVE_ZERO_COLUMNS -U_OPENMP -Ugeneratetestdata
-DEP_cache_GlycolSpecificHeat -DEP_cache_PsyTsatFnPb -UEP_nocache_Psychrometrics -UEP_psych_errors -UEP_psych_stats
--force
--std=c++17
--inline-suppr
--suppress=missingInclude
--suppress=missingIncludeSystem
--suppress=unusedFunction:src/EnergyPlus/api/autosizing.cc
--suppress=unusedFunction:src/EnergyPlus/api/datatransfer.cc
--suppress=unusedFunction:src/EnergyPlus/api/func.cc
--suppress=unusedFunction:src/EnergyPlus/api/runtime.cc
--suppress=unusedFunction:src/EnergyPlus/api/state.cc
--suppress=unusedFunction:src/EnergyPlus/Psychrometrics.cc
--enable=all
-i EnergyPlus/DXCoils.cc
-i EnergyPlus/RefrigeratedCase.cc
-i EnergyPlus/SolarShading.cc
-j $(nproc)
--template='[{file}:{line}]:({severity}),[{id}],{message}'
--suppress="uninitvar:*"
./src
3>&1 1>&2 2>&3 | tee cppcheck.txt
- name: Parse and colorize cppcheck
if: always() && steps.cpp_check_run.outcome == 'success'
run: python ./scripts/dev/colorize_cppcheck_results.py
- name: Upload cppcheck results as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: EnergyPlus-${{ github.sha }}-cppcheck_results.txt
path: cppcheck.txt