Skip to content

Commit 1a2513b

Browse files
authored
Merge pull request #114 from per1234/check-general-formatting
Add infrastructure to check general file formatting
2 parents cb06ac6 + af425db commit 1a2513b

File tree

12 files changed

+626
-459
lines changed

12 files changed

+626
-459
lines changed

.ecrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Exclude": [
3+
"^\\.git[/\\\\]",
4+
"^\\.licenses[/\\\\]",
5+
".pytest_cache[/\\\\]",
6+
"__pycache__[/\\\\]",
7+
"node_modules[/\\\\]",
8+
"^LICENSE\\.txt$",
9+
"^poetry\\.lock$",
10+
"\\.py$",
11+
"^compilesketches[/\\\\]tests[/\\\\]testdata[/\\\\]test_get_warning_count_from_output[/\\\\]has-warnings\\.txt$",
12+
"^compilesketches[/\\\\]tests[/\\\\]testdata[/\\\\]test_get_warning_count_from_output[/\\\\]no-warnings\\.txt$"
13+
]
14+
}

.editorconfig

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/general/.editorconfig
2+
# See: https://editorconfig.org/
3+
# The formatting style defined in this file is the official standardized style to be used in all Arduino Tooling
4+
# projects and should not be modified.
5+
# Note: indent style for each file type is defined even when it matches the universal config in order to make it clear
6+
# that this type has an official style.
7+
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
indent_size = 2
12+
indent_style = space
13+
insert_final_newline = true
14+
trim_trailing_whitespace = true
15+
16+
[*.{adoc,asc,asciidoc}]
17+
indent_size = 2
18+
indent_style = space
19+
20+
[*.{bash,sh}]
21+
indent_size = 2
22+
indent_style = space
23+
24+
[*.{c,cc,cp,cpp,cxx,h,hh,hpp,hxx,ii,inl,ino,ixx,pde,tpl,tpp,txx}]
25+
indent_size = 2
26+
indent_style = space
27+
28+
[*.{go,mod}]
29+
indent_style = tab
30+
31+
[*.java]
32+
indent_size = 2
33+
indent_style = space
34+
35+
[*.{js,jsx,json,jsonc,json5,ts,tsx}]
36+
indent_size = 2
37+
indent_style = space
38+
39+
[*.{md,mdx,mkdn,mdown,markdown}]
40+
indent_size = unset
41+
indent_style = space
42+
43+
[*.proto]
44+
indent_size = 2
45+
indent_style = space
46+
47+
[*.py]
48+
indent_size = 4
49+
indent_style = space
50+
51+
[*.svg]
52+
indent_size = 2
53+
indent_style = space
54+
55+
[*.{yaml,yml}]
56+
indent_size = 2
57+
indent_style = space
58+
59+
[{.gitconfig,.gitmodules}]
60+
indent_style = tab
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-general-formatting-task.md
2+
name: Check General Formatting
3+
4+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
5+
on:
6+
create:
7+
push:
8+
pull_request:
9+
schedule:
10+
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to tools.
11+
- cron: "0 8 * * TUE"
12+
workflow_dispatch:
13+
repository_dispatch:
14+
15+
jobs:
16+
run-determination:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
result: ${{ steps.determination.outputs.result }}
20+
steps:
21+
- name: Determine if the rest of the workflow should run
22+
id: determination
23+
run: |
24+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
25+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
26+
if [[
27+
"${{ github.event_name }}" != "create" ||
28+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
29+
]]; then
30+
# Run the other jobs.
31+
RESULT="true"
32+
else
33+
# There is no need to run the other jobs.
34+
RESULT="false"
35+
fi
36+
37+
echo "result=$RESULT" >> $GITHUB_OUTPUT
38+
39+
check:
40+
needs: run-determination
41+
if: needs.run-determination.outputs.result == 'true'
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- name: Set environment variables
46+
run: |
47+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
48+
echo "EC_INSTALL_PATH=${{ runner.temp }}/editorconfig-checker" >> "$GITHUB_ENV"
49+
50+
- name: Checkout repository
51+
uses: actions/checkout@v3
52+
53+
- name: Install Task
54+
uses: arduino/setup-task@v1
55+
with:
56+
repo-token: ${{ secrets.GITHUB_TOKEN }}
57+
version: 3.x
58+
59+
- name: Download latest editorconfig-checker release binary package
60+
id: download
61+
uses: MrOctopus/download-asset-action@1.0
62+
with:
63+
repository: editorconfig-checker/editorconfig-checker
64+
excludes: prerelease, draft
65+
asset: linux-amd64.tar.gz
66+
target: ${{ env.EC_INSTALL_PATH }}
67+
68+
- name: Install editorconfig-checker
69+
run: |
70+
cd "${{ env.EC_INSTALL_PATH }}"
71+
tar --extract --file="${{ steps.download.outputs.name }}"
72+
# Give the binary a standard name
73+
mv "${{ env.EC_INSTALL_PATH }}/bin/ec-linux-amd64" "${{ env.EC_INSTALL_PATH }}/bin/ec"
74+
# Add installation to PATH:
75+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
76+
echo "${{ env.EC_INSTALL_PATH }}/bin" >> "$GITHUB_PATH"
77+
78+
- name: Check formatting
79+
run: task --silent general:check-formatting

.github/workflows/testdata/reports/all-inputs/arduino-avr-uno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,4 @@
193193
}
194194
}
195195
]
196-
}
196+
}

.github/workflows/testdata/reports/all-inputs/esp8266-esp8266-huzzah.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,4 @@
193193
}
194194
}
195195
]
196-
}
196+
}

LICENSE renamed to LICENSE.txt

File renamed without changes.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Check Action Metadata status](https://github.com/arduino/compile-sketches/actions/workflows/check-action-metadata-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-action-metadata-task.yml)
44
[![Check Files status](https://github.com/arduino/compile-sketches/actions/workflows/check-files-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-files-task.yml)
5+
[![Check General Formatting status](https://github.com/arduino/compile-sketches/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-general-formatting-task.yml)
56
[![Check Python status](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml)
67
[![Spell Check status](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml)
78
[![Sync Labels status](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml)

Taskfile.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tasks:
99
desc: Check for problems with the project
1010
deps:
1111
- task: action:validate
12+
- task: general:check-formatting
1213
- task: general:check-spelling
1314
- task: python:lint
1415
- task: python:test
@@ -111,6 +112,18 @@ tasks:
111112
false
112113
}
113114
115+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml
116+
general:check-formatting:
117+
desc: Check basic formatting style of all files
118+
cmds:
119+
- |
120+
if ! which ec &>/dev/null; then
121+
echo "ec not found or not in PATH."
122+
echo "Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation"
123+
exit 1
124+
fi
125+
- ec
126+
114127
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
115128
general:check-spelling:
116129
desc: Check for commonly misspelled words

0 commit comments

Comments
 (0)