Skip to content

Commit 35a7bfa

Browse files
committed
Add CI workflow to check general file formatting
On every push, pull request, and periodically, check whether the repository's files are formatted according to .editorconfig.
1 parent 74215a2 commit 35a7bfa

File tree

6 files changed

+139
-1
lines changed

6 files changed

+139
-1
lines changed

.ecrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Exclude": [
3+
"^\\.git[/\\\\]",
4+
"^\\.licenses[/\\\\]",
5+
"__pycache__[/\\\\]",
6+
"internal[/\\\\]libraries[/\\\\]testdata[/\\\\]libraries[/\\\\]",
7+
"node_modules[/\\\\]",
8+
"tests[/\\\\]testdata[/\\\\]",
9+
"^LICENSE\\.txt$",
10+
"^poetry\\.lock$"
11+
]
12+
}

.editorconfig

+60
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
pull_request:
8+
schedule:
9+
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to tools.
10+
- cron: "0 8 * * TUE"
11+
workflow_dispatch:
12+
repository_dispatch:
13+
14+
jobs:
15+
check:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Set environment variables
20+
run: |
21+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
22+
echo "EC_INSTALL_PATH=${{ runner.temp }}/editorconfig-checker" >> "$GITHUB_ENV"
23+
24+
- name: Checkout repository
25+
uses: actions/checkout@v3
26+
27+
- name: Install Task
28+
uses: arduino/setup-task@v1
29+
with:
30+
repo-token: ${{ secrets.GITHUB_TOKEN }}
31+
version: 3.x
32+
33+
- name: Download latest editorconfig-checker release binary package
34+
id: download
35+
uses: MrOctopus/[email protected]
36+
with:
37+
repository: editorconfig-checker/editorconfig-checker
38+
excludes: prerelease, draft
39+
asset: linux-amd64.tar.gz
40+
target: ${{ env.EC_INSTALL_PATH }}
41+
42+
- name: Install editorconfig-checker
43+
run: |
44+
cd "${{ env.EC_INSTALL_PATH }}"
45+
tar --extract --file="${{ steps.download.outputs.name }}"
46+
# Give the binary a standard name
47+
mv "${{ env.EC_INSTALL_PATH }}/bin/ec-linux-amd64" "${{ env.EC_INSTALL_PATH }}/bin/ec"
48+
# Add installation to PATH:
49+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path
50+
echo "${{ env.EC_INSTALL_PATH }}/bin" >> "$GITHUB_PATH"
51+
52+
- name: Check formatting
53+
run: task --silent general:check-formatting

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![Integration Test status](https://github.com/arduino/libraries-repository-engine/actions/workflows/test-go-integration-task.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/test-go-integration-task.yml)
66
[![Check Go status](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-go-task.yml)
77
[![Check Python status](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-python-task.yml)
8+
[![Check General Formatting status](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-general-formatting-task.yml)
89
[![Check Prettier Formatting status](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-prettier-formatting-task.yml)
910
[![Check Taskfiles status](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/check-taskfiles.yml)
1011
[![Spell Check status](https://github.com/arduino/libraries-repository-engine/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/libraries-repository-engine/actions/workflows/spell-check-task.yml)

Taskfile.yml

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tasks:
1818
check:
1919
desc: Check for problems with the project
2020
deps:
21+
- task: general:check-formatting
2122
- task: general:check-spelling
2223
- task: go:lint
2324
- task: go:test
@@ -40,6 +41,17 @@ tasks:
4041
# This is an "umbrella" task used to call any documentation generation processes the project has.
4142
# It can be left empty if there are none.
4243

44+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml
45+
general:check-formatting:
46+
desc: Check basic formatting style of all files
47+
cmds:
48+
- |
49+
if ! which ec &>/dev/null; then
50+
echo "ec not found or not in PATH. Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation"
51+
exit 1
52+
fi
53+
- ec
54+
4355
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
4456
go:build:
4557
desc: Build the Go code
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
hello world
1+
hello world

0 commit comments

Comments
 (0)