diff --git a/Dockerfile b/Dockerfile index e34cf12..987f2d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ COPY entrypoint.sh /entrypoint.sh COPY default.cfg /default.cfg RUN apt-get update -RUN apt-get -y install curl cmake build-essential python3 git +RUN apt-get -y install curl cmake build-essential python3 git colordiff RUN chmod +x entrypoint.sh RUN curl -L -o uncrustify-0.70.1.tar.gz https://github.com/uncrustify/uncrustify/archive/uncrustify-0.70.1.tar.gz RUN tar -xzf uncrustify-0.70.1.tar.gz diff --git a/README.md b/README.md index 7df3234..443b6c2 100644 --- a/README.md +++ b/README.md @@ -41,21 +41,4 @@ jobs: uses: coleaeason/actions-uncrustify@v1 with: configPath: 'myConfig.cfg' -``` - -Checks for usaged of `std::`: -```yml -on: [ pull_request ] - -jobs: - cpp_style_check: - runs-on: ubuntu-latest - name: Check C++ Style - steps: - - name: Checkout this commit - uses: actions/checkout@v2 - - name: Run style checks - uses: coleaeason/actions-uncrustify@v1 - with: - checkSTD: 'true' ``` \ No newline at end of file diff --git a/action.yml b/action.yml index 6f64135..268a166 100644 --- a/action.yml +++ b/action.yml @@ -5,9 +5,6 @@ inputs: configPath: description: 'Alternate configuration file to use' required: false - checkSTD: - description: 'Whether or not files should be checked for std:: usage' - required: false runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index abf990d..a6e06d1 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -29,7 +29,7 @@ fi EXIT_VAL=0 while read -r FILENAME; do - FAILED="false" + TMPFILE="${FILENAME}.tmp" # Failure is passed to stderr so we need to redirect that to grep so we can pretty print some useful output instead of the deafult # Success is passed to stdout, so we need to redirect that separately so we can capture either case. @@ -43,20 +43,11 @@ while read -r FILENAME; do if [[ $RETURN_VAL -gt 0 ]]; then echo -e "${RED}${OUT} failed style checks.${RESET}" - FAILED="true" + uncrustify${CONFIG} -f ${FILENAME} -o ${TMPFILE} && colordiff -u ${FILENAME} ${TMPFILE} EXIT_VAL=$RETURN_VAL else echo -e "${GREEN}${OUT} passed style checks.${RESET}" fi - - if [[ -n "$INPUT_CHECKSTD" ]] && [[ "$INPUT_CHECKSTD" == "true" ]]; then - # Counts occurrences of std:: that aren't in comments and have a leading space (except if it's inside pointer brackets, eg: ) - RETURN_VAL=$(sed -n '/^.*\/\/.*/!s/ std:://p; /^.* std::.*\/\//s/ std:://p; /^.*\<.*std::.*\>/s/std:://p;' "${FILENAME}" | wc -l) - if [[ $RETURN_VAL -gt 0 ]] && [[ "$FAILED" != "true" ]]; then - echo -e "${RED}${OUT} failed style checks.${RESET}" - EXIT_VAL=$RETURN_VAL - fi - fi done < <(git diff --name-status --diff-filter=AM origin/master...${BRANCH_NAME} -- '*.cpp' '*.h' '*.hpp' '*.cxx' | awk '{ print $2 }' ) exit $EXIT_VAL