Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add CI workflow to check for Prettier formatting compliance
On every push and pull request that affects relevant files, check whether the formatting of supported
files is compliant with the Prettier style.
  • Loading branch information
per1234 committed Oct 7, 2024
commit db1ca8b0c97c47c0004ed784698391920c055e40
9 changes: 8 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ The **Node.js** version in use is defined in the `engines.node` field of [`packa

[nvm](https://github.com/nvm-sh/nvm) is recommended to easily switch between Node.js versions.

#### Task

The [**Task**](https://taskfile.dev) task runner tool is used for all common development and validation operations.

Follow the installation instructions here:<br />
https://taskfile.dev/installation/

### 2. Install dependencies

To work on the codebase you have to install all the dependencies:
Expand All @@ -32,7 +39,7 @@ Make sure to write or update tests for your work when appropriate.
Format the code to follow the standard style for the project:

```
npm run format
task general:format-prettier
```

### 5. Run tests
Expand Down
266 changes: 266 additions & 0 deletions .github/workflows/check-prettier-formatting-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md
name: Check Prettier Formatting

# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-prettier-formatting-task.ya?ml"
- "Taskfile.ya?ml"
- "**/.npmrc"
- "**/.prettierignore"
- "**/.prettierrc*"
# Prettier-covered file patterns are defined by:
# https://github.com/github-linguist/linguist/blob/master/lib/linguist/languages.yml
# CSS
- "**.css"
- "**.wxss"
# PostCSS
- "**.pcss"
- "**.postcss"
# Less
- "**.less"
# SCSS
- "**.scss"
# GraphQL
- "**.graphqls?"
- "**.gql"
# handlebars
- "**.handlebars"
- "**.hbs"
# HTML
- "**.mjml"
- "**.html?"
- "**.html.hl"
- "**.st"
- "**.xht"
- "**.xhtml"
# Vue
- "**.vue"
# JavaScript
- "**.flow"
- "**._?jsb?"
- "**.bones"
- "**.cjs"
- "**.es6?"
- "**.frag"
- "**.gs"
- "**.jake"
- "**.jscad"
- "**.jsfl"
- "**.js[ms]"
- "**.[mn]js"
- "**.pac"
- "**.wxs"
- "**.[xs]s?js"
- "**.xsjslib"
# JSX
- "**.jsx"
# TypeScript
- "**.ts"
# TSX
- "**.tsx"
# JSON
- "**/.eslintrc"
- "**.json"
- "**.avsc"
- "**.geojson"
- "**.gltf"
- "**.har"
- "**.ice"
- "**.JSON-tmLanguage"
- "**.mcmeta"
- "**.tfstate"
- "**.topojson"
- "**.webapp"
- "**.webmanifest"
- "**.yyp?"
# JSONC
- "**/.babelrc"
- "**/.jscsrc"
- "**/.js[hl]intrc"
- "**.jsonc"
- "**.sublime-*"
# JSON5
- "**.json5"
# Markdown
- "**.mdx?"
- "**.markdown"
- "**.mk?down"
- "**.mdwn"
- "**.mkdn?"
- "**.ronn"
- "**.workbook"
# YAML
- "**/.clang-format"
- "**/.clang-tidy"
- "**/.gemrc"
- "**/glide.lock"
- "**.ya?ml*"
- "**.mir"
- "**.reek"
- "**.rviz"
- "**.sublime-syntax"
- "**.syntax"
pull_request:
paths:
- ".github/workflows/check-prettier-formatting-task.ya?ml"
- "Taskfile.ya?ml"
- "**/.npmrc"
- "**/.prettierignore"
- "**/.prettierrc*"
# CSS
- "**.css"
- "**.wxss"
# PostCSS
- "**.pcss"
- "**.postcss"
# Less
- "**.less"
# SCSS
- "**.scss"
# GraphQL
- "**.graphqls?"
- "**.gql"
# handlebars
- "**.handlebars"
- "**.hbs"
# HTML
- "**.mjml"
- "**.html?"
- "**.html.hl"
- "**.st"
- "**.xht"
- "**.xhtml"
# Vue
- "**.vue"
# JavaScript
- "**.flow"
- "**._?jsb?"
- "**.bones"
- "**.cjs"
- "**.es6?"
- "**.frag"
- "**.gs"
- "**.jake"
- "**.jscad"
- "**.jsfl"
- "**.js[ms]"
- "**.[mn]js"
- "**.pac"
- "**.wxs"
- "**.[xs]s?js"
- "**.xsjslib"
# JSX
- "**.jsx"
# TypeScript
- "**.ts"
# TSX
- "**.tsx"
# JSON
- "**/.eslintrc"
- "**.json"
- "**.avsc"
- "**.geojson"
- "**.gltf"
- "**.har"
- "**.ice"
- "**.JSON-tmLanguage"
- "**.mcmeta"
- "**.tfstate"
- "**.topojson"
- "**.webapp"
- "**.webmanifest"
- "**.yyp?"
# JSONC
- "**/.babelrc"
- "**/.jscsrc"
- "**/.js[hl]intrc"
- "**.jsonc"
- "**.sublime-*"
# JSON5
- "**.json5"
# Markdown
- "**.mdx?"
- "**.markdown"
- "**.mk?down"
- "**.mdwn"
- "**.mkdn?"
- "**.ronn"
- "**.workbook"
# YAML
- "**/.clang-format"
- "**/.clang-tidy"
- "**/.gemrc"
- "**/glide.lock"
- "**.ya?ml*"
- "**.mir"
- "**.reek"
- "**.rviz"
- "**.sublime-syntax"
- "**.syntax"
schedule:
# Run periodically to catch breakage caused by external changes.
- cron: "0 4 * * WED"
workflow_dispatch:
repository_dispatch:

jobs:
run-determination:
runs-on: ubuntu-latest
permissions: {}
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi

echo "result=$RESULT" >> $GITHUB_OUTPUT

check:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: package.json

- name: Install Task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Format with Prettier
run: |
task \
general:format-prettier

- name: Check formatting
run: |
git \
diff \
--color \
--exit-code
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ jobs:
- name: npm install
run: npm install

- name: npm lint
run: npm run format-check

- name: npm test
run: npm test
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.licenses/
__pycache__/
/dist/
/lib/
node_modules/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Tests Status](https://github.com/arduino/arduino-lint-action/workflows/Test%20Action/badge.svg)](https://github.com/arduino/arduino-lint-action/actions?workflow=Test+Action)
[![Integration Tests Status](https://github.com/arduino/arduino-lint-action/workflows/Integration%20Tests/badge.svg)](https://github.com/arduino/arduino-lint-action/actions?workflow=Integration+Tests)
[![Check Packaging status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-packaging-ncc-typescript-npm.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-packaging-ncc-typescript-npm.yml)
[![Check Prettier Formatting status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-prettier-formatting-task.yml)
[![Check TypeScript Configuration status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-tsconfig.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-tsconfig.yml)
[![Check npm status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-npm-task.yml)
[![Spellcheck Status](https://github.com/arduino/arduino-lint-action/workflows/Spell%20Check/badge.svg)](https://github.com/arduino/arduino-lint-action/actions?workflow=Spell+Check)
Expand Down
9 changes: 9 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ tasks:
fix:
desc: Make automated corrections to the project's files
deps:
- task: general:format-prettier
- task: npm:install-deps

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
general:format-prettier:
desc: Format all supported files with Prettier
deps:
- task: npm:install-deps
cmds:
- npx prettier --write .

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
npm:install-deps:
desc: |
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"pack": "ncc build",
"test": "jest"
},
Expand Down