Skip to content

Commit 3e80e76

Browse files
authored
chore: improvisasi unittesting workflow (#112)
* chore: improvisasi unittesting workflow Signed-off-by: slowy07 <[email protected]> * fix: warning codacy yang dimana kode python resiko command injection Signed-off-by: slowy07 <[email protected]> --------- Signed-off-by: slowy07 <[email protected]>
1 parent cd0de0a commit 3e80e76

File tree

2 files changed

+60
-43
lines changed

2 files changed

+60
-43
lines changed

.github/workflows/cpp.yml

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,9 @@ jobs:
4848
- name: Konfigurasi statik lint cpp
4949
run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
5050

51-
- name: lint file yang telah di commit
52-
shell: python
53-
run: |
54-
import os
55-
import sys
56-
import subprocess
57-
58-
print("Python {}.{}.{}".format(*sys.version_info))
59-
with open("git_diff.txt") as in_file:
60-
file_modifikasi = sorted(in_file.read().splitlines())
61-
print("{} file yang termodifikasi".format(len(file_modifikasi)))
62-
63-
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
64-
cpp_files = [file for file in file_modifikasi if file.lower().endswith(cpp_exts)]
65-
print(f"{len(cpp_files)} C++ file yang termodifikasi")
66-
if not cpp_files:
67-
sys.exit(0)
68-
69-
subprocess.run(["clang-tidy", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"],
70-
check=True, text=True, stderr=subprocess.STDOUT)
71-
subprocess.run(["clang-format", "-i", "-style=file", *cpp_files],
72-
check=True, text=True, stderr=subprocess.STDOUT)
73-
upper_files = [file for file in cpp_files if file != file.lower()]
74-
if upper_files:
75-
print(f"{len(upper_files)} files contain uppercase characters:")
76-
print("\n".join(upper_files) + "\n")
77-
space_files = [file for file in cpp_files if " " in file or "-" in file]
78-
if space_files:
79-
print(f"{len(space_files)} file mengandung spasi dan garis tengah:")
80-
print("\n".join(space_files) + "\n")
81-
nodir_files = [file for file in cpp_files if file.count(os.sep) != 1]
82-
if nodir_files:
83-
print(f"{len(nodir_files)} files are not in one and only one directory:")
84-
print("\n".join(nodir_files) + "\n")
85-
bad_files = len(upper_files + space_files + nodir_files)
86-
if bad_files:
87-
sys.exit(bad_files)
88-
51+
- name: cek lint hasil modifikasi
52+
shell: bash
53+
run: python3 .linter/file_linter.py
8954
- name: commit
9055
run: |
9156
git commit -am "chore: clang formatter and clang-tidy fixing ${GITHUB_SHA:8}" || true
@@ -95,13 +60,28 @@ jobs:
9560
name: cek compile
9661
runs-on: ${{ matrix.os }}
9762
needs: [TestingUtama]
63+
permissions:
64+
pull-requests: write
9865
strategy:
9966
matrix:
10067
os: [ubuntu-latest, windows-latest, macOS-latest]
10168
steps:
102-
- uses: actions/checkout@v3
103-
with:
104-
submodules: true
105-
- run: cmake -B ./build -S .
106-
- run: cmake --build build
69+
- uses: actions/checkout@v4
70+
with:
71+
submodules: true
72+
- name: build cpp
73+
run: |
74+
cmake -B ./build -S .
75+
cmake --build build --parallel 4
76+
- name: tambah label jika fail
77+
uses: actions/github-script@v6
78+
if: ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'}}
79+
with:
80+
script: |
81+
github.rest.issue.addLabels({
82+
issue_number: context.issue.number,
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
labels: ['testing fail!']
86+
})
10787

.linter/file_linter.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
6+
with open("git_diff.txt") as in_file:
7+
modified_file: list = sorted(in_file.read().splitlines())
8+
print(f"{len(modified_file)} termodifikasi")
9+
10+
cpp_exts: tuple = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
11+
cpp_files: list = [file for file in modified_file if file.lower().endswith(cpp_exts)]
12+
print(f"{len(cpp_files)} yang termodifikasi")
13+
14+
if not cpp_files:
15+
sys.exit(0)
16+
17+
subprocess.run(["clang-tidy", "--fix", "-p=build", "--extra-arg=std=c+11", *cpp_files, "--"], check=True, text=True, stderr=subprocess.STDOUT, capture_output=True)
18+
subprocess.run(["clang-format", "-i", "-style=file", *cpp_files], check=True, text=True, stderr=subprocess.STDOUT, capture_output=True)
19+
20+
upper_files = [file for file in cpp_files if file != file.lower()]
21+
if upper_files:
22+
print(f"{len(upper_files)} file yang mengandung huruf besar")
23+
print("\n".join(upper_files) + "\n")
24+
25+
space_file = [file for file in cpp_files if " " in file or "-" in file]
26+
if space_file:
27+
print(f"{len(space_file)} file yang mengandung karakter spasi atau dash")
28+
print("\n".join(space_file) + "\n")
29+
30+
nodir_files = [file for file in cpp_files if file.count(os.sep) != 1]
31+
if nodir_files:
32+
print(f"{len(nodir_files)} file yang tidak ada dalam atau hanya satu dalam direktori")
33+
print("\n".join(nodir_files) + "\n")
34+
35+
bad_files = len(upper_files + space_file + nodir_files)
36+
if bad_files:
37+
sys.exit(bad_files)

0 commit comments

Comments
 (0)