Sunshine/.github/workflows/cpp-lint.yml

121 lines
3.6 KiB
YAML
Raw Normal View History

2022-08-08 00:26:40 +00:00
---
# This action is centrally managed in https://github.com/<organization>/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
# the above-mentioned repo.
2023-01-02 16:17:02 +00:00
# Lint c++ source files and cmake files.
2022-12-29 13:24:13 +00:00
name: C++ Lint
2022-08-08 00:26:40 +00:00
on:
pull_request:
branches: [master, nightly]
types: [opened, synchronize, reopened]
2023-01-02 16:17:02 +00:00
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
2022-08-08 00:26:40 +00:00
jobs:
2023-01-02 16:17:02 +00:00
clang-format:
name: Clang Format Lint
2022-08-08 00:26:40 +00:00
runs-on: ubuntu-latest
2023-01-02 16:17:02 +00:00
2022-08-08 00:26:40 +00:00
steps:
- name: Checkout
2023-09-05 22:46:54 +00:00
uses: actions/checkout@v4
2022-08-08 00:26:40 +00:00
2023-01-02 16:17:02 +00:00
- name: Find cpp files
id: find_files
2022-08-08 00:26:40 +00:00
run: |
# find files
found_files=$(find . -type f -iname "*.cpp" -o -iname "*.h" -o -iname "*.m" -o -iname "*.mm")
ignore_files=$(find . -type f -iname ".clang-format-ignore")
# Loop through each C++ file
for file in $found_files; do
for ignore_file in $ignore_files; do
ignore_directory=$(dirname "$ignore_file")
# if directory of ignore_file is beginning of file
if [[ "$file" == "$ignore_directory"* ]]; then
echo "ignoring file: ${file}"
found_files="${found_files//${file}/}"
break 1
fi
done
done
# remove empty lines
found_files=$(echo "$found_files" | sed '/^\s*$/d')
echo "found cpp files: ${found_files}"
2022-08-08 00:26:40 +00:00
2023-01-02 16:17:02 +00:00
# do not quote to keep this as a single line
echo found_files=${found_files} >> $GITHUB_OUTPUT
2022-08-08 00:26:40 +00:00
- name: Clang format lint
if: ${{ steps.find_files.outputs.found_files }}
uses: DoozyX/clang-format-lint-action@v0.16.2
2022-08-08 00:26:40 +00:00
with:
source: ${{ steps.find_files.outputs.found_files }}
2022-08-08 00:26:40 +00:00
extensions: 'cpp,h,m,mm'
clangFormatVersion: 16
2022-08-08 00:26:40 +00:00
style: file
inplace: false
- name: Upload Artifacts
if: failure()
uses: actions/upload-artifact@v4
2022-08-08 00:26:40 +00:00
with:
name: clang-format-fixes
path: ${{ steps.find_files.outputs.found_files }}
2022-12-29 13:24:13 +00:00
cmake-lint:
name: CMake Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
2023-09-05 22:46:54 +00:00
uses: actions/checkout@v4
2022-12-29 13:24:13 +00:00
- name: Set up Python
2023-12-07 16:48:02 +00:00
uses: actions/setup-python@v5
2022-12-29 13:24:13 +00:00
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools cmakelang
- name: Find cmake files
id: find_files
2022-12-29 13:24:13 +00:00
run: |
# find files
found_files=$(find . -type f -iname "CMakeLists.txt" -o -iname "*.cmake")
ignore_files=$(find . -type f -iname ".cmake-lint-ignore")
# Loop through each C++ file
for file in $found_files; do
for ignore_file in $ignore_files; do
ignore_directory=$(dirname "$ignore_file")
# if directory of ignore_file is beginning of file
if [[ "$file" == "$ignore_directory"* ]]; then
echo "ignoring file: ${file}"
found_files="${found_files//${file}/}"
break 1
fi
done
done
# remove empty lines
found_files=$(echo "$found_files" | sed '/^\s*$/d')
echo "found cmake files: ${found_files}"
2022-12-29 13:24:13 +00:00
# do not quote to keep this as a single line
echo found_files=${found_files} >> $GITHUB_OUTPUT
2022-12-29 13:24:13 +00:00
- name: Test with cmake-lint
run: |
cmake-lint --line-width 120 --tab-size 4 ${{ steps.find_files.outputs.found_files }}