Skip to content

Commit c9dd641

Browse files
authored
Merge pull request #122 from per1234/check-yaml
Add infrastructure to lint YAML files
2 parents 71e88e7 + 401d68b commit c9dd641

File tree

7 files changed

+246
-5
lines changed

7 files changed

+246
-5
lines changed

.github/workflows/check-yaml-task.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-yaml-task.md
2+
name: Check YAML
3+
4+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
5+
on:
6+
create:
7+
push:
8+
paths:
9+
- ".python-version"
10+
- ".yamllint*"
11+
- "poetry.lock"
12+
- "pyproject.toml"
13+
# Source: https://github.com/ikatyang/linguist-languages/blob/master/data/YAML.json (used by Prettier)
14+
- "**/.clang-format"
15+
- "**/.clang-tidy"
16+
- "**/.gemrc"
17+
- "**/glide.lock"
18+
- "**.ya?ml*"
19+
- "**.mir"
20+
- "**.reek"
21+
- "**.rviz"
22+
- "**.sublime-syntax"
23+
- "**.syntax"
24+
pull_request:
25+
paths:
26+
- ".python-version"
27+
- ".yamllint*"
28+
- "poetry.lock"
29+
- "pyproject.toml"
30+
# Source: https://github.com/ikatyang/linguist-languages/blob/master/data/YAML.json (used by Prettier)
31+
- "**/.clang-format"
32+
- "**/.clang-tidy"
33+
- "**/.gemrc"
34+
- "**/glide.lock"
35+
- "**.ya?ml*"
36+
- "**.mir"
37+
- "**.reek"
38+
- "**.rviz"
39+
- "**.sublime-syntax"
40+
- "**.syntax"
41+
schedule:
42+
# Run periodically to catch breakage caused by external changes.
43+
- cron: "0 9 * * WED"
44+
workflow_dispatch:
45+
repository_dispatch:
46+
47+
jobs:
48+
run-determination:
49+
runs-on: ubuntu-latest
50+
outputs:
51+
result: ${{ steps.determination.outputs.result }}
52+
steps:
53+
- name: Determine if the rest of the workflow should run
54+
id: determination
55+
run: |
56+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
57+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
58+
if [[
59+
"${{ github.event_name }}" != "create" ||
60+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
61+
]]; then
62+
# Run the other jobs.
63+
RESULT="true"
64+
else
65+
# There is no need to run the other jobs.
66+
RESULT="false"
67+
fi
68+
69+
echo "result=$RESULT" >> $GITHUB_OUTPUT
70+
71+
check:
72+
name: ${{ matrix.configuration.name }}
73+
needs: run-determination
74+
if: needs.run-determination.outputs.result == 'true'
75+
runs-on: ubuntu-latest
76+
77+
strategy:
78+
fail-fast: false
79+
80+
matrix:
81+
configuration:
82+
- name: Generate problem matcher output
83+
# yamllint's "github" output type produces annotated diffs, but is not useful to humans reading the log.
84+
format: github
85+
# The other matrix job is used to set the result, so this job is configured to always pass.
86+
continue-on-error: true
87+
- name: Check formatting
88+
# yamllint's "colored" output type is most suitable for humans reading the log.
89+
format: colored
90+
continue-on-error: false
91+
92+
steps:
93+
- name: Checkout repository
94+
uses: actions/checkout@v3
95+
96+
- name: Install Python
97+
uses: actions/setup-python@v4
98+
with:
99+
python-version-file: .python-version
100+
101+
- name: Install Poetry
102+
run: |
103+
pipx install \
104+
--python "$(which python)" \
105+
poetry
106+
107+
- name: Install Task
108+
uses: arduino/setup-task@v1
109+
with:
110+
repo-token: ${{ secrets.GITHUB_TOKEN }}
111+
version: 3.x
112+
113+
- name: Check YAML
114+
continue-on-error: ${{ matrix.configuration.continue-on-error }}
115+
run: task yaml:lint YAMLLINT_FORMAT=${{ matrix.configuration.format }}

