Repository: hpcaitech/ColossalAI

Issue:
[BUG]: Post-commit workflow does not work!
### 🐛 Describe the bug

Followed from this PR https://github.com/hpcaitech/ColossalAI/pull/3020.

https://github.com/hpcaitech/ColossalAI/blob/280fcdc4856e061688e3aba49c3b53427967fd7b/.github/workflows/post_commit.yml#L84-L85

The 'outputs' condition can be used only if the step or job has 'outputs'.
So the current workflow doesn't work and linting hasn't been done in a while.
It should be changed to use 'outcome'.

References
https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context

I'll create two PRs;
- [x] Fix post-commit workflow
- [ ] Run pre-commit for all lines that should be changed by lint

### Environment

_No response_


Discussion:

Resolving patch:
diff --git a/.github/workflows/scripts/example_checks/check_dispatch_inputs.py b/.github/workflows/scripts/example_checks/check_dispatch_inputs.py
--- a/.github/workflows/scripts/example_checks/check_dispatch_inputs.py
+++ b/.github/workflows/scripts/example_checks/check_dispatch_inputs.py
@@ -1,27 +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()
+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()
diff --git a/.github/workflows/scripts/example_checks/check_example_weekly.py b/.github/workflows/scripts/example_checks/check_example_weekly.py
--- a/.github/workflows/scripts/example_checks/check_example_weekly.py
+++ b/.github/workflows/scripts/example_checks/check_example_weekly.py
@@ -1,37 +1,37 @@
-import os
-
-
-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_name in file_list:
-        # Get the abs directory using os.path.join() and store into cur_path.
-        cur_path = os.path.join(path, file_name)
-        # Determine whether folder
-        if os.path.isdir(cur_path):
-            show_files(cur_path, all_files)
-        else:
-            all_files.append(cur_path)
-    return all_files
-
-
-def join(input_list, sep=None):
-    return (sep or ' ').join(input_list)
-
-
-def main():
-    contents = show_files('examples/', [])
-    all_loc = []
-    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) >= 4:
-            re_loc = '/'.join(split_loc[1:3])
-            if re_loc not in all_loc:
-                all_loc.append(re_loc)
-    print(all_loc)
-
-
-if __name__ == '__main__':
-    main()
+import os
+
+
+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_name in file_list:
+        # Get the abs directory using os.path.join() and store into cur_path.
+        cur_path = os.path.join(path, file_name)
+        # Determine whether folder
+        if os.path.isdir(cur_path):
+            show_files(cur_path, all_files)
+        else:
+            all_files.append(cur_path)
+    return all_files
+
+
+def join(input_list, sep=None):
+    return (sep or ' ').join(input_list)
+
+
+def main():
+    contents = show_files('examples/', [])
+    all_loc = []
+    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) >= 4:
+            re_loc = '/'.join(split_loc[1:3])
+            if re_loc not in all_loc:
+                all_loc.append(re_loc)
+    print(all_loc)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/.github/workflows/scripts/example_checks/detect_changed_example.py b/.github/workflows/scripts/example_checks/detect_changed_example.py
--- a/.github/workflows/scripts/example_checks/detect_changed_example.py
+++ b/.github/workflows/scripts/example_checks/detect_changed_example.py
@@ -1,24 +1,24 @@
-import argparse
-
-
-def main():
-    parser = argparse.ArgumentParser()
-    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-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('/'.join(loc.split("/")[1:3]))
-    # Output the result using print. Then the shell can get the values.
-    print(list(folder_need_check))
-
-
-if __name__ == '__main__':
-    main()
+import argparse
+
+
+def main():
+    parser = argparse.ArgumentParser()
+    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-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('/'.join(loc.split("/")[1:3]))
+    # Output the result using print. Then the shell can get the values.
+    print(list(folder_need_check))
+
+
+if __name__ == '__main__':
+    main()


Test patch:
diff --git a/.github/workflows/doc_test_on_pr.yml b/.github/workflows/doc_test_on_pr.yml
--- a/.github/workflows/doc_test_on_pr.yml
+++ b/.github/workflows/doc_test_on_pr.yml
@@ -71,7 +71,7 @@ jobs:
 
       - name: Checkout ColossalAI
         uses: actions/checkout@v3
-      
+
       - name: Install Doc Test Requirements
         run: |
           source activate pytorch