Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync pre-commit strategy accross submodules #373

Merged
merged 4 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ defaults:
shell: bash

jobs:

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]

build-test:
name: Build and run tests
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ string(TIMESTAMP date "%Y-%m-%d %H:%M")
# Enable testing (-DTEST=ON flag, it is OFF by default)
include(Testing)

# Includes githooks, now using clang-format
include(GitHooks)

# Start compile
include(MacroRootDict)
add_subdirectory(source)
Expand Down
55 changes: 0 additions & 55 deletions cmake/GitHooks.cmake

This file was deleted.

46 changes: 46 additions & 0 deletions scripts/validatePreCommitConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This script should be run from the root of a submodule repository.
# It will check that the pre-commit config file matches the one in the framework repository (master branch).
# TODO: if a branch with the same name as the current branch exists in the framework repository, use that instead of master.
# It will also check other files related to the pre-commit such as .clang-format and .cmake-format.yaml.

import os


def check_files(base_directory, file_name) -> bool:
# Check that the pre-commit config file is the same as the one in the framework repository.
# If not, print a warning and exit with a non-zero exit code.
# base_directory: the directory where the file is located.
# file_names: a list of file names to check.
# Returns: True if the files are the same, False otherwise.
# Note: this function will exit the script if the files are not the same.

branch_name = "master"
github_prefix = (
f"https://raw.githubusercontent.com/rest-for-physics/framework/{branch_name}/"
)

with open(os.path.join(base_directory, file_name), "r") as f:
local_file = f.read()
# download file with curl (this way we avoid adding a python dependency, requests, since curl is installed)
reference_file = os.popen(f"curl -s {github_prefix}{file_name}").read()
if local_file != reference_file:
print(
f"WARNING: The file {file_name} is different from the one in the framework repository (branch={branch_name})."
)
return False

return True


if __name__ == "__main__":
# check pre-commit config file
files = [".pre-commit-config.yaml", ".clang-format", ".cmake-format.yaml"]

status = True # OK
for file in files:
status = check_files(base_directory=".", file_name=file) and status

if not status:
exit(1) # ERROR
else:
exit(0) # OK