-
Notifications
You must be signed in to change notification settings - Fork 492
182 lines (163 loc) · 5.84 KB
/
compliance_check.yml
File metadata and controls
182 lines (163 loc) · 5.84 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
name: Compliance check
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
jobs:
style_check:
name: Coding style
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Dependencies
shell: bash
run: |
python -m pip install clang-format
- name: Check label
id: label_check
uses: actions/github-script@v7
with:
script: |
const labelName = 'skip-style-check';
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});
const hasLabel = labels.data.some(label => label.name === labelName);
core.setOutput('skip', hasLabel);
- name: check style
if: steps.label_check.outputs.skip != 'true'
shell: bash
run: |
set +e
INFO_URL="https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md"
GIT_BASE=$(git merge-base origin/master HEAD)
git diff -U0 "$GIT_BASE"...HEAD > diff.patch
clang-format-diff.py -p1 -style=file < diff.patch > clang-fmt.patch
if [ -s clang-fmt.patch ]; then
echo "Code formatting issues found:"
cat clang-fmt.patch
echo ""
echo "For formatting guidelines, see:"
echo " $INFO_URL"
exit 1
else
echo "All good, no formatting issues."
fi
- name: Skip style-check if label present
if: steps.label_check.outputs.skip == 'true'
run: echo "Skipping style check because 'skip-style-check' label is present."
style_license:
name: Licensing
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Dependencies
shell: bash
run: |
mkdir repos
git clone --depth=1 https://github.com/apache/mynewt-core repos/apache-mynewt-core
wget https://archive.apache.org/dist/creadur/apache-rat-0.17/apache-rat-0.17-bin.tar.gz
tar zxf apache-rat-0.17-bin.tar.gz apache-rat-0.17/apache-rat-0.17.jar
mv apache-rat-0.17/apache-rat-0.17.jar apache-rat.jar
- name: Check licensing
shell: bash
run: |
./repos/apache-mynewt-core/.github/check_license.py
style_doxygen:
name: Doxygen Style
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y doxygen graphviz
- name: Check Doxygen
shell: bash
run: |
.github/check_doxygen.py
commits-check:
name: Check commit messages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Validate commit message style
shell: bash
run: |
set -e
has_errors=0
COMMIT_URL="https://cwiki.apache.org/confluence/display/MYNEWT/Contributing+to+Apache+Mynewt"
# Determine commit range for PR or fallback to origin/master
if [ -n "${GITHUB_BASE_REF}" ]; then
base_ref="origin/${GITHUB_BASE_REF}"
else
base_ref="origin/master"
fi
base_commit=$(git merge-base HEAD ${base_ref})
echo "Checking commits from ${base_commit} to HEAD"
for commit in $(git rev-list --no-merges ${base_commit}..HEAD); do
short_sha=$(git rev-parse --short=7 $commit)
subject=$(git log -1 --pretty=format:%s $commit)
body=$(git log -1 --pretty=format:%b $commit)
if [ ${#subject} -gt 72 ]; then
echo "Commit $short_sha subject too long (${#subject} > 72):"
echo "$subject"
has_errors=1
fi
if [[ "$subject" != *:* ]]; then
echo "Commit $short_sha subject missing colon (e.g. 'subsystem: msg')"
echo "$subject"
has_errors=1
fi
if [ -z "$body" ]; then
echo "Commit $short_sha body is missing"
has_errors=1
else
line_num=0
while IFS= read -r line; do
line_num=$((line_num + 1))
if [ ${#line} -gt 72 ]; then
echo "Commit $short_sha body line $line_num too long (${#line} > 72):"
echo "$line"
has_errors=1
fi
done <<< "$body"
fi
echo ""
done
if [ "$has_errors" -eq 1 ]; then
echo "::error::Commit message check failed."
echo "For contributing guidelines, see:"
echo " $COMMIT_URL"
exit 1
else
echo "All commit messages pass style rules."
fi