Skip to content

Commit 8bea9d9

Browse files
committed
Add template workflow to check for Prettier formatting compliance
On every push and pull request that affects relevant files, and periodically, check whether the formatting of supported files is compliant with the Prettier style.
1 parent dc1e538 commit 8bea9d9

File tree

7 files changed

+743
-0
lines changed

7 files changed

+743
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
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+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/check-prettier-formatting-task.ya?ml"
9+
- "Taskfile.ya?ml"
10+
- "**/.prettierignore"
11+
- "**/.prettierrc*"
12+
# CSS
13+
- "**.css"
14+
- "**.wxss"
15+
# PostCSS
16+
- "**.pcss"
17+
- "**.postcss"
18+
# Less
19+
- "**.less"
20+
# SCSS
21+
- "**.scss"
22+
# GraphQL
23+
- "**.graphqls?"
24+
- "**.gql"
25+
# handlebars
26+
- "**.handlebars"
27+
- "**.hbs"
28+
# HTML
29+
- "**.mjml"
30+
- "**.html?"
31+
- "**.html.hl"
32+
- "**.st"
33+
- "**.xht"
34+
- "**.xhtml"
35+
# Vue
36+
- "**.vue"
37+
# JavaScript
38+
- "**.flow"
39+
- "**._?jsb?"
40+
- "**.bones"
41+
- "**.cjs"
42+
- "**.es6?"
43+
- "**.frag"
44+
- "**.gs"
45+
- "**.jake"
46+
- "**.jscad"
47+
- "**.jsfl"
48+
- "**.js[ms]"
49+
- "**.[mn]js"
50+
- "**.pac"
51+
- "**.wxs"
52+
- "**.[xs]s?js"
53+
- "**.xsjslib"
54+
# JSX
55+
- "**.jsx"
56+
# TypeScript
57+
- "**.ts"
58+
# TSX
59+
- "**.tsx"
60+
# JSON
61+
- "**/.eslintrc"
62+
- "**.json"
63+
- "**.avsc"
64+
- "**.geojson"
65+
- "**.gltf"
66+
- "**.har"
67+
- "**.ice"
68+
- "**.JSON-tmLanguage"
69+
- "**.mcmeta"
70+
- "**.tfstate"
71+
- "**.topojson"
72+
- "**.webapp"
73+
- "**.webmanifest"
74+
- "**.yyp?"
75+
# JSONC
76+
- "**/.babelrc"
77+
- "**/.jscsrc"
78+
- "**/.js[hl]intrc"
79+
- "**.jsonc"
80+
- "**.sublime-*"
81+
# JSON5
82+
- "**.json5"
83+
# Markdown
84+
- "**.mdx?"
85+
- "**.markdown"
86+
- "**.mk?down"
87+
- "**.mdwn"
88+
- "**.mkdn?"
89+
- "**.ronn"
90+
- "**.workbook"
91+
# YAML
92+
- "**/.clang-format"
93+
- "**/.clang-tidy"
94+
- "**/.gemrc"
95+
- "**/glide.lock"
96+
- "**.ya?ml*"
97+
- "**.mir"
98+
- "**.reek"
99+
- "**.rviz"
100+
- "**.sublime-syntax"
101+
- "**.syntax"
102+
pull_request:
103+
paths:
104+
- ".github/workflows/check-prettier-formatting-task.ya?ml"
105+
- "Taskfile.ya?ml"
106+
- "**/.prettierignore"
107+
- "**/.prettierrc*"
108+
# CSS
109+
- "**.css"
110+
- "**.wxss"
111+
# PostCSS
112+
- "**.pcss"
113+
- "**.postcss"
114+
# Less
115+
- "**.less"
116+
# SCSS
117+
- "**.scss"
118+
# GraphQL
119+
- "**.graphqls?"
120+
- "**.gql"
121+
# handlebars
122+
- "**.handlebars"
123+
- "**.hbs"
124+
# HTML
125+
- "**.mjml"
126+
- "**.html?"
127+
- "**.html.hl"
128+
- "**.st"
129+
- "**.xht"
130+
- "**.xhtml"
131+
# Vue
132+
- "**.vue"
133+
# JavaScript
134+
- "**.flow"
135+
- "**._?jsb?"
136+
- "**.bones"
137+
- "**.cjs"
138+
- "**.es6?"
139+
- "**.frag"
140+
- "**.gs"
141+
- "**.jake"
142+
- "**.jscad"
143+
- "**.jsfl"
144+
- "**.js[ms]"
145+
- "**.[mn]js"
146+
- "**.pac"
147+
- "**.wxs"
148+
- "**.[xs]s?js"
149+
- "**.xsjslib"
150+
# JSX
151+
- "**.jsx"
152+
# TypeScript
153+
- "**.ts"
154+
# TSX
155+
- "**.tsx"
156+
# JSON
157+
- "**/.eslintrc"
158+
- "**.json"
159+
- "**.avsc"
160+
- "**.geojson"
161+
- "**.gltf"
162+
- "**.har"
163+
- "**.ice"
164+
- "**.JSON-tmLanguage"
165+
- "**.mcmeta"
166+
- "**.tfstate"
167+
- "**.topojson"
168+
- "**.webapp"
169+
- "**.webmanifest"
170+
- "**.yyp?"
171+
# JSONC
172+
- "**/.babelrc"
173+
- "**/.jscsrc"
174+
- "**/.js[hl]intrc"
175+
- "**.jsonc"
176+
- "**.sublime-*"
177+
# JSON5
178+
- "**.json5"
179+
# Markdown
180+
- "**.mdx?"
181+
- "**.markdown"
182+
- "**.mk?down"
183+
- "**.mdwn"
184+
- "**.mkdn?"
185+
- "**.ronn"
186+
- "**.workbook"
187+
# YAML
188+
- "**/.clang-format"
189+
- "**/.clang-tidy"
190+
- "**/.gemrc"
191+
- "**/glide.lock"
192+
- "**.ya?ml*"
193+
- "**.mir"
194+
- "**.reek"
195+
- "**.rviz"
196+
- "**.sublime-syntax"
197+
- "**.syntax"
198+
workflow_dispatch:
199+
repository_dispatch:
200+
201+
jobs:
202+
check:
203+
runs-on: ubuntu-latest
204+
205+
steps:
206+
- name: Checkout repository
207+
uses: actions/checkout@v2
208+
209+
- name: Install Task
210+
uses: arduino/setup-task@v1
211+
with:
212+
repo-token: ${{ secrets.GITHUB_TOKEN }}
213+
version: 3.x
214+
215+
- name: Format with Prettier
216+
run: task general:format-prettier
217+
218+
- name: Check formatting
219+
run: git diff --color --exit-code

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![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)
88
[![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)
99
[![Check Markdown status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-markdown-task.yml)
10+
[![Check Prettier Formatting status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-prettier-formatting-task.yml)
1011

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

Taskfile.yml

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tasks:
88
- task: config:sync
99
- task: dependabot:sync
1010
- task: markdown:fix
11+
- task: general:format-prettier
1112

1213
check:
1314
desc: Check for problems with the project
@@ -17,6 +18,12 @@ tasks:
1718
- task: markdown:lint
1819
- task: markdown:check-links
1920

21+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
22+
general:format-prettier:
23+
desc: Format all supported files with Prettier
24+
cmds:
25+
- npx prettier --write .
26+
2027
general:check-formatting:
2128
desc: Check basic formatting style of all files
2229
cmds:
@@ -37,6 +44,7 @@ tasks:
3744
cp \
3845
"{{.WORKFLOW_TEMPLATES_PATH}}/check-general-formatting-task.yml" \
3946
"{{.WORKFLOW_TEMPLATES_PATH}}/check-markdown-task.yml" \
47+
"{{.WORKFLOW_TEMPLATES_PATH}}/check-prettier-formatting-task.yml" \
4048
"{{.WORKFLOWS_PATH}}"
4149
4250
config:sync:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See: https://taskfile.dev/#/usage
2+
version: "3"
3+
4+
tasks:
5+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
6+
general:format-prettier:
7+
desc: Format all supported files with Prettier
8+
cmds:
9+
- npx prettier --write .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# "Check Prettier Formatting" workflow (Task)
2+
3+
Workflow file: [check-prettier-formatting-task.yml](check-prettier-formatting-task.yml)
4+
5+
Use [Prettier](https://prettier.io/docs/en/index.html) to check formatting. Supported languages include:
6+
7+
- JavaScript
8+
- TypeScript
9+
- CSS
10+
- HTML
11+
- JSON
12+
- Markdown
13+
- YAML
14+
15+
This is the version of the workflow for projects using the [Task](https://taskfile.dev/#/) task runner tool.
16+
17+
## Assets
18+
19+
- [`Taskfile.yml`](assets/check-prettier-formatting-task/Taskfile.yml] - Formatting task.
20+
- Install to: repository root (or add the `general:format-prettier` task into the existing `Taskfile.yml`)
21+
22+
## Configuration
23+
24+
Prettier should be configured via a `.prettierignore` file to ignore any externally maintained files contained in the repository:
25+
https://prettier.io/docs/en/ignore.html
26+
27+
Support for additional languages can be added to Prettier via plugins:
28+
https://prettier.io/docs/en/plugins.html
29+
30+
Prettier automatically determines the language based on file name. In cases where it is not able to recognize a file, the parser can be specified in a `.prettierrc.yml` configuration file:
31+
https://prettier.io/docs/en/configuration.html#setting-the-parserdocsenoptionshtmlparser-option
32+
33+
The default Prettier code style is the official standardized style to be used in all Arduino tooling projects and should not be modified.
34+
35+
## Readme badge
36+
37+
Markdown badge:
38+
39+
```markdown
40+
[![Check Prettier Formatting status](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-prettier-formatting-task.yml)
41+
```
42+
43+
Replace the `REPO_OWNER` and `REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)).
44+
45+
---
46+
47+
Asciidoc badge:
48+
49+
```adoc
50+
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-prettier-formatting-task.yml/badge.svg["Check Prettier Formatting status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-prettier-formatting-task.yml"]
51+
```
52+
53+
Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)).
54+
55+
## Commit message
56+
57+
```
58+
Add CI workflow to check for Prettier formatting compliance
59+
60+
On every push and pull request that affects relevant files, and periodically, check whether the formatting of supported
61+
files is compliant with the Prettier style.
62+
```
63+
64+
## PR message
65+
66+
```markdown
67+
On every push and pull request that affects relevant files, and periodically, check whether the formatting of supported files is compliant with the [Prettier](https://prettier.io/docs/en/index.html) style.
68+
```

0 commit comments

Comments
 (0)