-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add githook script to alert on changes that require re-installs #26
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,9 +274,12 @@ format: ## Run black and isort code formatter | |
format-modified: ## Run black and isort code formatter on modified files | ||
($(VENV_RUN); python -m isort `git ls-files -m | grep '\.py$$' | xargs`; python -m black `git ls-files -m | grep '\.py$$' | xargs` ) | ||
|
||
init-precommit: ## install te pre-commit hook into your local git repository | ||
init-precommit: ## install the pre-commit hook into your local git repository | ||
($(VENV_RUN); pre-commit install) | ||
Comment on lines
+277
to
278
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: typo in comment: 'te' should be 'the' |
||
|
||
init-githooks: ## install all githooks into your local git repository | ||
($(VENV_RUN); pre-commit install -t pre-commit -t post-checkout -t post-merge) | ||
|
||
clean: ## Clean up (npm dependencies, downloaded infrastructure code, compiled Java classes) | ||
rm -rf .filesystem | ||
rm -rf localstack/dashboard/web/node_modules | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Git hook that checks if there's been any updates to a set of predefined files | ||
|
||
This is for example useful to be alerted if there might be a need to reinstall the project | ||
""" | ||
|
||
import os | ||
import subprocess | ||
|
||
from rich.console import Console | ||
|
||
c = Console() | ||
|
||
DISABLE_CHECKS_ENV_VAR = "GITHOOK_DISABLE_DEPS_CHECK" | ||
|
||
# basically anything that might lead to issues with an existing local setup | ||
files_to_watch = ["setup.py", "setup.cfg", "requirements.txt", "Makefile", "pyproject.toml"] | ||
|
||
# TODO: alert on rebase | ||
# TODO: alert on pull | ||
# TODO: compare providers | ||
# TODO: compare plugins | ||
|
||
|
||
if __name__ == "__main__": | ||
if os.environ.get(DISABLE_CHECKS_ENV_VAR, "0") == "1": | ||
exit(0) | ||
Comment on lines
+26
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Add a log message when checks are disabled to inform the user. |
||
|
||
envs = {k: v for k, v in os.environ.items() if k.startswith("PRE_COMMIT")} | ||
|
||
# checkout | ||
from_commit = envs.get("PRE_COMMIT_FROM_REF") | ||
to_commit = envs.get("PRE_COMMIT_TO_REF") | ||
|
||
if from_commit and to_commit: | ||
r = subprocess.run( | ||
["git", "diff", "--name-only", from_commit, to_commit], capture_output=True | ||
) | ||
Comment on lines
+35
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Use 'git diff --name-only' with '--no-renames' flag to avoid issues with renamed files. |
||
|
||
files = r.stdout.decode().splitlines() | ||
|
||
for file in files_to_watch: | ||
if file in files: | ||
c.print( | ||
f"[red]ATTENTION![/red] Found a change in file [red]{file}[/red] during the checkout." | ||
) | ||
c.print( | ||
f"\t>> show changes: [bold]git diff {from_commit[:8]}:{file} {to_commit[:8]}:{file}[/bold]\n" | ||
) | ||
Comment on lines
+42
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using a set for faster lookup of changed files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider setting
always_run: false
to improve performance, as the script likely doesn't need to run on every commit.