Skip to content

Commit

Permalink
Merge pull request #250 from per1234/clangformat-config
Browse files Browse the repository at this point in the history
Host standardized ClangFormat configuration file
  • Loading branch information
per1234 authored Jul 26, 2022
2 parents 44f1951 + c5f256f commit d9f73eb
Show file tree
Hide file tree
Showing 2,667 changed files with 210,856 additions and 246 deletions.
4 changes: 2 additions & 2 deletions .codespellrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# See: https://github.com/codespell-project/codespell#using-a-config-file
[codespell]
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
ignore-words-list = licence,ot
skip = ./.git,./.licenses,__pycache__,node_modules,./go.mod,./go.sum,./package-lock.json,./poetry.lock,./yarn.lock
ignore-words-list = ba,licence,ot
skip = ./.git,./.licenses,__pycache__,node_modules,./other/clang-format-configuration/testdata/input/samples,./other/clang-format-configuration/testdata/golden,./other/clang-format-configuration/.clang-format,./go.mod,./go.sum,./package-lock.json,./poetry.lock,./yarn.lock
builtin = clear,informal,en-GB_to_en-US
check-filenames =
check-hidden =
2 changes: 2 additions & 0 deletions .ecrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"^\\.licenses[/\\\\]",
"__pycache__[/\\\\]",
"node_modules[/\\\\]",
"^other[/\\\\]clang-format-configuration[/\\\\]testdata[/\\\\]",
"^other[/\\\\]clang-format-configuration[/\\\\]\\.clang-format",
"^LICENSE\\.txt$",
"^poetry\\.lock$"
]
Expand Down
14 changes: 14 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-javascript/.eslintrc.yml
# See: https://eslint.org/docs/user-guide/configuring/
# The code style defined in this file is the official standardized style to be used in all Arduino projects and should
# not be modified.

extends:
- airbnb-base
- prettier
rules:
max-len:
- error
- code: 180
no-console: "off"
no-underscore-dangle: "off"
230 changes: 230 additions & 0 deletions .github/workflows/check-clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
name: Check ClangFormat Configuration

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:
push:
paths:
- ".github/workflows/check-clang-format.yml"
- "other/clang-format-configuration/scripts/convert-clang-format-configuration.js"
- "other/clang-format-configuration/testdata/**"
- "other/clang-format-configuration/.clang-format"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
pull_request:
paths:
- ".github/workflows/check-clang-format.yml"
- "other/clang-format-configuration/scripts/convert-clang-format-configuration.js"
- "other/clang-format-configuration/testdata/**"
- "other/clang-format-configuration/.clang-format"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
schedule:
# Run periodically to catch breakage caused by external changes.
- cron: "0 17 * * WED"
workflow_dispatch:
inputs:
clang-format-version:
description: ClangFormat version (leave empty for standard version)
type: string
default: ""
required: false
repository_dispatch:

jobs:
validate:
runs-on: ubuntu-latest

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

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

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

- name: Validate ClangFormat configuration files
run: task --silent clang-format:validate

check-config:
runs-on: ubuntu-latest

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

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

- name: Set environment variables
run: |
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
if [[ "${{ github.event.inputs.clang-format-version }}" == "" ]]; then
echo "CLANG_FORMAT_VERSION=$(task clang-format:get-version)" >> "$GITHUB_ENV"
else
echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV"
fi
echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV"
echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV"
- name: Download ClangFormat
id: download
uses: MrOctopus/download-asset-action@1.0
with:
repository: arduino/clang-static-binaries
tag: ${{ env.CLANG_FORMAT_VERSION }}
asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2
target: ${{ env.CLANG_FORMAT_INSTALL_PATH }}

- name: Install ClangFormat
run: |
cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}"
tar --extract --file="${{ steps.download.outputs.name }}"
# Add installation to PATH:
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH"
- name: Check ClangFormat configuration file
id: check
run: |
task \
--silent \
clang-format:check-config \
CLANG_FORMAT_VERSION="${{ env.CLANG_FORMAT_VERSION }}"
- name: Save effective configuration file to a workflow artifact
if: >
always() &&
steps.check.outcome == 'failure'
uses: actions/upload-artifact@v3
with:
path: ${{ env.WORKING_FOLDER }}/expected/.clang-format
if-no-files-found: error
name: config-output

