Skip to content

Add infrastructure for formatting with the Prettier tool #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
260 changes: 260 additions & 0 deletions .github/workflows/check-prettier-formatting-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md
name: Check Prettier Formatting

env:
# See: https://github.com/actions/setup-node/#readme
NODE_VERSION: 16.x

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-prettier-formatting-task.ya?ml"
- "Taskfile.ya?ml"
- "**/.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"
pull_request:
paths:
- ".github/workflows/check-prettier-formatting-task.ya?ml"
- "Taskfile.ya?ml"
- "**/.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/v[0-9]+$"
# 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: ${{ env.NODE_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
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
20 changes: 10 additions & 10 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ name: Run integration tests
on:
pull_request:
paths:
- '.github/workflows/test-integration.yml'
- '.github/workflows/testdata/**'
- 'action.yml'
- 'Dockerfile'
- 'reportsizedeltas/**'
- ".github/workflows/test-integration.yml"
- ".github/workflows/testdata/**"
- "action.yml"
- "Dockerfile"
- "reportsizedeltas/**"
push:
paths:
- '.github/workflows/test-integration.yml'
- '.github/workflows/testdata/**'
- 'action.yml'
- 'Dockerfile'
- 'reportsizedeltas/**'
- ".github/workflows/test-integration.yml"
- ".github/workflows/testdata/**"
- "action.yml"
- "Dockerfile"
- "reportsizedeltas/**"
schedule:
# Run daily at 8 AM UTC to catch breakage caused by changes to external resources.
- cron: "0 8 * * *"
Expand Down
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.github/workflows/testdata/sketches-reports/
/reportsizedeltas/tests/data/size-deltas-reports-new/
/reportsizedeltas/tests/data/size-deltas-reports-old/
.licenses/
__pycache__/
node_modules/
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![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)
[![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)
[![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)
[![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)
[![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)
[![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)
[![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)
Expand Down Expand Up @@ -72,7 +73,7 @@ In this usage, the `sketches-reports-source` defines the path to the folder cont
```yaml
on:
schedule:
- cron: '*/5 * * * *'
- cron: "*/5 * * * *"
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -81,6 +82,7 @@ jobs:
```

This must be used in conjunction with a workflow that runs the [`arduino/compile-sketches`](https://github.com/arduino/compile-sketches) action and uploads the resulting sketches report to a [workflow artifact](https://help.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts):

```yaml
on: [push, pull_request]
jobs:
Expand Down Expand Up @@ -122,7 +124,7 @@ jobs:
enable-deltas-report: true
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}

# This step is needed to pass the size data to the report job
# This step is needed to pass the size data to the report job
- name: Upload sketches report to workflow artifact
uses: actions/upload-artifact@v3
with:
Expand All @@ -131,7 +133,7 @@ jobs:

# When using a matrix to compile for multiple boards, it's necessary to use a separate job for the deltas report
report:
needs: compile # Wait for the compile job to finish to get the data for the report
needs: compile # Wait for the compile job to finish to get the data for the report
if: github.event_name == 'pull_request' # Only run the job when the workflow is triggered by a pull request
runs-on: ubuntu-latest
steps:
Expand Down
10 changes: 9 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tasks:
desc: Make automated corrections to the project's files
deps:
- task: general:correct-spelling
- task: general:format-prettier
- task: markdown:fix
- task: markdown:toc
- task: poetry:sync
Expand All @@ -49,6 +50,14 @@ tasks:
cmds:
- poetry run codespell --write-changes

# 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/check-markdown-task/Taskfile.yml
markdown:check-links:
desc: Check for broken links
Expand Down Expand Up @@ -125,7 +134,6 @@ tasks:
cmds:
- npm install


# Parameter variables:
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml
Expand Down
14 changes: 7 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: 'Report Arduino Sketch Size Deltas'
description: 'Comments on the pull request with a report on the resulting change in memory usage of Arduino sketches'
name: "Report Arduino Sketch Size Deltas"
description: "Comments on the pull request with a report on the resulting change in memory usage of Arduino sketches"
inputs:
sketches-reports-source:
description: 'When run from scheduled workflow, name of the workflow artifact that contains sketches reports. When run from a pull request triggered workflow, path to the folder containing sketches reports.'
default: 'sketches-reports'
description: "When run from scheduled workflow, name of the workflow artifact that contains sketches reports. When run from a pull request triggered workflow, path to the folder containing sketches reports."
default: "sketches-reports"
github-token:
description: 'GitHub access token used to comment the memory usage comparison results to the PR thread'
description: "GitHub access token used to comment the memory usage comparison results to the PR thread"
default: ${{ github.token }}
runs:
using: 'docker'
image: 'Dockerfile'
using: "docker"
image: "Dockerfile"
Loading