[workflow] refactored the example check workflow (#2411)

* [workflow] refactored the example check workflow

* polish code

* polish code

* polish code

* polish code

* polish code

* polish code

* polish code

* polish code

* polish code

* polish code

* polish code
This commit is contained in:
Frank Lee
2023-01-10 11:26:19 +08:00
committed by GitHub
parent 8de8de9fa3
commit 8327932d2c
10 changed files with 113 additions and 92 deletions

View File

@@ -0,0 +1,27 @@
import argparse
import os
def check_inputs(input_list):
for path in input_list:
real_path = os.path.join('examples', path)
if not os.path.exists(real_path):
return False
return True
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--fileNameList', type=str, help="List of file names")
args = parser.parse_args()
name_list = args.fileNameList.split(",")
is_correct = check_inputs(name_list)
if is_correct:
print('success')
else:
print('failure')
if __name__ == '__main__':
main()

View File

@@ -5,9 +5,9 @@ def show_files(path, all_files):
# Traverse all the folder/file in current directory
file_list = os.listdir(path)
# Determine the element is folder or file. If file, pass it into list, if folder, recurse.
for file in file_list:
for file_name in file_list:
# Get the abs directory using os.path.join() and store into cur_path.
cur_path = os.path.join(path, file)
cur_path = os.path.join(path, file_name)
# Determine whether folder
if os.path.isdir(cur_path):
show_files(cur_path, all_files)
@@ -26,9 +26,8 @@ def main():
for file_loc in contents:
split_loc = file_loc.split('/')
# must have two sub-folder levels after examples folder, such as examples/images/vit is acceptable, examples/images/README.md is not, examples/requirements.txt is not.
if len(split_loc) - split_loc.index('examples') >= 3:
tmp_loc = split_loc[(split_loc.index('examples') + 1):(split_loc.index('examples') + 3)]
re_loc = join(tmp_loc, '/')
if len(split_loc) >= 4:
re_loc = '/'.join(split_loc[1:3])
if re_loc not in all_loc:
all_loc.append(re_loc)
print(all_loc)

View File

@@ -3,14 +3,19 @@ import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--fileNameList', type=str)
parser.add_argument('-f', '--fileNameList', type=str, help="The list of changed files")
args = parser.parse_args()
name_list = args.fileNameList.split(":")
folder_need_check = set()
for loc in name_list:
# Find only the sub-folder of 'example' folder
# Find only the sub-sub-folder of 'example' folder
# the examples folder structure is like
# - examples
# - area
# - application
# - file
if loc.split("/")[0] == "examples" and len(loc.split("/")) >= 4:
folder_need_check.add(loc.split("/")[1] + "/" + loc.split("/")[2])
folder_need_check.add('/'.join(loc.split("/")[1:3]))
# Output the result using print. Then the shell can get the values.
print(list(folder_need_check))

View File

@@ -1,23 +0,0 @@
import argparse
import os
def detect_correct(loc_li):
for loc in loc_li:
real_loc = 'examples/' + eval(loc)
if not os.path.exists(real_loc):
return -1
return 1
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--fileNameList', type=str)
args = parser.parse_args()
name_list = args.fileNameList.split(",")
result = detect_correct(name_list)
print(result)
if __name__ == '__main__':
main()