Merge pull request #96 from github/hvitved/codeql-submodule-sync

Add `github/codeql` submodule and functionality for synchronizing files
This commit is contained in:
Arthur Baars
2021-01-19 11:16:38 +01:00
committed by GitHub
5 changed files with 68 additions and 0 deletions

17
.github/workflows/sync_files.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
name: Check synchronized files
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Check synchronized files
run: scripts/sync-identical-files.py

3
.gitmodules vendored
View File

@@ -0,0 +1,3 @@
[submodule "codeql"]
path = codeql
url = https://github.com/github/codeql.git

1
codeql Submodule

Submodule codeql added at fc2fe6cccb

View File

@@ -0,0 +1 @@
{}

46
scripts/sync-identical-files.py Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env python3
# Due to various technical limitations, we sometimes have files that need to be
# kept identical in the repository. This script loads a database of such
# files and can perform two functions: check whether they are still identical,
# and overwrite the others with a master copy if needed.
# The script that does the actual work is `sync-files.py`, which lives in the `codeql` submodule.
import sys
import os
sys.path.append(os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../codeql/config')))
import importlib
syncfiles = importlib.import_module('sync-files')
def chdir_repo_root():
root_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
os.chdir(root_path)
def sync_identical_files():
if len(sys.argv) == 1:
master_file_picker = lambda files: None
elif len(sys.argv) == 2:
if sys.argv[1] == "--latest":
master_file_picker = syncfiles.choose_latest_file
elif os.path.isfile(sys.argv[1]):
master_file_picker = lambda files: syncfiles.choose_master_file(sys.argv[1], files)
else:
raise Exception("File not found")
else:
raise Exception("Bad command line or file not found")
chdir_repo_root()
syncfiles.load_if_exists('.', 'scripts/identical-files.json')
for group_name, files in syncfiles.file_groups.items():
syncfiles.check_group(group_name, files, master_file_picker, syncfiles.emit_local_error)
def main():
sync_identical_files()
if syncfiles.local_error_count > 0:
exit(1)
else:
print(__file__ +": All checks OK.")
if __name__ == "__main__":
main()