forked from FreeRTOS/CI-CD-Github-Actions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swap to the clang-formatting directory for now. Update the files to b…
…e smaller for the tests, minor changes to the action file. Add a README explaining the action and directory layout
- Loading branch information
Showing
49 changed files
with
1,274 additions
and
63,613 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Clang-Format GithubAction | ||
## Purpose | ||
This directory contains an [action.yml](action.yml) file to clang-format 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 clang-format 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
name: 'formatting' | ||
description: 'CI formatting check' | ||
inputs: | ||
path: | ||
description: 'Path to repository folder to run formatting check for. ' | ||
required: false | ||
default: ./ | ||
exclude-files: | ||
description: 'List of comma-separated files to exclude from the formatting check. Eg file1, file2' | ||
required: false | ||
default: '' | ||
exclude-dirs: | ||
description: 'List of comma-separated directories to exclude from the formatting check. Eg docs, build' | ||
required: false | ||
default: '' | ||
include-extensions: | ||
description: 'List of comma-separated extensions to add to the formatting check. Eg md, dox' | ||
required: false | ||
default: '' | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- env: | ||
# At time of writing, you can't add a global environment | ||
# to an action file so stuck with this. If this gets changed | ||
# Please move this | ||
bashPass: \033[32;1mPASSED - | ||
bashInfo: \033[33;1mINFO - | ||
bashFail: \033[31;1mFAILED - | ||
bashEnd: \033[0m | ||
stepName: Install Clang Format | ||
name: ${{ env.stepName }} | ||
shell: bash | ||
run: | | ||
# ${{ env.stepName }} | ||
echo -e "::group::${{ env.stepName }}" | ||
sudo apt-get install clang-format fd-find dos2unix | ||
echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH | ||
export PATH="$PATH:$GITHUB_ACTION_PATH" | ||
fdfind --version | ||
fdInstalled=$? | ||
clang-format --version | ||
clangFormatInstalled=$? | ||
echo -e "::endgroup::" | ||
if [ $clangFormatInstalled -eq 1 ] || [ $fdInstalled -eq 1 ]; then | ||
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}" | ||
exit 1 | ||
else | ||
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" | ||
exit 0 | ||
fi | ||
- env: | ||
bashPass: \033[32;1mPASSED - | ||
bashInfo: \033[33;1mINFO - | ||
bashFail: \033[31;1mFAILED - | ||
bashEnd: \033[0m | ||
stepName: Formatting Check | ||
name: ${{ env.stepName }} | ||
id: action-formatting-check | ||
if: ${{ steps.validate-inputs.outcome}} = "success" | ||
working-directory: ${{ inputs.path }} | ||
shell: bash | ||
run: | | ||
# ${{ env.stepName }} | ||
echo -e "${{ env.bashInfo }} Using clang-format version "$(clang-format --version)" ${{ env.bashEnd }}" | ||
exitCode=0 | ||
export PATH="$PATH:$GITHUB_ACTION_PATH" | ||
# TODO: These checks should really only run against modified files on PRS | ||
# Where when the commit to the actual repo happens, then we should trigger the job | ||
# Against all of the files in the repo. Nice inbetween to keep checks fast for PRs, | ||
# But maintain that we don't have a change in the Repo that suddenly causes an issue | ||
# Parse the optional inputs | ||
args="" | ||
# fd-find uses -E to exclude a file or directory | ||
if [ -n "${{ inputs.exclude-dirs }}" ]; then | ||
dirs=" -E " | ||
dirs+="${{ inputs.exclude-dirs }}" | ||
dirs="${dirs//,/ -E }" | ||
args+=" ${dirs}" | ||
fi | ||
# fd-find uses -E to exclude a file or directory | ||
if [ -n "${{ inputs.exclude-files }}" ]; then | ||
files=" -E " | ||
files+="${{ inputs.exclude-files }}" | ||
files="${files//,/ -E }" | ||
args+=" ${files}" | ||
fi | ||
# fd-find uses -e to include a file extension | ||
if [ -n "${{ inputs.include-file-types }}" ]; then | ||
file_types=" -e " | ||
file_types+="${{ inputs.include-file-types }}" | ||
file_types="${file_types//,/ -e }" | ||
args+=" ${file_types}" | ||
fi | ||
# Get all .c and .h files, as well as any other requested file types. | ||
# Then run clang-format with the common config file. | ||
echo -e "::group::${{ env.bashInfo }} Check Formatting ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} Running: fdfind -e c -e h ${args} --exec clang-format -i ${{ env.bashEnd }}" | ||
fdfind -e c -e h ${args} --exec clang-format --verbose -i | ||
# Replace all trailing whitespace, exclude photo files | ||
echo -e "::group::${{ env.bashInfo }} Check for Trailing Whitespace ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} Running: fdfind --type=file -E '*.png' -E '*.jpg' -E '*.svg' -E '.a' -E '.lib' ${args} . --exec sed -Ei 's/[[:blank:]]+$//' ${{ env.bashEnd }}" | ||
fdfind --type=file -E '*.png' -E '*.jpg' -E '*.svg' -E '.a' -E '.lib' ${args} . --exec sed -Ei 's/[[:blank:]]+$//' | ||
# Replace all line endings with LF ones instead of CRLF | ||
echo -e "::group::${{ env.bashInfo }} Check for CRLF Line Endings ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} Running: fdfind --type=file ${args} . --exec dos2unix ${{ env.bashEnd }}" | ||
fdfind --type=file ${args} . --exec dos2unix | ||
# Determine if there was a formatting diff. | ||
# If there was, create a patch of it. | ||
set +e | ||
git diff --exit-code >> formattingChanges.patch | ||
exitCode=$? | ||
set -e | ||
if [ $exitCode -eq 0 ]; then | ||
echo -e "::endgroup::" | ||
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" | ||
else | ||
# Run a git diff to print the formatting differences | ||
echo -e "::group::${{ env.bashInfo }} Format Difference ${{ env.bashEnd }}" | ||
git diff --color=always | ||
echo -e "::endgroup::${{ env.bashFail }} List of files with formatting errors: ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashFail }} "$(git diff --name-only)" ${{ env.bashEnd }} " | ||
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}" | ||
fi | ||
exit $exitCode | ||
- name: Upload Formatting Git Patch | ||
if: failure() && ( steps.action-formatting-check.outcome == 'failure' ) | ||
id: upload-formatting-patch | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: formattingChanges | ||
path: ${{ inputs.path }}/formattingChanges.patch | ||
retention-days: 7 | ||
|
||
- env: | ||
stepName: Formatting Git Patch Info | ||
bashPass: \033[32;1m | ||
bashInfo: \033[33;1m | ||
bashFail: \033[31;1m | ||
bashEnd: \033[0 | ||
if: failure() && ( steps.upload-formatting-patch.outcome == 'success' ) | ||
shell: bash | ||
run: | | ||
# ${{ env.stepName }} | ||
echo -e "${{ env.bashInfo }} A git patch of the formatting issues has been attached to this workflow ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} This can be accessed by returning to the bottom of the summary page of the workflow run ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} At the bottom of the page will be a formattingChanges.patch file that you can download ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} Copy this patch to your repository and apply it using 'git apply formattingChanges.patch' ${{ env.bashEnd }}" |
92 changes: 46 additions & 46 deletions
92
formatting/filesWithCRLFEndings/cgc_error.h → ...filesWithCRLFEndings/fileWithCRLFEnding.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
#ifndef CGC_ERROR_H_ | ||
#define CGC_ERROR_H_ | ||
|
||
/* Error checking macros for the clock selction and clock enable defines */ | ||
|
||
#if ( (CLK_SOURCE != CLK_SOURCE_LOCO) && \ | ||
(CLK_SOURCE != CLK_SOURCE_HOCO) && \ | ||
(CLK_SOURCE != CLK_SOURCE_MAIN) && \ | ||
(CLK_SOURCE != CLK_SOURCE_SUB) && \ | ||
(CLK_SOURCE != CLK_SOURCE_PLL) ) | ||
#error "No CLK_SOURCE specified. Please specify a valid CLK_SOURCE"; | ||
#endif | ||
|
||
|
||
#if (CLK_SOURCE == CLK_SOURCE_HOCO) && (ENABLE_HOCO == 0) | ||
#error "HOCO has been specified as the CLK_SOURCE but ENABLE_HOCO is (0). Please set to (1) in file cgc.h" | ||
#endif | ||
|
||
#if (CLK_SOURCE == CLK_SOURCE_MAIN) && (ENABLE_MAIN == 0) | ||
#error "HOCO has been specified as the CLK_SOURCE but ENABLE_HOCO is (0). Please set to (1) in file cgc.h" | ||
#endif | ||
|
||
#if (CLK_SOURCE == CLK_SOURCE_SUB) && (ENABLE_SUB == 0) | ||
#error "HOCO has been specified as the CLK_SOURCE but ENABLE_HOCO is (0). Please set to (1) in file cgc.h" | ||
#endif | ||
|
||
#if (CLK_SOURCE == CLK_SOURCE_PLL) && (ENABLE_PLL == 0) | ||
#error "PLL has been specified as the CLK_SOURCE but ENABLE_PLL is (0). Please set to (1) in file cgc.h" | ||
#endif | ||
|
||
#if ( FCLK_FREQUENCY > 50000000L ) | ||
#error "FCLK_FREQUENCY Error: Please enter a valid divider value" | ||
#endif | ||
|
||
#if ( ICLK_FREQUENCY > 100000000L ) | ||
#error "ICLK_FREQUENCY Error: Please enter a valid divider value" | ||
#endif | ||
|
||
#if ( BCLK_FREQUENCY > 100000000L ) | ||
#error "BCLK_FREQUENCY Error: Please enter a valid divider value" | ||
#endif | ||
|
||
#if ( PCLKB_FREQUENCY > 50000000L ) | ||
#error "PCLKB_FREQUENCY Error: Please enter a valid divider value" | ||
#endif | ||
|
||
#ifndef CGC_ERROR_H_ | ||
#define CGC_ERROR_H_ | ||
|
||
/* Error checking macros for the clock selction and clock enable defines */ | ||
|
||
#if ( (CLK_SOURCE != CLK_SOURCE_LOCO) && \ | ||
(CLK_SOURCE != CLK_SOURCE_HOCO) && \ | ||
(CLK_SOURCE != CLK_SOURCE_MAIN) && \ | ||
(CLK_SOURCE != CLK_SOURCE_SUB) && \ | ||
(CLK_SOURCE != CLK_SOURCE_PLL) ) | ||
#error "No CLK_SOURCE specified. Please specify a valid CLK_SOURCE"; | ||
#endif | ||
|
||
|
||
#if (CLK_SOURCE == CLK_SOURCE_HOCO) && (ENABLE_HOCO == 0) | ||
#error "HOCO has been specified as the CLK_SOURCE but ENABLE_HOCO is (0). Please set to (1) in file cgc.h" | ||
#endif | ||
|
||
#if (CLK_SOURCE == CLK_SOURCE_MAIN) && (ENABLE_MAIN == 0) | ||
#error "HOCO has been specified as the CLK_SOURCE but ENABLE_HOCO is (0). Please set to (1) in file cgc.h" | ||
#endif | ||
|
||
#if (CLK_SOURCE == CLK_SOURCE_SUB) && (ENABLE_SUB == 0) | ||
#error "HOCO has been specified as the CLK_SOURCE but ENABLE_HOCO is (0). Please set to (1) in file cgc.h" | ||
#endif | ||
|
||
#if (CLK_SOURCE == CLK_SOURCE_PLL) && (ENABLE_PLL == 0) | ||
#error "PLL has been specified as the CLK_SOURCE but ENABLE_PLL is (0). Please set to (1) in file cgc.h" | ||
#endif | ||
|
||
#if ( FCLK_FREQUENCY > 50000000L ) | ||
#error "FCLK_FREQUENCY Error: Please enter a valid divider value" | ||
#endif | ||
|
||
#if ( ICLK_FREQUENCY > 100000000L ) | ||
#error "ICLK_FREQUENCY Error: Please enter a valid divider value" | ||
#endif | ||
|
||
#if ( BCLK_FREQUENCY > 100000000L ) | ||
#error "BCLK_FREQUENCY Error: Please enter a valid divider value" | ||
#endif | ||
|
||
#if ( PCLKB_FREQUENCY > 50000000L ) | ||
#error "PCLKB_FREQUENCY Error: Please enter a valid divider value" | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.