Skip to content

Updates to Uncrustify Formatting #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
formatting/filesWithCRLFEndings/* eol=crlf
clang-formatting/filesWithFormattingErrors/* eol=crlf
295 changes: 295 additions & 0 deletions .github/workflows/formattingTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
name: Formatting Tests

on:
push:
branches: ["**"]
pull_request:
branches: [main,v2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this branch always exist?

workflow_dispatch:

env:
# The bash escape character is \033
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m

jobs:
uncrustify-formatting-success-cases:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- env:
stepName: "Functional | Success | Exclude Files and Dirs"
name: ${{ env.stepName }}
id: exclude-dirs-with-errors
uses: ./formatting
with:
path: formatting/goodFiles
exclude-dirs: "fileWithErrorInclude, fileWithErrorSource"
exclude-files: "formatErrorTest.h, formatErrorTest.c"

- env:
stepName: "Functional | Success | Exclude Just Files"
name: ${{ env.stepName }}
id: exclude-files-with-errors
uses: ./formatting
with:
path: formatting/goodFiles
exclude-dirs: ",,,"
exclude-files: "errorFileInDirectory.h, formatErrorTest.h, errorFileInDirectory.c, formatErrorTest.c"

- name: Remove Error Files at Top Directory
working-directory: formatting/goodFiles
shell: bash
run: |
# Remove Error Files at Top Directory
# Do a git remove since we use a git diff to check if formatting fails
git rm $(find . -name "formatErrorTest.c")
git rm $(find . -name "formatErrorTest.h")

- env:
stepName: "Functional | Success | Exclude Just Error Dirs"
name: ${{ env.stepName }}
id: exclude-two-files-two-dirs
uses: ./formatting
with:
path: formatting/goodFiles
exclude-dirs: "fileWithErrorInclude, fileWithErrorSource"

formatting-error-cases:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- env:
stepName: "Functional | Failure | Whitespace, CRLF, and Format Failure"
name: ${{ env.stepName }}
id: all-format-errors
continue-on-error: true
uses: ./formatting
with:
path: formatting

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "Functional | Failure | CRLF and Formatting Error"
name: ${{ env.stepName }}
id: crlf-and-format-error
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-dirs: "filesWithTrailingWhitespace"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "Functional | Failure | CRLF and Whitespace Error"
name: ${{ env.stepName }}
id: crlf-and-whitespace-error
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-dirs: "filesWithFormattingErrors"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "Functional | Failure | CRLF and Whitespace Error Not C Files"
name: ${{ env.stepName }}
id: crlf-and-whitespace-non-c-error
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-dirs: "filesWithFormattingErrors, fileWithErrorInclude, fileWithErrorSource"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "Functional | Failure | CRLF Error"
name: ${{ env.stepName }}
id: crlf-error
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-dirs: "filesWithFormattingErrors,filesWithTrailingWhitespace"
exclude-files: "badFile.c"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "Functional | Failure | Formatting and Whitespace Error"
name: ${{ env.stepName }}
id: formatting-and-whitespace-error
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-dirs: "filesWithCRLFEndings"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "Functional | Failure | Formatting Error"
name: ${{ env.stepName }}
id: formatting-error
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-dirs: "filesWithTrailingWhitespace,filesWithCRLFEndings"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "Functional | Failure | Whitespace Error"
name: ${{ env.stepName }}
id: whitespace-error
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-dirs: "filesWithFormattingErrors,filesWithCRLFEndings"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "API | Failure | Exclude Dirs Error"
name: ${{ env.stepName }}
id: error-in-exclude-dirs
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-dirs: "filesWithFormattingErrors, filesWithCRLFEndings"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "API | Failure | Exclude Files Error"
name: ${{ env.stepName }}
id: error-in-exclude-files
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-files: "filesWithFormattingErrors, filesWithCRLFEndings"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: "API | Failure | Exclude Option Errors"
name: ${{ env.stepName }}
id: error-in-both
continue-on-error: true
uses: ./formatting
with:
path: formatting
exclude-files: "filesWithFormattingErrors, filesWithCRLFEndings"
exclude-dirs: "filesWithFormattingErrors,
filesWithCRLFEndings"

- name: Reset Files
shell: bash
run: git reset --hard

- env:
stepName: Check Failure Test Cases
name: ${{ env.stepName }}
id: check-failure-test-cases
shell: bash
run: |
# ${{ env.stepName }}
exitStatus=0
if [ "${{ steps.all-format-errors.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | Whitespace, CRLF, and Format Failure | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | Whitespace, CRLF, and Format Failure | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.crlf-and-format-error.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | CRLF and Formatting Error | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | CRLF and Formatting Error | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.crlf-and-whitespace-error.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | CRLF and Whitespace Error | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | CRLF and Whitespace Error | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.crlf-and-whitespace-non-c-error.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | CRLF and Whitespace Error Not C Files | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | CRLF and Whitespace Error Not C Files | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.crlf-error.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | CRLF Error | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | CRLF Error | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.formatting-and-whitespace-error.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | Formatting and Whitespace Error | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | Formatting and Whitespace Error | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.formatting-error.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | Formatting Error | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | Formatting Error | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.whitespace-error.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | Whitespace Error | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | Whitespace Error | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.error-in-exclude-dirs.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} API | Failure | Exclude Dirs Error | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} API | Failure | Exclude Dirs Error | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.error-in-exclude-files.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} API | Failure | Exclude Files Error | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} API | Failure | Exclude Files Error | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
if [ "${{ steps.error-in-both.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} API | Failure | Exclude Option Errors | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} API | Failure | Exclude Option Errors | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
exit $exitStatus
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
test-format-check:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
repository: FreeRTOS/coreMQTT
ref: main
repository: Skptak/coreMQTT
ref: CI-CD-Updates
path: coreMQTT
- name: Test formatting check action
uses: ./formatting
Expand Down
29 changes: 29 additions & 0 deletions formatting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Uncrustify Format GitHub Action
## Purpose
This directory contains an [action.yml](action.yml) file to uncrustify code
files inside of [FreeRTOS](https://github.com/FreeRTOS/) repositories. It
additionally will check for files with trailing whitespace, and CRLF line
endings.

If a file is found that contains incorrect formatting, trailing whitespace, or
CRLF endings, this action will create a Git Patch that will be added to the
summary of the workflow run that uses this action. This allows an end user to
download the patch, apply it, and then pass the formatting checks.

A patch is provided, instead of automatically applying the updates, as
automatically formatting files could lead to merge conflicts. If an end-user
didn't know they need to perform a `git pull` as their origin would have the
formatting change applied.

## Testing Files
This directory contains many files that are used to test the action.
These tests can be found inside of
[formattingTests.yml](../.github/workflows/formattingTests.yml).
The files have been named in such a way to explain what their purpose is.
The general idea is that there are a mix of files, some with CRLF endings,
some with uncrustify errors, and some with trailing whitespace. Where the
inside of
[formattingTests.yml](../.github/workflows/formattingTests.yml)
these various files are checked to ensure this action properly fails when
a formatting issue is discovered. Additional tests are here to ensure that
the various input parameters to the action work as intended.
Loading