Skip to content

Commit e87e4cf

Browse files
committed
step
1 parent 87421b4 commit e87e4cf

3 files changed

Lines changed: 126 additions & 20 deletions

File tree

.github/workflows/format_check.yml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1+
# Copyright ARDUINO SRL (https://www.arduino.cc)
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# CI workflow to check formatting
15
name: 'Format Check'
26

37
on:
48
push:
5-
branches:
6-
- 'main'
7-
89
pull_request:
9-
types:
10-
- opened
11-
- edited
12-
- reopened
13-
- synchronize
14-
branches:
15-
- 'main'
1610

1711
jobs:
1812
verify-format:
1913
runs-on: ubuntu-latest
2014
steps:
15+
- name: Install clang
16+
working-directory: /opt
17+
run: |
18+
sudo apt-get remove --purge man-db -y # skips the mandb triggers
19+
sudo apt-get update
20+
sudo apt-get install -y --no-install-recommends clang
2121
- name: Checkout code
2222
uses: actions/checkout@v4
2323
with:
@@ -33,21 +33,37 @@ jobs:
3333
libraries/**/*.{c,cpp,h,hpp}
3434
files_ignore: |
3535
cores/arduino/api/**
36-
loader/llext_exports.c
3736
loader/blobs/4343WA1_*.c
3837
loader/blobs/wifi_nvram_image.h
3938
libraries/examples/**
4039
libraries/extras/**
4140
libraries/ea_malloc/**
4241
json: true
43-
- name: Export changed files in a text file, one per line
42+
- name: Run clang-format checks
43+
id: clang-format
4444
if: steps.changed-files.outputs.any_changed == 'true'
45+
env:
46+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
PR_NUMBER: ${{ github.event.pull_request.number }}
4548
run: |
4649
echo ${{ steps.changed-files.outputs.all_changed_files }} | jq -r '.[]' > all_changed_files.txt
4750
cat all_changed_files.txt
48-
- name: Run clang-format check
49-
if: steps.changed-files.outputs.any_changed == 'true'
50-
uses: pillo79/clang-format-action@05f671e71f0758aba4d3c9dbb0ee81bc5f0137c6
51-
with:
52-
clang-format-version: '19'
53-
check-files-from: all_changed_files.txt
51+
if ./extra/ci_clang_check.sh -f all_changed_files.txt ; then
52+
echo 'FORMATTING_ISSUES=false' >> $GITHUB_ENV
53+
else
54+
echo 'FORMATTING_ISSUES=true' >> $GITHUB_ENV
55+
fi
56+
57+
- name: Post review comments on PRs
58+
if: always() && github.event_name == 'pull_request' && steps.changed-files.outputs.any_changed == 'true'
59+
env:
60+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
PR_NUMBER: ${{ github.event.pull_request.number }}
62+
run: |
63+
if $FORMATTING_ISSUES ; then
64+
gh pr review $PR_NUMBER --request-changes --body "Please address the formatting issues highlighted in the review comments."
65+
else
66+
if gh pr view $PR_NUMBER --json latestReviews --jq '.latestReviews | map(select(.author == "ArduinoBot")) | map(select(.state == "REQUEST_CHANGES")) | length == 1' | grep -q '1' ; then
67+
gh pr review $PR_NUMBER --approve --body "Formatting issues have been resolved, thanks!"
68+
fi
69+
fi

extra/ci_clang_check.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright ARDUINO SRL
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# parse arguments
7+
while getopts "p:f:o:r:e:i:" opt; do
8+
case $opt in
9+
p) CHECK_PATH="$OPTARG" ;;
10+
f) CHECK_FILES_FROM="$OPTARG" ;;
11+
e) EXCLUDE_REGEX="$OPTARG" ;;
12+
i) INCLUDE_REGEX="$OPTARG" ;;
13+
*) echo "Invalid option: -$OPTARG" >&2 ; exit 1 ;;
14+
esac
15+
done
16+
17+
if [[ -z "$CHECK_FILES_FROM" ]] && [[ -z "$CHECK_PATH" ]]; then
18+
echo "No source input provided. Fallback to all files." >&2
19+
CHECK_PATH="."
20+
elif [[ -f "$CHECK_FILES_FROM" ]]; then
21+
echo "Checking files listed in 'check-files-from'." >&2
22+
elif [[ ! -z "$CHECK_PATH" ]] && [[ -d "$CHECK_PATH" ]]; then
23+
echo "Checking directory specified by 'check-path'." >&2
24+
else
25+
echo "::warning::Invalid inputs provided. Fallback to all files." >&2
26+
CHECK_FILES_FROM=""
27+
CHECK_PATH="."
28+
fi
29+
30+
# Set the regex to an empty string regex if nothing was provided
31+
if [[ -z $EXCLUDE_REGEX ]]; then
32+
EXCLUDE_REGEX="^$"
33+
fi
34+
35+
# Set the filetype regex if nothing was provided.
36+
# Find all C/C++/Protobuf/CUDA files:
37+
# h, H, hpp, hh, h++, hxx
38+
# c, C, cpp, cc, c++, cxx
39+
# ino, pde
40+
# proto
41+
# cu
42+
if [[ -z $INCLUDE_REGEX ]]; then
43+
INCLUDE_REGEX='^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$))|(ino|pde|proto|cu))$'
44+
fi
45+
46+
cd "$GITHUB_WORKSPACE" || exit 2
47+
48+
exit_code=0
49+
if [[ -f "$CHECK_FILES_FROM" ]]; then
50+
# Use the provided list of files to check.
51+
src_files=$(grep -E "$INCLUDE_REGEX" "$CHECK_FILES_FROM")
52+
else
53+
# Find all source files in the provided path, excluding .git directories.
54+
src_files=$(find "$CHECK_PATH" -name .git -prune -o -regextype posix-egrep -regex "$INCLUDE_REGEX" -print)
55+
fi
56+
57+
HEAD_SHA=$(git rev-parse $GITHUB_HEAD_REF)
58+
59+
intro_out=false
60+
IFS=$'\n' # Loop below should separate on new lines, not spaces.
61+
for file in $src_files; do
62+
# Only check formatting if the path doesn't match the regex
63+
if ! [[ ${file} =~ $EXCLUDE_REGEX ]]; then
64+
clang-format -i -style=file "${file}" 2>&1
65+
changes=$(git diff -U0 ${file})
66+
[ -z "$changes" ] && continue
67+
68+
exit_code=1
69+
70+
git diff --color=always ${file}
71+
72+
echo "$changes" | while IFS= read -r line ; do
73+
# match file and line numbers in the diff output and provide Github Actions annotations
74+
if [[ $line =~ ^@@\ -([0-9]+),?([0-9]*)\ \+([0-9]+),?([0-9]*)\ @@ ]]; then
75+
# Extract the line numbers from the diff output
76+
git_start_line=${BASH_REMATCH[1]}
77+
git_line_count=${BASH_REMATCH[2]:-1}
78+
fix_start_line=${BASH_REMATCH[3]}
79+
fix_line_count=${BASH_REMATCH[4]:-1}
80+
81+
git_end_line=$((git_start_line + git_line_count - 1))
82+
83+
echo "::warning file=${file},line=${git_start_line},endLine=${git_end_line}::Fix code formatting"
84+
fi
85+
done
86+
fi
87+
done
88+
89+
exit $exit_code

loader/llext_exports.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <zephyr/kernel.h>
1010

1111
#define FORCE_EXPORT_SYM(name) \
12-
extern void name(void); \
13-
EXPORT_SYMBOL(name);
12+
extern void name(void); \
13+
EXPORT_SYMBOL(name);
1414

1515
/*
1616
* Libc functions are exported with a __real_ prefix so that the sketch
@@ -26,6 +26,7 @@ EXPORT_LIBC_SYM(memmove);
2626
EXPORT_LIBC_SYM(strrchr);
2727
EXPORT_LIBC_SYM(strstr);
2828
EXPORT_LIBC_SYM(strncmp);
29+
2930
EXPORT_LIBC_SYM(strncpy);
3031
EXPORT_LIBC_SYM(strcasecmp);
3132
EXPORT_LIBC_SYM(strcmp);

0 commit comments

Comments
 (0)