Skip to content

Commit d7b3cc1

Browse files
committed
Add infrastructure for formatting with the Prettier tool
Prettier is a tool for formatting files of various formats. It is a standard in Arduino tooling projects. A task is provided to allow contributors to easily format the files of the project. A GitHub Actions workflow checks for Prettier formatting compliance on every push and pull request that affects relevant files.
1 parent 5494460 commit d7b3cc1

File tree

6 files changed

+301
-2
lines changed

6 files changed

+301
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md
2+
name: Check Prettier Formatting
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/check-prettier-formatting-task.ya?ml"
14+
- "Taskfile.ya?ml"
15+
- "**/.prettierignore"
16+
- "**/.prettierrc*"
17+
# CSS
18+
- "**.css"
19+
- "**.wxss"
20+
# PostCSS
21+
- "**.pcss"
22+
- "**.postcss"
23+
# Less
24+
- "**.less"
25+
# SCSS
26+
- "**.scss"
27+
# GraphQL
28+
- "**.graphqls?"
29+
- "**.gql"
30+
# handlebars
31+
- "**.handlebars"
32+
- "**.hbs"
33+
# HTML
34+
- "**.mjml"
35+
- "**.html?"
36+
- "**.html.hl"
37+
- "**.st"
38+
- "**.xht"
39+
- "**.xhtml"
40+
# Vue
41+
- "**.vue"
42+
# JavaScript
43+
- "**.flow"
44+
- "**._?jsb?"
45+
- "**.bones"
46+
- "**.cjs"
47+
- "**.es6?"
48+
- "**.frag"
49+
- "**.gs"
50+
- "**.jake"
51+
- "**.jscad"
52+
- "**.jsfl"
53+
- "**.js[ms]"
54+
- "**.[mn]js"
55+
- "**.pac"
56+
- "**.wxs"
57+
- "**.[xs]s?js"
58+
- "**.xsjslib"
59+
# JSX
60+
- "**.jsx"
61+
# TypeScript
62+
- "**.ts"
63+
# TSX
64+
- "**.tsx"
65+
# JSON
66+
- "**/.eslintrc"
67+
- "**.json"
68+
- "**.avsc"
69+
- "**.geojson"
70+
- "**.gltf"
71+
- "**.har"
72+
- "**.ice"
73+
- "**.JSON-tmLanguage"
74+
- "**.mcmeta"
75+
- "**.tfstate"
76+
- "**.topojson"
77+
- "**.webapp"
78+
- "**.webmanifest"
79+
- "**.yyp?"
80+
# JSONC
81+
- "**/.babelrc"
82+
- "**/.jscsrc"
83+
- "**/.js[hl]intrc"
84+
- "**.jsonc"
85+
- "**.sublime-*"
86+
# JSON5
87+
- "**.json5"
88+
# Markdown
89+
- "**.mdx?"
90+
- "**.markdown"
91+
- "**.mk?down"
92+
- "**.mdwn"
93+
- "**.mkdn?"
94+
- "**.ronn"
95+
- "**.workbook"
96+
# YAML
97+
- "**/.clang-format"
98+
- "**/.clang-tidy"
99+
- "**/.gemrc"
100+
- "**/glide.lock"
101+
- "**.ya?ml*"
102+
- "**.mir"
103+
- "**.reek"
104+
- "**.rviz"
105+
- "**.sublime-syntax"
106+
- "**.syntax"
107+
pull_request:
108+
paths:
109+
- ".github/workflows/check-prettier-formatting-task.ya?ml"
110+
- "Taskfile.ya?ml"
111+
- "**/.prettierignore"
112+
- "**/.prettierrc*"
113+
# CSS
114+
- "**.css"
115+
- "**.wxss"
116+
# PostCSS
117+
- "**.pcss"
118+
- "**.postcss"
119+
# Less
120+
- "**.less"
121+
# SCSS
122+
- "**.scss"
123+
# GraphQL
124+
- "**.graphqls?"
125+
- "**.gql"
126+
# handlebars
127+
- "**.handlebars"
128+
- "**.hbs"
129+
# HTML
130+
- "**.mjml"
131+
- "**.html?"
132+
- "**.html.hl"
133+
- "**.st"
134+
- "**.xht"
135+
- "**.xhtml"
136+
# Vue
137+
- "**.vue"
138+
# JavaScript
139+
- "**.flow"
140+
- "**._?jsb?"
141+
- "**.bones"
142+
- "**.cjs"
143+
- "**.es6?"
144+
- "**.frag"
145+
- "**.gs"
146+
- "**.jake"
147+
- "**.jscad"
148+
- "**.jsfl"
149+
- "**.js[ms]"
150+
- "**.[mn]js"
151+
- "**.pac"
152+
- "**.wxs"
153+
- "**.[xs]s?js"
154+
- "**.xsjslib"
155+
# JSX
156+
- "**.jsx"
157+
# TypeScript
158+
- "**.ts"
159+
# TSX
160+
- "**.tsx"
161+
# JSON
162+
- "**/.eslintrc"
163+
- "**.json"
164+
- "**.avsc"
165+
- "**.geojson"
166+
- "**.gltf"
167+
- "**.har"
168+
- "**.ice"
169+
- "**.JSON-tmLanguage"
170+
- "**.mcmeta"
171+
- "**.tfstate"
172+
- "**.topojson"
173+
- "**.webapp"
174+
- "**.webmanifest"
175+
- "**.yyp?"
176+
# JSONC
177+
- "**/.babelrc"
178+
- "**/.jscsrc"
179+
- "**/.js[hl]intrc"
180+
- "**.jsonc"
181+
- "**.sublime-*"
182+
# JSON5
183+
- "**.json5"
184+
# Markdown
185+
- "**.mdx?"
186+
- "**.markdown"
187+
- "**.mk?down"
188+
- "**.mdwn"
189+
- "**.mkdn?"
190+
- "**.ronn"
191+
- "**.workbook"
192+
# YAML
193+
- "**/.clang-format"
194+
- "**/.clang-tidy"
195+
- "**/.gemrc"
196+
- "**/glide.lock"
197+
- "**.ya?ml*"
198+
- "**.mir"
199+
- "**.reek"
200+
- "**.rviz"
201+
- "**.sublime-syntax"
202+
- "**.syntax"
203+
schedule:
204+
# Run periodically to catch breakage caused by external changes.
205+
- cron: "0 4 * * WED"
206+
workflow_dispatch:
207+
repository_dispatch:
208+
209+
jobs:
210+
run-determination:
211+
runs-on: ubuntu-latest
212+
permissions: {}
213+
outputs:
214+
result: ${{ steps.determination.outputs.result }}
215+
steps:
216+
- name: Determine if the rest of the workflow should run
217+
id: determination
218+
run: |
219+
RELEASE_BRANCH_REGEX="^refs/heads/v[0-9]+$"
220+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
221+
if [[
222+
"${{ github.event_name }}" != "create" ||
223+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
224+
]]; then
225+
# Run the other jobs.
226+
RESULT="true"
227+
else
228+
# There is no need to run the other jobs.
229+
RESULT="false"
230+
fi
231+
232+
echo "result=$RESULT" >> $GITHUB_OUTPUT
233+
234+
check:
235+
needs: run-determination
236+
if: needs.run-determination.outputs.result == 'true'
237+
runs-on: ubuntu-latest
238+
permissions:
239+
contents: read
240+
241+
steps:
242+
- name: Checkout repository
243+
uses: actions/checkout@v4
244+
245+
- name: Setup Node.js
246+
uses: actions/setup-node@v4
247+
with:
248+
node-version: ${{ env.NODE_VERSION }}
249+
250+
- name: Install Task
251+
uses: arduino/setup-task@v1
252+
with:
253+
repo-token: ${{ secrets.GITHUB_TOKEN }}
254+
version: 3.x
255+
256+
- name: Format with Prettier
257+
run: task general:format-prettier
258+
259+
- name: Check formatting
260+
run: git diff --color --exit-code