check-output:
runs-on: ubuntu-latest

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

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

- name: Set environment variables
run: |
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
if [[ "${{ github.event.inputs.clang-format-version }}" == "" ]]; then
echo "CLANG_FORMAT_VERSION=$(task clang-format:get-version)" >> "$GITHUB_ENV"
else
echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV"
fi
echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV"
echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV"
- name: Download ClangFormat
id: download
uses: MrOctopus/download-asset-action@1.0
with:
repository: arduino/clang-static-binaries
tag: ${{ env.CLANG_FORMAT_VERSION }}
asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2
target: ${{ env.CLANG_FORMAT_INSTALL_PATH }}

- name: Install ClangFormat
run: |
cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}"
tar --extract --file="${{ steps.download.outputs.name }}"
# Add installation to PATH:
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH"
- name: Check ClangFormat output
id: check
run: |
task \
clang-format:check-output \
CLANG_FORMAT_VERSION="${{ env.CLANG_FORMAT_VERSION }}" \
WORKING_FOLDER="${{ env.WORKING_FOLDER }}"
- name: Save formatted test data to a workflow artifact
if: >
always() &&
steps.check.outcome == 'failure'
uses: actions/upload-artifact@v3
with:
path: ${{ env.WORKING_FOLDER }}/output
if-no-files-found: error
name: testdata-output

check-testdata:
runs-on: ubuntu-latest

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

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

- name: Check ClangFormat test data
run: task --silent clang-format:check-testdata

convert:
runs-on: ubuntu-latest

steps:
- name: Set environment variables
run: |
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
echo "CONVERSION_OUTPUT_PATH=${{ runner.temp }}/clang-format-js-object.txt" >> "$GITHUB_ENV"
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

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

- name: Convert the ClangFormat configuration
run: |
task \
--silent \
clang-format:convert \
OUTPUT_PATH="${{ env.CONVERSION_OUTPUT_PATH }}"
- name: Save conversion to a workflow artifact
uses: actions/upload-artifact@v3
with:
path: ${{ env.CONVERSION_OUTPUT_PATH }}
if-no-files-found: error
name: javascript-configuration-object
49 changes: 49 additions & 0 deletions .github/workflows/check-eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Check ESLint Configuration

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:
push:
paths:
- ".github/workflows/check-eslint.yml"
- "workflow-templates/assets/check-javascript/.eslintrc.yml"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
pull_request:
paths:
- ".github/workflows/check-eslint.yml"
- "workflow-templates/assets/check-javascript/.eslintrc.yml"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
validate:
runs-on: ubuntu-latest

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

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

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

- name: Validate workflows
run: task --silent eslint:validate
54 changes: 54 additions & 0 deletions .github/workflows/check-javascript-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-javascript-task.md
name: Check JavaScript

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:
push:
paths:
- ".github/workflows/check-javascript-task.ya?ml"
- ".eslintignore"
- "**/.eslintrc*"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "**.jsx?"
pull_request:
paths:
- ".github/workflows/check-javascript-task.ya?ml"
- ".eslintignore"
- "**/.eslintrc*"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "**.jsx?"
workflow_dispatch:
repository_dispatch:

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest

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

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

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

- name: Lint
run: task js:lint
2 changes: 2 additions & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.licenses/
__pycache__/
node_modules/
/other/clang-format-configuration/testdata/golden/samples/
/other/clang-format-configuration/testdata/input/samples/
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.licenses/
__pycache__/
node_modules/
/other/clang-format-configuration/testdata/golden/samples/
/other/clang-format-configuration/testdata/input/samples/
/other/clang-format-configuration/.clang-format
1 change: 1 addition & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ yaml-files:

ignore: |
/.git/
/other/clang-format-configuration/.clang-format
__pycache__/
node_modules/
Loading

0 comments on commit d9f73eb

Please sign in to comment.