Skip to content

Commit fae3fb3

Browse files
authored
Merge pull request #24 from manumerous Add format test to CI pipeline
Add format test to CI pipeline
2 parents 9e62e3b + 5f2cf8a commit fae3fb3

File tree

11 files changed

+101
-21
lines changed

11 files changed

+101
-21
lines changed

.clang-format

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BasedOnStyle: Google
2+
ColumnLimit: 140
3+
IndentWidth: 2
4+
BreakBeforeBraces: Attach
5+
DerivePointerAlignment: false
6+
PointerAlignment: Left
7+
AllowShortFunctionsOnASingleLine: Inline
8+
IncludeBlocks: Preserve
9+
BinPackParameters: false

.github/workflows/format_test.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Code Format Check
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
format-check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.x'
21+
22+
- name: Install Python formatters
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install black
26+
27+
- name: Install clang-format
28+
run: |
29+
sudo apt-get update
30+
sudo apt-get install -y clang-format
31+
32+
- name: Check clang-format version
33+
run: clang-format --version
34+
35+
- name: Check Black version
36+
run: black --version
37+
38+
- name: Check git status before formatting
39+
run: git status --porcelain
40+
41+
- name: Run make format
42+
run: make format
43+
44+
- name: Check for formatting changes
45+
id: format-check
46+
run: |
47+
if [ -n "$(git status --porcelain)" ]; then
48+
echo "changes=true" >> $GITHUB_OUTPUT
49+
echo "❌ Files were modified by 'make format'"
50+
echo ""
51+
echo "Modified files:"
52+
git status --porcelain
53+
echo ""
54+
echo "Diff:"
55+
git diff
56+
else
57+
echo "changes=false" >> $GITHUB_OUTPUT
58+
echo "✅ No formatting changes needed"
59+
fi
60+
61+
- name: Display formatting instructions
62+
if: steps.format-check.outputs.changes == 'true'
63+
run: |
64+
echo "❌ Code formatting check failed!"
65+
echo ""
66+
echo "To fix all formatting issues, run:"
67+
echo ""
68+
echo " make format"
69+
echo ""
70+
echo "Then commit and push your changes."
71+
72+
- name: Fail if formatting issues found
73+
if: steps.format-check.outputs.changes == 'true'
74+
run: |
75+
echo "Code formatting issues detected. Please run 'make format' to fix them."
76+
exit 1

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# clang
2-
.clang-*
3-
41
# Remove accidental build stuff put in here
52
build/
63
log/

Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,8 @@ clean-cppad:
170170
rm -rf cppad_code_gen
171171

172172
format:
173-
lib/halodi-ros2-code-quality/Tools/fix_code_style.sh robot_models humanoid_nmpc
174-
175-
validate-format:
176-
lib/halodi-ros2-code-quality/Tools/check_code_style.sh robot_models humanoid_nmpc
177-
173+
find . -name "lib" -prune -o \( -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) -print | xargs clang-format -i && \
174+
black . --exclude="lib/"
178175

179176
launch-g1-dummy-sim:
180177
cd ${build_dir} && \

dependencies.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ninja-build
1111
ccache
1212
python3-pygame
1313
python3-tk
14+
black
1415

1516
ros-${ROS_DISTRO}-ament-cmake-clang-format
1617
ros-${ROS_DISTRO}-joint-state-publisher-gui

humanoid_nmpc/humanoid_common_mpc/include/humanoid_common_mpc/gait/GaitScheduleUpdater.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class GaitScheduleUpdater : public SolverSynchronizedModule {
5353
const vector_t& currentState,
5454
const ReferenceManagerInterface& referenceManager) override;
5555

56-
void postSolverRun(const PrimalSolution&) override{};
56+
void postSolverRun(const PrimalSolution&) override {};
5757

5858
// Override this function in case you need to e.g. access the received gait in a mutex protected way.
5959
virtual ModeSequenceTemplate getReceivedGait() { return receivedGait_; }

