Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move check coding rule setting file to C2A user top #97

Merged
merged 9 commits into from
Sep 21, 2023
Merged
64 changes: 9 additions & 55 deletions .github/workflows/check_coding_rule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,17 @@ on:
pull_request:

jobs:
check_coding_rule:
runs-on: ubuntu-latest
check_coding_rule_v4:
strategy:
fail-fast: false
matrix:
example:
user:
- mobc
- subobc

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version-file: .github/workflows/.python-version
architecture: 'x64'
- name: setup
shell: bash
run: ./setup.sh
- name: check coding rule
id: check
shell: bash -e {0}
continue-on-error: true
working-directory: ./examples/${{ matrix.example }}/src
run: |
python ./src_core/script/ci/check_coding_rule.py ./src_core/script/ci/check_coding_rule.json | tee /tmp/coding-rule.log
status="${PIPESTATUS[0]}"
echo "status: ${status}"
echo "status=${status}" >> "$GITHUB_OUTPUT"
exit "${status}"

- name: install reviewdog
uses: reviewdog/[email protected]

- name: fix error log source file path
run: |
sed 's/.\/src_core\///g' < /tmp/coding-rule.log \
| > ./coding-rule.log \
sed 's/.\/src_user/examples\/${{ matrix.example }}\/src\/src_user/g'
cat ./coding-rule.log

- name: reviewdog(github-pr-review)
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
reviewdog \
-name 'check_coding_rule' \
-level error \
-fail-on-error=true \
-filter-mode=added \
-diff="git diff FETCH_HEAD" \
-reporter=github-pr-review \
-efm="%-GThe above files are invalid coding rule." \
-efm="%E%f: %l: %m" \
-efm="%Z%s" \
< coding-rule.log

- name: exit
shell: bash
run: |
exit $(( "${{ steps.check.outputs.status }}" ))
uses: arkedge/workflows-c2a/.github/workflows/[email protected]
with:
c2a_dir: examples/${{ matrix.user }}
c2a_custom_setup: |
cd ../..
pwd
./setup.sh
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
- example user についてはこの migration script のみで移行しているが,あらゆる C2A user の状況について考慮できているわけではないため,適宜対応が必要
- `hal`(旧 `IfWrapper`)のうち,古すぎるインターフェースを排除: [#23](https://github.com/arkedge/c2a-core/issues/23), [#25](https://github.com/arkedge/c2a-core/pull/25)
- 既に使われてしまっているものについては,各 C2A user で一旦雑に古いヘッダファイルを各々で持って対応可能(今後再設計する予定)
- `check_coding_rule.py` の設定ファイルである `check_coding_rule.json` の場所を C2A user のトップディレクトリに変更: [#97](https://github.com/arkedge/c2a-core/pull/97)
- 対応方法
- `Script/CI/check_coding_rule.json` ないし `script/ci/check_coding_rule.json` を C2A user のトップディレクトリに移動
- 設定ファイルから `c2a_root_dir` を削除
- 設定ファイル中のディレクトリの設定を C2A user のトップディレクトリからの相対パスに変更


### Enhancements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{
"c2a_root_dir" : "./",
"input_file_encoding" : "utf-8",
"target_dirs" : [
"src_core/",
"src_user/"
"src/src_core/",
"src/src_user/"
],
"ignore_dirs" : [
"src_core/examples",
"src_core/docs",
"src_core/script"
"src/src_core/examples",
"src/src_core/docs",
"src/src_core/script"
],
"ignore_files" : [
"src_user/tlm_cmd/telemetry_definitions.c"
"src/src_user/tlm_cmd/telemetry_definitions.c"
],
"ignore_rules" : [
],
Expand Down
40 changes: 40 additions & 0 deletions examples/subobc/check_coding_rule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"input_file_encoding" : "utf-8",
"target_dirs" : [
"src/src_core/",
"src/src_user/"
],
"ignore_dirs" : [
"src/src_core/examples",
"src/src_core/docs",
"src/src_core/script"
],
"ignore_files" : [
"src/src_user/tlm_cmd/telemetry_definitions.c"
],
"ignore_rules" : [
],
"comment_ignore_rules" : [
"以下を指定すると,該当ルールが無視される",
"comment",
"newline",
"eof",
"space",
"operator_space",
"preprocessor",
"include_guard"
],
"additional_type" : [
"TCP",
"CommonTlmCmdPacket",
"CommonTlmPacket",
"CommonCmdPacket",
"SpacePacket",
"TlmSpacePacket",
"CmdSpacePacket"
],
"comment_additional_type" : [
"FIXME: TCP はもう存在しないはずなので,どこかで消す",
"FIXME: CTCP, CTP, CCP については,整理が終わり次第,消して大丈夫になるはず"
]
}
15 changes: 10 additions & 5 deletions script/ci/check_coding_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,31 @@ def main():
print("WARNING: " + rule_name + " rule is ignored!!")
settings["check_funcs"] = check_funcs # ここだけ, settings に追記している

if not check_coding_rule(settings):
dname = os.path.dirname(setting_file_path)
if not dname:
dname = os.getcwd()
check_root_dir = dname + r"/"

if not check_coding_rule(check_root_dir, settings):
print("The above files are invalid coding rule.")
sys.exit(1)
print("Completed!")
sys.exit(0)


# True: OK, False: NG
def check_coding_rule(settings: dict) -> bool:
def check_coding_rule(check_root_dir: str, settings: dict) -> bool:
flag = True

target_dirs = []
for target_dir in settings["target_dirs"]:
target_dirs.append(settings["c2a_root_dir"] + target_dir)
target_dirs.append(check_root_dir + target_dir)
ignore_dirs = []
for ignore_dir in settings["ignore_dirs"]:
ignore_dirs.append(settings["c2a_root_dir"] + ignore_dir)
ignore_dirs.append(check_root_dir + ignore_dir)
ignore_files = []
for ignore_file in settings["ignore_files"]:
ignore_files.append(settings["c2a_root_dir"] + ignore_file)
ignore_files.append(check_root_dir + ignore_file)

preprocess_(target_dirs, ignore_dirs, ignore_files, settings)

Expand Down