diff --git a/.github/workflows/check_coding_rule.yml b/.github/workflows/check_coding_rule.yml index 83a314e9..52b73f0f 100644 --- a/.github/workflows/check_coding_rule.yml +++ b/.github/workflows/check_coding_rule.yml @@ -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/action-setup@v1.0.6 - - - 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/check-coding-rule-v4.yml@v4.3.0 + with: + c2a_dir: examples/${{ matrix.user }} + c2a_custom_setup: | + cd ../.. + pwd + ./setup.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index cd9ea5c9..d41e2564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/script/ci/check_coding_rule.json b/examples/mobc/check_coding_rule.json similarity index 81% rename from script/ci/check_coding_rule.json rename to examples/mobc/check_coding_rule.json index c55a06c9..5c9e1e79 100644 --- a/script/ci/check_coding_rule.json +++ b/examples/mobc/check_coding_rule.json @@ -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" : [ ], diff --git a/examples/subobc/check_coding_rule.json b/examples/subobc/check_coding_rule.json new file mode 100644 index 00000000..5c9e1e79 --- /dev/null +++ b/examples/subobc/check_coding_rule.json @@ -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 については,整理が終わり次第,消して大丈夫になるはず" + ] +} diff --git a/script/ci/check_coding_rule.py b/script/ci/check_coding_rule.py index aa453975..e1524db2 100644 --- a/script/ci/check_coding_rule.py +++ b/script/ci/check_coding_rule.py @@ -59,7 +59,12 @@ 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!") @@ -67,18 +72,18 @@ def main(): # 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)