Skip to content

Commit

Permalink
Updated scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rishikeshsreehari committed Nov 20, 2024
1 parent 8ca9fee commit 0a8a0be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
8 changes: 4 additions & 4 deletions data/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": "24.296.F.2011",
"PushCount": 296,
"LastCommitLong": "2a989431d34f3b26362300c533594a1fa6a801a3",
"LastCommitShort": "2a98943"
"Version": "24.297.F.2011",
"PushCount": 297,
"LastCommitLong": "22c0cc8bd6a86e0275dc4704320abd1ab2328667",
"LastCommitShort": "22c0cc8"
}
36 changes: 25 additions & 11 deletions scripts/post_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
import json
import subprocess
import sys
from pathlib import Path

# Check for recursion
if os.environ.get('POST_COMMIT_RUNNING') == '1':
print("Skipping recursive post-commit hook")
sys.exit(0)
VERSION_FILE = "data/version.json"
LOCK_FILE = ".git/post-commit.lock"

# Set flag to prevent recursion
os.environ['POST_COMMIT_RUNNING'] = '1'
def check_lock():
"""Check if lock exists and is still valid"""
if os.path.exists(LOCK_FILE):
print("Lock file exists, skipping post-commit hook")
return True
return False

VERSION_FILE = "data/version.json"
def create_lock():
"""Create lock file"""
Path(LOCK_FILE).touch()

def remove_lock():
"""Remove lock file"""
if os.path.exists(LOCK_FILE):
os.remove(LOCK_FILE)

def get_git_hashes():
"""Get the latest git commit hashes (long and short)."""
Expand All @@ -28,7 +38,12 @@ def get_git_hashes():

def update_commit_hashes():
"""Update the commit hashes in version.json after commit."""
if check_lock():
return

try:
create_lock()

with open(VERSION_FILE, "r") as f:
data = json.load(f)

Expand All @@ -51,11 +66,10 @@ def update_commit_hashes():

except Exception as e:
print(f"Error updating commit hashes: {e}")
finally:
remove_lock()

if __name__ == "__main__":
print("Starting post-commit hook...")
update_commit_hashes()
print("Post-commit hook completed")

# Clear the environment variable
os.environ.pop('POST_COMMIT_RUNNING', None)
print("Post-commit hook completed")

0 comments on commit 0a8a0be

Please sign in to comment.