Skip to content

Commit ca03dde

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 051bb95 commit ca03dde

File tree

13 files changed

+510
-0
lines changed

13 files changed

+510
-0
lines changed

.ecrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Exclude": ["LICENSE.txt"]
3+
}

.editorconfig

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/assets/shared/.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]
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

.github/workflows/check-ci-sync.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This repository contains intentionally duplicated copies of template workflows under .github/workflows used for this
2+
# repository's own CI system.
3+
#
4+
# This workflow checks that the copies are in sync.
5+
# If the workflow fails, run `task fix` and commit.
6+
7+
name: Check CI Workflows Sync
8+
9+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
10+
on:
11+
push:
12+
paths:
13+
- ".github/workflows/*.ya?ml"
14+
- "Taskfile.ya?ml"
15+
- "workflow-templates/*.ya?ml"
16+
pull_request:
17+
paths:
18+
- ".github/workflows/*.ya?ml"
19+
- "Taskfile.ya?ml"
20+
- "workflow-templates/*.ya?ml"
21+
workflow_dispatch:
22+
repository_dispatch:
23+
24+
jobs:
25+
check-sync:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v2
31+
32+
- name: Install Task
33+
uses: arduino/setup-task@v1
34+
with:
35+
repo-token: ${{ secrets.GITHUB_TOKEN }}
36+
version: 3.x
37+
38+
- name: Sync files
39+
run: task --silent ci:sync
40+
41+
- name: Check file duplicates sync
42+
run: |
43+
git add .
44+
if ! git diff --color --exit-code HEAD; then
45+
echo "::error::File duplicates are out of sync. Please run \"task fix\""
46+
exit 1
47+
fi
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This repository contains intentionally duplicated copies of template configuration files in use for this repository's
2+
# own purposes
3+
#
4+
# This workflow checks that the copies are in sync.
5+
# If the workflow fails, run `task fix` and commit.
6+
7+
name: Check Configuration Files Sync
8+
9+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
10+
on:
11+
push:
12+
pull_request:
13+
workflow_dispatch:
14+
repository_dispatch:
15+
16+
jobs:
17+
check-sync:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v2
23+
24+
- name: Install Task
25+
uses: arduino/setup-task@v1
26+
with:
27+
repo-token: ${{ secrets.GITHUB_TOKEN }}
28+
version: 3.x
29+
30+
- name: Sync files
31+
run: task --silent config:sync
32+
33+
- name: Check file duplicates sync
34+
run: |
35+
git add .
36+
if ! git diff --color --exit-code HEAD; then
37+
echo "::error::File duplicates are out of sync. Please run \"task fix\""
38+
exit 1
39+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/master/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@v2
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: Get data for latest editorconfig-checker release
34+
id: get-release-data
35+
uses: octokit/[email protected]
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
with:
39+
# Pre-releases are ignored
40+
route: GET /repos/:owner/:repo/releases/latest
41+
# The following inputs result in "Unexpected input" warnings on the workflow run log and summary page,
42+
# but they are correct
43+
owner: editorconfig-checker
44+
repo: editorconfig-checker
45+
46+
- name: Download release binary
47+
id: download-release
48+
uses: carlosperate/[email protected]
49+
with:
50+
# See: https://github.com/editorconfig-checker/editorconfig-checker/releases
51+
file-url: https://github.com/editorconfig-checker/editorconfig-checker/releases/download/${{ fromJson(steps.get-release-data.outputs.data).tag_name }}/ec-linux-amd64.tar.gz
52+
location: ${{ env.EC_INSTALL_PATH }}
53+
54+
- name: Install editorconfig-checker
55+
run: |
56+
cd "${{ env.EC_INSTALL_PATH }}"
57+
tar --extract --file="${{ steps.download-release.outputs.file-path }}"
58+
# Give the binary a standard name
59+
mv "${{ env.EC_INSTALL_PATH }}/bin/ec-linux-amd64" "${{ env.EC_INSTALL_PATH }}/bin/ec"
60+
# Add installation to PATH:
61+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path
62+
echo "${{ env.EC_INSTALL_PATH }}/bin" >> "$GITHUB_PATH"
63+
64+
- name: Check formatting
65+
run: task --silent general:check-formatting

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Tooling Project Assets
22

33
[![Check Configuration Files status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-configuration-files.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-configuration-files.yml)
4+
[![Check General Formatting status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-general-formatting-task.yml)
45
[![Check License status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-license.yml)
56
[![Check File Duplicates Sync status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-sync.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-sync.yml)
7+
[![Check CI Workflows Sync status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-ci-sync.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-ci-sync.yml)
8+
[![Check Configuration Files Sync status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-config-sync.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-config-sync.yml)
69

710
The [Arduino](https://www.arduino.cc/) Tooling Team's collection of reusable project infrastructure assets.
811

Taskfile.yml

+35
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,48 @@ tasks:
44
fix:
55
desc: Make automated corrections to the project's files
66
deps:
7+
- task: ci:sync
8+
- task: config:sync
79
- task: dependabot:sync
810

911
check:
1012
desc: Check for problems with the project
1113
deps:
14+
- task: general:check-formatting
1215
- task: config:validate
1316

17+
general:check-formatting:
18+
desc: Check basic formatting style of all files
19+
cmds:
20+
- |
21+
if ! which ec &>/dev/null; then
22+
echo "ec not found or not in PATH. Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation"
23+
exit 1
24+
fi
25+
- ec
26+
27+
ci:sync:
28+
desc: Sync CI workflows from templates
29+
vars:
30+
WORKFLOWS_PATH: "./.github/workflows"
31+
WORKFLOW_TEMPLATES_PATH: "./workflow-templates"
32+
cmds:
33+
- |
34+
cp \
35+
"{{.WORKFLOW_TEMPLATES_PATH}}/check-general-formatting-task.yml" \
36+
"{{.WORKFLOWS_PATH}}"
37+
38+
config:sync:
39+
desc: Sync configuration files from templates
40+
vars:
41+
REPOSITORY_ROOT_PATH: "./"
42+
WORKFLOW_TEMPLATE_ASSETS_PATH: "./workflow-templates/assets"
43+
cmds:
44+
- |
45+
cp \
46+
"{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/shared/.editorconfig" \
47+
"{{.REPOSITORY_ROOT_PATH}}"
48+
1449
dependabot:sync:
1550
desc: Sync workflow duplicates for dependabot checks
1651
vars:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Exclude": ["LICENSE.txt"]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/assets/check-general-formatting-task/Taskfile.yml
2+
# See: https://taskfile.dev/#/usage
3+
version: "3"
4+
5+
tasks:
6+
general:check-formatting:
7+
desc: Check basic formatting style of all files
8+
cmds:
9+
- |
10+
if ! which ec &>/dev/null; then
11+
echo "ec not found or not in PATH. Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation"
12+
exit 1
13+
fi
14+
- ec
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/assets/shared/.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]
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

0 commit comments

Comments
 (0)