|
29 | 29 | REFERENCE_DOC_DIR = SCRIPTS_DIR / ".." / "docs" / "dyn" |
30 | 30 | TEMP_DIR = SCRIPTS_DIR / "temp" |
31 | 31 |
|
32 | | -# Clear discovery documents and reference documents directory |
33 | | -shutil.rmtree(DISCOVERY_DOC_DIR, ignore_errors=True) |
34 | | -shutil.rmtree(REFERENCE_DOC_DIR, ignore_errors=True) |
35 | | - |
36 | | -# Clear temporary directory |
37 | | -shutil.rmtree(TEMP_DIR, ignore_errors=True) |
38 | | - |
39 | | -# Check out a fresh copy |
40 | | -subprocess.call(["git", "checkout", DISCOVERY_DOC_DIR]) |
41 | | -subprocess.call(["git", "checkout", REFERENCE_DOC_DIR]) |
42 | | - |
43 | | -# Snapshot current discovery artifacts to a temporary directory |
44 | | -with tempfile.TemporaryDirectory() as current_discovery_doc_dir: |
45 | | - shutil.copytree(DISCOVERY_DOC_DIR, current_discovery_doc_dir, dirs_exist_ok=True) |
46 | | - |
47 | | - # Download discovery artifacts and generate documentation |
48 | | - describe.generate_all_api_documents( |
49 | | - doc_destination_dir=REFERENCE_DOC_DIR, |
50 | | - artifact_destination_dir=DISCOVERY_DOC_DIR, |
51 | | - ) |
52 | | - |
53 | | - # Get a list of files changed using `git diff` |
54 | | - git_diff_output = subprocess.check_output( |
55 | | - [ |
56 | | - "git", |
57 | | - "diff", |
58 | | - "origin/main", |
59 | | - "--name-only", |
60 | | - "--", |
61 | | - DISCOVERY_DOC_DIR / "*.json", |
62 | | - REFERENCE_DOC_DIR / "*.html", |
63 | | - REFERENCE_DOC_DIR / "*.md", |
64 | | - ], |
65 | | - universal_newlines=True, |
66 | | - ) |
67 | | - |
68 | | - # Create lists of the changed files |
69 | | - all_changed_files = [ |
70 | | - pathlib.Path(file_name).name for file_name in git_diff_output.split("\n") |
71 | | - ] |
72 | | - json_changed_files = [file for file in all_changed_files if file.endswith(".json")] |
73 | | - |
74 | | - # Create temporary directory |
75 | | - pathlib.Path(TEMP_DIR).mkdir() |
76 | | - |
77 | | - # Analyze the changes in discovery artifacts using the changesummary module |
78 | | - changesummary.ChangeSummary( |
79 | | - DISCOVERY_DOC_DIR, current_discovery_doc_dir, TEMP_DIR, json_changed_files |
80 | | - ).detect_discovery_changes() |
81 | | - |
82 | | - # Write a list of the files changed to a file called `changed files` which will be used in the `createcommits.sh` script. |
83 | | - with open(TEMP_DIR / "changed_files", "w") as f: |
84 | | - f.writelines("\n".join(all_changed_files)) |
| 32 | + |
| 33 | +def main(): |
| 34 | + # Clear discovery documents and reference documents directory |
| 35 | + shutil.rmtree(DISCOVERY_DOC_DIR, ignore_errors=True) |
| 36 | + shutil.rmtree(REFERENCE_DOC_DIR, ignore_errors=True) |
| 37 | + |
| 38 | + # Clear temporary directory |
| 39 | + shutil.rmtree(TEMP_DIR, ignore_errors=True) |
| 40 | + |
| 41 | + # Check out a fresh copy |
| 42 | + subprocess.call(["git", "checkout", DISCOVERY_DOC_DIR]) |
| 43 | + subprocess.call(["git", "checkout", REFERENCE_DOC_DIR]) |
| 44 | + |
| 45 | + # Snapshot current discovery artifacts to a temporary directory |
| 46 | + with tempfile.TemporaryDirectory() as current_discovery_doc_dir: |
| 47 | + shutil.copytree( |
| 48 | + DISCOVERY_DOC_DIR, current_discovery_doc_dir, dirs_exist_ok=True |
| 49 | + ) |
| 50 | + |
| 51 | + # Download discovery artifacts and generate documentation |
| 52 | + describe.generate_all_api_documents( |
| 53 | + doc_destination_dir=REFERENCE_DOC_DIR, |
| 54 | + artifact_destination_dir=DISCOVERY_DOC_DIR, |
| 55 | + ) |
| 56 | + |
| 57 | + # Get a list of files changed using `git diff` |
| 58 | + git_diff_output = subprocess.check_output( |
| 59 | + [ |
| 60 | + "git", |
| 61 | + "diff", |
| 62 | + "origin/main", |
| 63 | + "--name-only", |
| 64 | + "--", |
| 65 | + DISCOVERY_DOC_DIR / "*.json", |
| 66 | + REFERENCE_DOC_DIR / "*.html", |
| 67 | + REFERENCE_DOC_DIR / "*.md", |
| 68 | + ], |
| 69 | + universal_newlines=True, |
| 70 | + ) |
| 71 | + |
| 72 | + # Create lists of the changed files |
| 73 | + all_changed_files = [ |
| 74 | + pathlib.Path(file_name).name for file_name in git_diff_output.split("\n") |
| 75 | + ] |
| 76 | + json_changed_files = [ |
| 77 | + file for file in all_changed_files if file.endswith(".json") |
| 78 | + ] |
| 79 | + |
| 80 | + # Create temporary directory |
| 81 | + pathlib.Path(TEMP_DIR).mkdir() |
| 82 | + |
| 83 | + # Analyze the changes in discovery artifacts using the changesummary module |
| 84 | + changesummary.ChangeSummary( |
| 85 | + DISCOVERY_DOC_DIR, current_discovery_doc_dir, TEMP_DIR, json_changed_files |
| 86 | + ).detect_discovery_changes() |
| 87 | + |
| 88 | + # Write a list of the files changed to a file called `changed files` which will be used in the `createcommits.sh` script. |
| 89 | + with open(TEMP_DIR / "changed_files", "w") as f: |
| 90 | + f.writelines("\n".join(all_changed_files)) |
| 91 | + |
| 92 | + |
| 93 | +if __name__ == "__main__": |
| 94 | + main() |
0 commit comments