humanoid_nmpc/humanoid_common_mpc/include/humanoid_common_mpc/reference_manager/ProceduralMpcMotionManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ProceduralMpcMotionManager : public SolverSynchronizedModule {
9696
*
9797
* @param primalSolution : primalSolution
9898
*/
99-
void postSolverRun(const PrimalSolution& primalSolution) override{};
99+
void postSolverRun(const PrimalSolution& primalSolution) override {};
100100

101101
virtual void setAndScaleVelocityCommand(const WalkingVelocityCommand& rawVelocityCommand);
102102

humanoid_nmpc/humanoid_common_mpc/src/gait/GaitSchedule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void GaitSchedule::tileModeSequenceTemplate(scalar_t startTime, scalar_t finalTi
137137
scalar_t deltaTime = templateTimes[i + 1] - templateTimes[i];
138138
eventTimes.push_back(eventTimes.back() + deltaTime);
139139
} // end of i loop
140-
} // end of while loop
140+
} // end of while loop
141141

142142
// default final phase
143143
modeSequence.push_back(ModeNumber::STANCE);

humanoid_nmpc/humanoid_common_mpc_ros2/include/humanoid_common_mpc_ros2/ros_comm/MRTPolicySubscriber.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class MRTPolicySubscriber : public MRT_BASE {
4646
*/
4747
~MRTPolicySubscriber() override;
4848

49-
void resetMpcNode(const TargetTrajectories& initTargetTrajectories) override{};
49+
void resetMpcNode(const TargetTrajectories& initTargetTrajectories) override {};
5050

51-
void setCurrentObservation(const SystemObservation& currentObservation) override{};
51+
void setCurrentObservation(const SystemObservation& currentObservation) override {};
5252

5353
/**
5454
* Shut down the ROS nodes.

humanoid_nmpc/humanoid_wb_mpc/src/end_effector/PinocchioEndEffectorDynamicsCppAd.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,8 @@ ad_vector_t PinocchioEndEffectorDynamicsCppAd::getOrientationCppAd(const ad_vect
379379
/******************************************************************************************************/
380380
/******************************************************************************************************/
381381
/******************************************************************************************************/
382-
auto PinocchioEndEffectorDynamicsCppAd::getOrientationError(const vector_t& state,
383-
const std::vector<quaternion_t>& referenceOrientations) const
384-
-> std::vector<vector3_t> {
382+
auto PinocchioEndEffectorDynamicsCppAd::getOrientationError(
383+
const vector_t& state, const std::vector<quaternion_t>& referenceOrientations) const -> std::vector<vector3_t> {
385384
vector_t params(4 * endEffectorIds_.size());
386385
for (size_t i = 0; i < endEffectorIds_.size(); i++) {
387386
params.segment<4>(i * 4) = referenceOrientations[i].coeffs();
@@ -662,8 +661,8 @@ ad_vector_t PinocchioEndEffectorDynamicsCppAd::getLinearAccelerationCppAd(const
662661
/******************************************************************************************************/
663662
/******************************************************************************************************/
664663
/******************************************************************************************************/
665-
auto PinocchioEndEffectorDynamicsCppAd::getLinearAcceleration(const vector_t& state, const vector_t& input) const
666-
-> std::vector<vector3_t> {
664+
auto PinocchioEndEffectorDynamicsCppAd::getLinearAcceleration(const vector_t& state,
665+
const vector_t& input) const -> std::vector<vector3_t> {
667666
vector_t stateInput(state.rows() + input.rows());
668667
stateInput << state, input;
669668
const vector_t accelerationValues = linearAccelerationCppAdInterfacePtr_->getFunctionValue(stateInput);
@@ -721,8 +720,8 @@ ad_vector_t PinocchioEndEffectorDynamicsCppAd::getAngularAccelerationCppAd(const
721720
/******************************************************************************************************/
722721
/******************************************************************************************************/
723722
/******************************************************************************************************/
724-
auto PinocchioEndEffectorDynamicsCppAd::getAngularAcceleration(const vector_t& state, const vector_t& input) const
725-
-> std::vector<vector3_t> {
723+
auto PinocchioEndEffectorDynamicsCppAd::getAngularAcceleration(const vector_t& state,
724+
const vector_t& input) const -> std::vector<vector3_t> {
726725
vector_t stateInput(state.rows() + input.rows());
727726
stateInput << state, input;
728727
const vector_t accelerationValues = angularAccelerationCppAdInterfacePtr_->getFunctionValue(stateInput);

0 commit comments

Comments
 (0)