diff --git a/.github/workflows/check-prettier-formatting-task.yml b/.github/workflows/check-prettier-formatting-task.yml new file mode 100644 index 0000000..47b1c6c --- /dev/null +++ b/.github/workflows/check-prettier-formatting-task.yml @@ -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 diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index e888951..7ea191d 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -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 * * *" diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..79bae62 --- /dev/null +++ b/.prettierignore @@ -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/ diff --git a/README.md b/README.md index a4d51bf..d323218 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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: @@ -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: @@ -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: diff --git a/Taskfile.yml b/Taskfile.yml index 0cb35ab..55af182 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -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 @@ -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 @@ -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 diff --git a/action.yml b/action.yml index 3074acc..6a4f3cd 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/package-lock.json b/package-lock.json index 232b00c..8b4a113 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "github-label-sync": "2.3.1", "markdown-link-check": "3.11.2", "markdown-toc": "1.2.0", - "markdownlint-cli": "0.37.0" + "markdownlint-cli": "0.37.0", + "prettier": "3.1.1" } }, "node_modules/@financial-times/origami-service-makefile": { @@ -2050,6 +2051,21 @@ "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", "dev": true }, + "node_modules/prettier": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -4329,6 +4345,12 @@ "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", "dev": true }, + "prettier": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", + "dev": true + }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", diff --git a/package.json b/package.json index 95b611e..4a4db71 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "github-label-sync": "2.3.1", "markdown-link-check": "3.11.2", "markdown-toc": "1.2.0", - "markdownlint-cli": "0.37.0" + "markdownlint-cli": "0.37.0", + "prettier": "3.1.1" } }