Skip to content

Commit df6f433

Browse files
committed
Add infrastructure to check for Prettier formatting compliance
A task and GitHub Actions workflow are provided here for formatting the project's files using the Prettier code formatter tool. On every push and pull request that affects relevant files, the GitHub Actions workflow will check whether the formatting of supported files is compliant with the Prettier style.
1 parent 7a24ee5 commit df6f433

File tree

6 files changed

+296
-2
lines changed

6 files changed

+296
-2
lines changed
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
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+
outputs:
213+
result: ${{ steps.determination.outputs.result }}
214+
steps:
215+
- name: Determine if the rest of the workflow should run
216+
id: determination
217+
run: |
218+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
219+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
220+
if [[
221+
"${{ github.event_name }}" != "create" ||
222+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
223+
]]; then
224+
# Run the other jobs.
225+
RESULT="true"
226+
else
227+
# There is no need to run the other jobs.
228+
RESULT="false"
229+
fi
230+
231+
echo "result=$RESULT" >> $GITHUB_OUTPUT
232+
233+
check:
234+
needs: run-determination
235+
if: needs.run-determination.outputs.result == 'true'
236+
runs-on: ubuntu-latest
237+
238+
steps:
239+
- name: Checkout repository
240+
uses: actions/checkout@v3
241+
242+
- name: Setup Node.js
243+
uses: actions/setup-node@v3
244+
with:
245+
node-version: ${{ env.NODE_VERSION }}
246+
247+
- name: Install Task
248+
uses: arduino/setup-task@v1
249+
with:
250+
repo-token: ${{ secrets.GITHUB_TOKEN }}
251+
version: 3.x
252+
253+
- name: Format with Prettier
254+
run: task general:format-prettier
255+
256+
- name: Check formatting
257+
run: git diff --color --exit-code

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.licenses/
2+
.pytest_cache/
3+
__pycache__/
4+
node_modules/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![Check License status](https://github.com/arduino/compile-sketches/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-license.ym
77
[![Check Markdown status](https://github.com/arduino/compile-sketches/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-markdown-task.yml)
88
[![Check npm status](https://github.com/arduino/compile-sketches/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-npm-task.yml)
9+
[![Check Prettier Formatting status](https://github.com/arduino/compile-sketches/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-prettier-formatting-task.yml)
910
[![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)
1011
[![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)
1112
[![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: 9 additions & 0 deletions
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: python:format
2829

@@ -182,6 +183,14 @@ tasks:
182183
cmds:
183184
- poetry run codespell --write-changes
184185

186+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
187+
general:format-prettier:
188+
desc: Format all supported files with Prettier
189+
deps:
190+
- task: npm:install-deps
191+
cmds:
192+
- npx prettier --write .
193+
185194
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
186195
markdown:check-links:
187196
desc: Check for broken links

package-lock.json

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ajv-formats": "2.1.1",
55
"github-label-sync": "2.3.1",
66
"markdown-link-check": "3.10.3",
7-
"markdownlint-cli": "0.33.0"
7+
"markdownlint-cli": "0.33.0",
8+
"prettier": "2.8.6"
89
}
910
}

0 commit comments

Comments
 (0)