.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.github/workflows/testdata/sketches-reports/
2+
/reportsizedeltas/tests/data/size-deltas-reports-new/
3+
/reportsizedeltas/tests/data/size-deltas-reports-old/
4+
.licenses/
5+
__pycache__/
6+
node_modules/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Check Markdown status](https://github.com/arduino/report-size-deltas/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-markdown-task.yml)
44
[![Check npm status](https://github.com/arduino/report-size-deltas/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-npm-task.yml)
55
[![Check Poetry status](https://github.com/arduino/report-size-deltas/actions/workflows/check-poetry-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-poetry-task.yml)
6+
[![Check Prettier Formatting status](https://github.com/arduino/report-size-deltas/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-prettier-formatting-task.yml)
67
[![Check Python status](https://github.com/arduino/report-size-deltas/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-python-task.yml)
78
[![Check Taskfiles status](https://github.com/arduino/report-size-deltas/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-taskfiles.yml)
89
[![Check ToC status](https://github.com/arduino/report-size-deltas/actions/workflows/check-toc-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-toc-task.yml)

Taskfile.yml

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ tasks:
2323
desc: Make automated corrections to the project's files
2424
deps:
2525
- task: general:correct-spelling
26+
- task: general:format-prettier
2627
- task: markdown:fix
2728
- task: markdown:toc
2829
- task: poetry:sync
@@ -49,6 +50,14 @@ tasks:
4950
cmds:
5051
- poetry run codespell --write-changes
5152

53+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
54+
general:format-prettier:
55+
desc: Format all supported files with Prettier
56+
deps:
57+
- task: npm:install-deps
58+
cmds:
59+
- npx prettier --write .
60+
5261
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
5362
markdown:check-links:
5463
desc: Check for broken links

package-lock.json

+23-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"github-label-sync": "2.3.1",
66
"markdown-link-check": "3.11.2",
77
"markdown-toc": "1.2.0",
8-
"markdownlint-cli": "0.37.0"
8+
"markdownlint-cli": "0.37.0",
9+
"prettier": "3.1.1"
910
}
1011
}

0 commit comments

Comments
 (0)