mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
Merge pull request #2842 from openmv/update_code_formatter
misc: Update code formatter.
This commit is contained in:
commit
0de60ff3d5
55
.github/workflows/codeformat.yml
vendored
55
.github/workflows/codeformat.yml
vendored
@ -15,6 +15,7 @@ on:
|
||||
- synchronize
|
||||
branches:
|
||||
- 'master'
|
||||
- 'update_code_formatter'
|
||||
paths:
|
||||
- '**/*.{c,cc,h}'
|
||||
|
||||
@ -28,41 +29,21 @@ jobs:
|
||||
submodules: false
|
||||
persist-credentials: false
|
||||
|
||||
- name: '♻ Caching dependencies'
|
||||
uses: actions/cache@v4.2.0
|
||||
id: cache
|
||||
with:
|
||||
path: ~/cache/deps/bin
|
||||
key: 'uncrustify'
|
||||
|
||||
- name: '🛠 Install dependencies'
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
run: source tools/ci.sh && ci_install_code_format_deps
|
||||
|
||||
- name: '📜 Get list of changed files'
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@v46
|
||||
with:
|
||||
files: |
|
||||
**/*.{c,cc,h}
|
||||
!cubeai/**
|
||||
!docker/**
|
||||
!docs/**
|
||||
!drivers/**
|
||||
drivers/sensors/*.{c,cc,h}
|
||||
!lib/**
|
||||
lib/imlib/*.{c,cc,h}
|
||||
lib/tflm/*.{c,cc,h}
|
||||
!scripts/**
|
||||
!tools/**
|
||||
|
||||
- name: '📜 Show list of changed files'
|
||||
run: |
|
||||
echo "${{ toJSON(steps.changed-files.outputs) }}"
|
||||
shell:
|
||||
bash
|
||||
|
||||
- name: '🔎 Check code formatting'
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
run: |
|
||||
source tools/ci.sh && ci_run_code_format_check ${{ steps.changed-files.outputs.all_changed_files }}
|
||||
uses: openmv/uncrustify-action@v1
|
||||
with:
|
||||
config-path: 'tools/uncrustify.cfg'
|
||||
extensions: 'c,cc,h'
|
||||
exclude-patterns: |
|
||||
cubeai/**
|
||||
docker/**
|
||||
docs/**
|
||||
drivers/**
|
||||
!drivers/sensors/**
|
||||
lib/**
|
||||
!lib/imlib/**
|
||||
!lib/tflm/**
|
||||
scripts/**
|
||||
tools/**
|
||||
uncrustify-version: '0.75.0'
|
||||
fail-on-error: 'true'
|
||||
|
39
tools/ci.sh
39
tools/ci.sh
@ -75,45 +75,6 @@ ci_package_firmware_development() {
|
||||
(cd firmware && for i in *; do zip -r -j "firmware_${i%/}.zip" "$i"; done)
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
# Install code formatter deps
|
||||
CODEFORMAT_PATH=${HOME}/cache/deps/
|
||||
UNCRUSTIFY_PATH=${CODEFORMAT_PATH}/uncrustify
|
||||
UNCRUSTIFY_URL="https://github.com/uncrustify/uncrustify/archive/uncrustify-0.75.0.tar.gz"
|
||||
|
||||
ci_install_code_format_deps() {
|
||||
sudo apt-get install wget cmake build-essential colordiff
|
||||
|
||||
mkdir -p ${UNCRUSTIFY_PATH}
|
||||
wget --no-check-certificate -O - ${UNCRUSTIFY_URL} | tar xvz --strip-components=1 -C ${UNCRUSTIFY_PATH}
|
||||
(cd ${UNCRUSTIFY_PATH} && mkdir build && cd build && cmake .. && cmake --build .)
|
||||
|
||||
# Copy binaries to cache
|
||||
mkdir -p ${CODEFORMAT_PATH}/bin
|
||||
cp ${UNCRUSTIFY_PATH}/build/uncrustify ${CODEFORMAT_PATH}/bin/
|
||||
cp `which colordiff` ${CODEFORMAT_PATH}/bin/
|
||||
chmod +x ${CODEFORMAT_PATH}/bin/uncrustify
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
# Run code formatter
|
||||
ci_run_code_format_check() {
|
||||
export PATH=${CODEFORMAT_PATH}/bin:${PATH}
|
||||
UNCRUSTIFY_CONFIG=tools/uncrustify.cfg
|
||||
|
||||
exit_code=0
|
||||
for file in "$@"; do
|
||||
file_fmt="${file}.tmp"
|
||||
uncrustify -q -c ${UNCRUSTIFY_CONFIG} -f ${file} -o ${file_fmt} || true
|
||||
|
||||
diff -q -u ${file} ${file_fmt} >> /dev/null 2>&1 || {
|
||||
colordiff -u ${file} ${file_fmt} || true
|
||||
exit_code=1
|
||||
}
|
||||
done
|
||||
exit $exit_code
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
# Install STEdgeAI tools
|
||||
STEDGEAI_URL="https://upload.openmv.io/stedgeai/STEdgeAI-2.1.0.tar.gz"
|
||||
|
Loading…
Reference in New Issue
Block a user