.github/workflows/test-integration.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,12 @@ jobs:
300300
jq \
301301
--null-input \
302302
--exit-status \
303-
--slurpfile generated "$reportPath" \
304-
--slurpfile golden "${{ env.TESTDATA_REPORTS_PATH }}/${{ needs.all-inputs.outputs.report-artifact-name }}/$(basename "$reportPath")" \
303+
--slurpfile \
304+
generated \
305+
"$reportPath" \
306+
--slurpfile \
307+
golden \
308+
"${{ env.TESTDATA_REPORTS_PATH }}/${{ needs.all-inputs.outputs.report-artifact-name }}/$(basename "$reportPath")" \
305309
'($generated|.[0].boards) == ($golden|.[0].boards)'
306310
) && (
307311
# Check the commit_hash value

.yamllint.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-yaml/.yamllint.yml
2+
# See: https://yamllint.readthedocs.io/en/stable/configuration.html
3+
# The code style defined in this file is the official standardized style to be used in all Arduino tooling projects and
4+
# should not be modified.
5+
# Note: Rules disabled solely because they are redundant to Prettier are marked with a "Prettier" comment.
6+
7+
rules:
8+
braces:
9+
level: error
10+
forbid: non-empty
11+
min-spaces-inside: -1 # Prettier
12+
max-spaces-inside: -1 # Prettier
13+
min-spaces-inside-empty: -1 # Prettier
14+
max-spaces-inside-empty: -1 # Prettier
15+
brackets:
16+
level: error
17+
forbid: non-empty
18+
min-spaces-inside: -1 # Prettier
19+
max-spaces-inside: -1 # Prettier
20+
min-spaces-inside-empty: -1 # Prettier
21+
max-spaces-inside-empty: -1 # Prettier
22+
colons: disable # Prettier
23+
commas: disable # Prettier
24+
comments: disable # Prettier
25+
comments-indentation: disable # Prettier
26+
document-end: disable # Prettier
27+
document-start: disable
28+
empty-lines: disable # Prettier
29+
empty-values: disable
30+
hyphens: disable # Prettier
31+
indentation: disable # Prettier
32+
key-duplicates: disable # Prettier
33+
key-ordering: disable
34+
line-length:
35+
level: warning
36+
max: 120
37+
allow-non-breakable-words: true
38+
allow-non-breakable-inline-mappings: true
39+
new-line-at-end-of-file: disable # Prettier
40+
new-lines: disable # Prettier
41+
octal-values:
42+
level: warning
43+
forbid-implicit-octal: true
44+
forbid-explicit-octal: false
45+
quoted-strings: disable
46+
trailing-spaces: disable # Prettier
47+
truthy:
48+
level: error
49+
allowed-values:
50+
- "true"
51+
- "false"
52+
- "on" # Used by GitHub Actions as a workflow key.
53+
check-keys: true
54+
55+
yaml-files:
56+
# Source: https://github.com/ikatyang/linguist-languages/blob/master/data/YAML.json (used by Prettier)
57+
- ".clang-format"
58+
- ".clang-tidy"
59+
- ".gemrc"
60+
- ".yamllint"
61+
- "glide.lock"
62+
- "*.yml"
63+
- "*.mir"
64+
- "*.reek"
65+
- "*.rviz"
66+
- "*.sublime-syntax"
67+
- "*.syntax"
68+
- "*.yaml"
69+
- "*.yaml-tmlanguage"
70+
- "*.yaml.sed"
71+
- "*.yml.mysql"
72+
73+
ignore: |
74+
/.git/
75+
__pycache__/
76+
node_modules/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[![Check Taskfiles status](https://github.com/arduino/compile-sketches/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-taskfiles.yml)
1212
[![Check ToC status](https://github.com/arduino/compile-sketches/actions/workflows/check-toc-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-toc-task.yml)
1313
[![Check Workflows status](https://github.com/arduino/compile-sketches/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-workflows-task.yml)
14+
[![Check YAML status](https://github.com/arduino/compile-sketches/actions/workflows/check-yaml-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-yaml-task.yml)
1415
[![Spell Check status](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml)
1516
[![Sync Labels status](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml)
1617
[![Test Python status](https://github.com/arduino/compile-sketches/actions/workflows/test-python-poetry-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/test-python-poetry-task.yml)

Taskfile.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tasks:
1919
- task: npm:validate
2020
- task: python:lint
2121
- task: python:test
22+
- task: yaml:lint
2223

2324
fix:
2425
desc: Make automated corrections to the project's files
@@ -474,3 +475,13 @@ tasks:
474475
else
475476
echo "{{.RAW_PATH}}"
476477
fi
478+
479+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-yaml-task/Taskfile.yml
480+
yaml:lint:
481+
desc: Check for problems with YAML files
482+
deps:
483+
- task: poetry:install-deps
484+
vars:
485+
POETRY_GROUPS: dev
486+
cmds:
487+
- poetry run yamllint --format {{default "colored" .YAMLLINT_FORMAT}} .

poetry.lock

Lines changed: 36 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pytest = "7.2.2"
2222
pytest-mock = "3.10.0"
2323
flake8 = "6.0.0"
2424
pep8-naming = "0.13.3"
25+
yamllint = "1.30.0"
2526

2627
[tool.poetry.group.external]
2728
# Provided only for use by boards platforms

0 commit comments

Comments
 (0)