Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c11df1f

Browse files
committed
Add sync-identical-files.py
1 parent e9a8afe commit c11df1f

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

.github/workflows/sync_files.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Check synchronized files
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
sync:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
submodules: true
16+
- name: Check synchronized files
17+
run: scripts/sync-identical-files.py

scripts/identical-files.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

scripts/sync-identical-files.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
# Due to various technical limitations, we sometimes have files that need to be
4+
# kept identical in the repository. This script loads a database of such
5+
# files and can perform two functions: check whether they are still identical,
6+
# and overwrite the others with a master copy if needed.
7+
# The script that does the actual work is `sync-files.py`, which lives in the `codeql` submodule.
8+
import sys
9+
import os
10+
11+
sys.path.append(os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../codeql/config')))
12+
13+
import importlib
14+
syncfiles = importlib.import_module('sync-files')
15+
16+
def chdir_repo_root():
17+
root_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
18+
os.chdir(root_path)
19+
20+
def sync_identical_files():
21+
if len(sys.argv) == 1:
22+
master_file_picker = lambda files: None
23+
elif len(sys.argv) == 2:
24+
if sys.argv[1] == "--latest":
25+
master_file_picker = syncfiles.choose_latest_file
26+
elif os.path.isfile(sys.argv[1]):
27+
master_file_picker = lambda files: syncfiles.choose_master_file(sys.argv[1], files)
28+
else:
29+
raise Exception("File not found")
30+
else:
31+
raise Exception("Bad command line or file not found")
32+
chdir_repo_root()
33+
syncfiles.load_if_exists('.', 'scripts/identical-files.json')
34+
for group_name, files in syncfiles.file_groups.items():
35+
syncfiles.check_group(group_name, files, master_file_picker, syncfiles.emit_local_error)
36+
37+
def main():
38+
sync_identical_files()
39+
40+
if syncfiles.local_error_count > 0:
41+
exit(1)
42+
else:
43+
print(__file__ +": All checks OK.")
44+
45+
if __name__ == "__main__":
46+
main()

0 commit comments

Comments
 (0)