From 05f1963aa58b5051973a7f4017234c2b726f989c Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Fri, 2 Feb 2024 15:17:39 +0530 Subject: [PATCH] Add format check. Use "ci" for all workflow names. --- .github/format_check_diff.sh | 13 +++++++++++++ .github/workflows/format_check.yml | 11 +++++++++++ .github/workflows/no_pch.yml | 2 +- lib/src/core/version.cpp | 2 +- tools/format_code.sh | 24 ++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100755 .github/format_check_diff.sh create mode 100644 .github/workflows/format_check.yml create mode 100755 tools/format_code.sh diff --git a/.github/format_check_diff.sh b/.github/format_check_diff.sh new file mode 100755 index 0000000..791e32c --- /dev/null +++ b/.github/format_check_diff.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +[[ ! $(git --version) ]] && exit 1 + +output=$(git diff) + +if [[ "$output" != "" ]]; then + echo "One or more source files are not formatted!" + exit 1 +fi + +echo "All source files are formatted" +exit diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml new file mode 100644 index 0000000..c0e4aaa --- /dev/null +++ b/.github/workflows/format_check.yml @@ -0,0 +1,11 @@ +name: ci +on: [push] +jobs: + format-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: format code + run: tools/format_code.sh + - name: check diff + run: .github/format_check_diff.sh diff --git a/.github/workflows/no_pch.yml b/.github/workflows/no_pch.yml index 6426ba2..f2a3fff 100644 --- a/.github/workflows/no_pch.yml +++ b/.github/workflows/no_pch.yml @@ -1,4 +1,4 @@ -name: no-pch +name: ci on: [pull_request] jobs: build-linux-no-pch: diff --git a/lib/src/core/version.cpp b/lib/src/core/version.cpp index 937eb17..421494a 100644 --- a/lib/src/core/version.cpp +++ b/lib/src/core/version.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include namespace bave { diff --git a/tools/format_code.sh b/tools/format_code.sh new file mode 100755 index 0000000..d69b061 --- /dev/null +++ b/tools/format_code.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +[[ ! $(clang-format --version) ]] && exit 1 + +script_path=${0%/*} +tools_root=${script_path%/*} +project_root=$tools_root/.. + +if [[ "$0" != "$project_root" ]] && [[ "$project_root" != "" ]]; then + cd "$project_root" || exit 1 + echo "-- Changed pwd to $(pwd)" +fi + +files=$(find lib tools example/android/app/src/main example/desktop example/flappy -name "*.?pp") + +if [[ "$files" == "" ]]; then + echo "-- No source files found" + exit +fi + +clang-format -i $files || exit 1 +echo -e "-- Formatted Files:\n$files\n" + +exit