From c1fed7ee47b62f98ac4a2052537abcf2eba731e3 Mon Sep 17 00:00:00 2001 From: per1234 Date: Wed, 28 Jul 2021 20:01:38 -0700 Subject: [PATCH] Add CI workflow to check general file formatting On every push, pull request, and periodically, check whether the repository's files are formatted according to .editorconfig. --- .ecrc | 8 +++ .../check-general-formatting-task.yml | 53 +++++++++++++++++++ README.md | 1 + Taskfile.yml | 13 +++++ 4 files changed, 75 insertions(+) create mode 100644 .ecrc create mode 100644 .github/workflows/check-general-formatting-task.yml diff --git a/.ecrc b/.ecrc new file mode 100644 index 00000000..b6366684 --- /dev/null +++ b/.ecrc @@ -0,0 +1,8 @@ +{ + "Exclude": [ + "LICENSE.txt", + "poetry.lock", + "^internal/rule/schema/schemadata/bindata.go$", + "^internal/rule/schema/testdata/bindata.go$" + ] +} diff --git a/.github/workflows/check-general-formatting-task.yml b/.github/workflows/check-general-formatting-task.yml new file mode 100644 index 00000000..c1460dd3 --- /dev/null +++ b/.github/workflows/check-general-formatting-task.yml @@ -0,0 +1,53 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-general-formatting-task.md +name: Check General Formatting + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to tools. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + echo "EC_INSTALL_PATH=${{ runner.temp }}/editorconfig-checker" >> "$GITHUB_ENV" + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Download latest editorconfig-checker release binary package + id: download + uses: MrOctopus/download-asset-action@1.0 + with: + repository: editorconfig-checker/editorconfig-checker + excludes: prerelease, draft + asset: linux-amd64.tar.gz + target: ${{ env.EC_INSTALL_PATH }} + + - name: Install editorconfig-checker + run: | + cd "${{ env.EC_INSTALL_PATH }}" + tar --extract --file="${{ steps.download.outputs.name }}" + # Give the binary a standard name + mv "${{ env.EC_INSTALL_PATH }}/bin/ec-linux-amd64" "${{ env.EC_INSTALL_PATH }}/bin/ec" + # Add installation to PATH: + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path + echo "${{ env.EC_INSTALL_PATH }}/bin" >> "$GITHUB_PATH" + + - name: Check formatting + run: task --silent general:check-formatting diff --git a/README.md b/README.md index 5cadd73e..df222601 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![Check Markdown status](https://github.com/arduino/arduino-lint/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-markdown-task.yml) [![Docs Status](https://github.com/arduino/arduino-lint/workflows/Publish%20documentation/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Publish+documentation) [![Codecov](https://codecov.io/gh/arduino/arduino-lint/branch/main/graph/badge.svg?token=nprqPQMbdh)](https://codecov.io/gh/arduino/arduino-lint) +[![Check General Formatting status](https://github.com/arduino/arduino-lint/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-general-formatting-task.yml) [![Check Certificates status](https://github.com/arduino/arduino-lint/actions/workflows/check-certificates.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-certificates.yml) **Arduino Lint** is a command line tool that checks for common problems in [Arduino](https://www.arduino.cc/) projects: diff --git a/Taskfile.yml b/Taskfile.yml index 4b5970d9..a7da6851 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -44,6 +44,7 @@ tasks: - task: python:check - task: docs:check - task: config:check + - task: general:check-formatting - task: check-spelling lint: @@ -60,6 +61,7 @@ tasks: cmds: - task: docs:check-formatting - task: config:check-formatting + - task: general:check-formatting format: desc: Format all files @@ -312,6 +314,17 @@ tasks: - npx {{ .PRETTIER }} --write "**/*.{yml,yaml}" - npx {{ .PRETTIER }} --write "**/*.json" + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml + general:check-formatting: + desc: Check basic formatting style of all files + cmds: + - | + if ! which ec &>/dev/null; then + echo "ec not found or not in PATH. Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation" + exit 1 + fi + - ec + check-spelling: desc: Check for commonly misspelled words cmds: