Repository navigation
118 lines (105 loc) · 5.23 KB
/
Copy pathformat-code.yml
File metadata and controls
118 lines (105 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Format Code
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
jobs:
format-code:
name: Format Code
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Install Clang-Format 22
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
sudo apt-get install -y clang-format-22
sudo ln -sf /usr/bin/clang-format-22 /usr/bin/clang-format
- name: Run Clang-Format Lint
run: |
# 1. Register a GitHub Problem Matcher for native LLVM diagnostic strings
echo '{
"problemMatcher": [
{
"owner": "clang-format-native",
"pattern": [
{
"regexp": "^([^:]+):(\\d+):(\\d+):\\s+(warning|error):\\s+(.+)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
]
}
]
}' > .github/cf-matcher.json
echo "::add-matcher::.github/cf-matcher.json"
# 2. Gather all matching source files. The find skips hidden directories such as .git.
#
# The list omits build_opt.h. It has the .h suffix, but it is an Arduino build-options file
# (a list of -D compiler flags, and not C++). The Arduino toolchain fixes its name.
#
# .c is in the list, because src/ is C11 and its implementation files are .c.
#
# The IDF component manager downloads managed_components/ into an example. It is
# third-party source from a vendor, and this project does not style it. Git ignores it.
# Thus a checkout restores it unformatted, and a local run cannot change that.
FILES=$(find . -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.ino" \) -not -path "*/.*" -not -path "*/managed_components/*" -not -name "build_opt.h")
# 3. An empty repository has no files to check.
if [ -z "$FILES" ]; then
echo "No source files found matching (.c, .cpp, .h, .ino). Skipping check."
exit 0
fi
# 4. Run the dry-run style audit over all files.
#
# ```
# --style=file finds the .clang-format rules in the directories above each file
# --dry-run computes the format and writes nothing
# --Werror exits 1 when a file breaks a style rule
# ```
echo "$FILES" | xargs clang-format --style=file --dry-run --Werror
- name: Python formatting (Black)
# The Python files that generate, check and measure the C sources have the same style gate
# as the C sources. Sonar also reads this tree. The line length comes from [tool.black] in
# pyproject.toml. Thus local runs and CI agree.
run: |
python3 -m pip install --quiet black
git ls-files '*.py' | xargs python3 -m black --check --diff
# Shell has the same gate: the scripts, and the two git hooks. The hooks are shell with no
# extension, and thus no glob finds them, and the step below names them. The scripts use
# -i 4 -ci. The flag -d prints the diff and exits 1. The step pins the version, because a
# different shfmt gives a different format, and CI must agree with `tools/harness.py ci fmt`.
- name: Install shfmt
run: |
curl -fsSL -o /tmp/shfmt \
https://github.com/mvdan/sh/releases/download/v3.13.1/shfmt_v3.13.1_linux_amd64
sudo install -m 755 /tmp/shfmt /usr/local/bin/shfmt
- name: Shell formatting (shfmt)
run: |
shfmt -i 4 -ci -d $(git ls-files '*.sh') \
tools/git-hooks/pre-commit tools/git-hooks/post-commit
# Every src/ guard, through the single CI entry point. `ci.py check` runs the default set, and
# prints ok/FAIL for each guard. Thus a failure still names itself. `ci.py list` shows the rest.
#
# ```
# owned_context mutable state lives in one owned <Name>Ctx, not ambient globals
# test_coverage the build_src_filter of an env names every src/ TU
# src_banned no construct that docs/SRCBANNED.md bans
# duplicate_symbols no symbol that two src/ files define (Arduino compiles all of src/)
# frame_specs the declared length of every PROTOCORE_FK_LIT matches its string
# coverage_xml test/coverage.xml satisfies the SonarQube generic format
# version_sites every file that prints the version is in .bumpversion.cfg
# ```
- name: src/ guards (ci.py check)
run: python3 -m tools.ci_tooling.ci check
- name: Crypto KAT vectors up to date (generated .inc matches vendored JSON)
# The file test/unit/src/crypto/mac/test_crypto_kat/kat_data.inc comes from the vendored external
# vectors in test/vectors/*.json. Regenerate, and fail if the committed table drifted from its source.
run: |
python3 -m tools.crypto.gen_crypto_vectors
git diff --exit-code test/unit/src/crypto/mac/test_crypto_kat/kat_data.inc