Skip to content

Commit

Permalink
Add format check.
Browse files Browse the repository at this point in the history
Use "ci" for all workflow names.
  • Loading branch information
karnkaul committed Feb 2, 2024
1 parent 85a6ff3 commit 05f1963
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .github/format_check_diff.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/no_pch.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: no-pch
name: ci
on: [pull_request]
jobs:
build-linux-no-pch:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <bave/core/version.hpp>
#include <fmt/format.h>
#include <bave/core/version.hpp>
#include <sstream>

namespace bave {
Expand Down
24 changes: 24 additions & 0 deletions tools/format_code.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 05f1963

Please sign in to comment.