2021-11-14 06:53:37 +08:00
|
|
|
name: Compliance Checks
|
2020-06-08 23:58:14 +08:00
|
|
|
|
2024-07-12 01:25:34 +08:00
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
types:
|
|
|
|
- edited
|
|
|
|
- opened
|
|
|
|
- reopened
|
|
|
|
- synchronize
|
2020-06-08 23:58:14 +08:00
|
|
|
|
|
|
|
jobs:
|
2021-11-14 06:53:37 +08:00
|
|
|
check_compliance:
|
2023-03-18 18:11:12 +08:00
|
|
|
runs-on: ubuntu-22.04
|
2020-06-08 23:58:14 +08:00
|
|
|
name: Run compliance checks on patch series (PR)
|
|
|
|
steps:
|
2021-01-05 06:28:33 +08:00
|
|
|
- name: Update PATH for west
|
|
|
|
run: |
|
|
|
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
|
|
|
2020-06-08 23:58:14 +08:00
|
|
|
- name: Checkout the code
|
2024-01-27 12:26:39 +08:00
|
|
|
uses: actions/checkout@v4
|
2021-01-05 06:28:33 +08:00
|
|
|
with:
|
2021-01-13 11:27:48 +08:00
|
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
fetch-depth: 0
|
2020-06-08 23:58:14 +08:00
|
|
|
|
2024-04-29 21:49:26 +08:00
|
|
|
- name: Set up Python
|
|
|
|
uses: actions/setup-python@v5
|
|
|
|
with:
|
|
|
|
python-version: 3.11
|
|
|
|
|
2020-06-08 23:58:14 +08:00
|
|
|
- name: cache-pip
|
2024-01-27 12:26:39 +08:00
|
|
|
uses: actions/cache@v4
|
2020-06-08 23:58:14 +08:00
|
|
|
with:
|
|
|
|
path: ~/.cache/pip
|
2023-10-30 16:56:59 +08:00
|
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('.github/workflows/compliance.yml') }}
|
2020-06-08 23:58:14 +08:00
|
|
|
|
|
|
|
- name: Install python dependencies
|
|
|
|
run: |
|
|
|
|
pip3 install setuptools
|
|
|
|
pip3 install wheel
|
2024-09-11 00:00:00 +08:00
|
|
|
pip3 install python-magic lxml junitparser gitlint pylint pykwalify yamllint clang-format unidiff sphinx-lint
|
2020-06-08 23:58:14 +08:00
|
|
|
pip3 install west
|
|
|
|
|
2021-01-05 06:28:33 +08:00
|
|
|
- name: west setup
|
2021-02-03 21:37:44 +08:00
|
|
|
env:
|
|
|
|
BASE_REF: ${{ github.base_ref }}
|
2021-01-05 06:28:33 +08:00
|
|
|
run: |
|
2021-02-03 21:37:44 +08:00
|
|
|
git config --global user.email "you@example.com"
|
|
|
|
git config --global user.name "Your Name"
|
|
|
|
git remote -v
|
2022-11-29 22:43:52 +08:00
|
|
|
# Ensure there's no merge commits in the PR
|
|
|
|
[[ "$(git rev-list --merges --count origin/${BASE_REF}..)" == "0" ]] || \
|
|
|
|
(echo "::error ::Merge commits not allowed, rebase instead";false)
|
2021-02-03 21:37:44 +08:00
|
|
|
git rebase origin/${BASE_REF}
|
2024-09-17 15:39:16 +08:00
|
|
|
git clean -f -d
|
2021-02-03 21:37:44 +08:00
|
|
|
# debug
|
|
|
|
git log --pretty=oneline | head -n 10
|
2021-01-05 06:28:33 +08:00
|
|
|
west init -l . || true
|
2024-01-24 09:59:52 +08:00
|
|
|
west config manifest.group-filter -- +ci,-optional
|
2023-10-27 00:27:15 +08:00
|
|
|
west update -o=--depth=1 -n 2>&1 1> west.update.log || west update -o=--depth=1 -n 2>&1 1> west.update2.log
|
2021-01-05 06:28:33 +08:00
|
|
|
|
2024-07-12 01:25:34 +08:00
|
|
|
- name: Check for PR description
|
|
|
|
if: ${{ github.event.pull_request.body == '' }}
|
|
|
|
continue-on-error: true
|
|
|
|
id: pr_description
|
|
|
|
run: |
|
|
|
|
echo "Pull request description cannot be empty."
|
|
|
|
exit 1
|
|
|
|
|
2020-06-08 23:58:14 +08:00
|
|
|
- name: Run Compliance Tests
|
2021-01-20 21:46:47 +08:00
|
|
|
continue-on-error: true
|
2020-06-08 23:58:14 +08:00
|
|
|
id: compliance
|
|
|
|
env:
|
|
|
|
BASE_REF: ${{ github.base_ref }}
|
|
|
|
run: |
|
|
|
|
export ZEPHYR_BASE=$PWD
|
2021-01-13 11:27:48 +08:00
|
|
|
# debug
|
|
|
|
ls -la
|
|
|
|
git log --pretty=oneline | head -n 10
|
2022-09-15 04:23:15 +08:00
|
|
|
# Increase rename limit to allow for large PRs
|
|
|
|
git config diff.renameLimit 10000
|
2022-11-21 19:19:16 +08:00
|
|
|
./scripts/ci/check_compliance.py --annotate -e KconfigBasic \
|
2022-11-10 23:02:09 +08:00
|
|
|
-c origin/${BASE_REF}..
|
2020-06-08 23:58:14 +08:00
|
|
|
|
|
|
|
- name: upload-results
|
2024-01-27 12:26:39 +08:00
|
|
|
uses: actions/upload-artifact@v4
|
2023-01-03 19:23:56 +08:00
|
|
|
continue-on-error: true
|
2020-06-08 23:58:14 +08:00
|
|
|
with:
|
|
|
|
name: compliance.xml
|
|
|
|
path: compliance.xml
|
|
|
|
|
|
|
|
- name: check-warns
|
|
|
|
run: |
|
2021-01-20 21:46:47 +08:00
|
|
|
if [[ ! -s "compliance.xml" ]]; then
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
2024-06-27 17:52:52 +08:00
|
|
|
warns=("ClangFormat")
|
2022-11-21 19:19:16 +08:00
|
|
|
files=($(./scripts/ci/check_compliance.py -l))
|
2024-06-27 17:52:52 +08:00
|
|
|
|
2022-11-21 19:19:16 +08:00
|
|
|
for file in "${files[@]}"; do
|
|
|
|
f="${file}.txt"
|
|
|
|
if [[ -s $f ]]; then
|
2024-06-27 17:52:52 +08:00
|
|
|
results=$(cat $f)
|
|
|
|
results="${results//'%'/'%25'}"
|
|
|
|
results="${results//$'\n'/'%0A'}"
|
|
|
|
results="${results//$'\r'/'%0D'}"
|
|
|
|
|
|
|
|
if [[ "${warns[@]}" =~ "${file}" ]]; then
|
|
|
|
echo "::warning file=${f}::$results"
|
|
|
|
else
|
|
|
|
echo "::error file=${f}::$results"
|
|
|
|
exit=1
|
|
|
|
fi
|
2020-12-18 20:15:11 +08:00
|
|
|
fi
|
|
|
|
done
|
2020-06-08 23:58:14 +08:00
|
|
|
|
2021-12-03 17:40:55 +08:00
|
|
|
if [ "${exit}" == "1" ]; then
|
2024-07-12 01:25:34 +08:00
|
|
|
echo "Compliance error, check for error messages in the \"Run Compliance Tests\" step"
|
|
|
|
echo "You can run this step locally with the ./scripts/ci/check_compliance.py script."
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${{ steps.pr_description.outcome }}" == "failure" ]; then
|
|
|
|
echo "PR description cannot be empty"
|
2020-06-08 23:58:14 +08:00
|
|
|
exit 1;
|
|
|
|
fi
|