Skip to content

Instantly share code, notes, and snippets.

@Dogacel
Created June 13, 2018 16:40
Show Gist options
  • Save Dogacel/d4c29ba50b46b76acfabfbaaefa84fb1 to your computer and use it in GitHub Desktop.
Save Dogacel/d4c29ba50b46b76acfabfbaaefa84fb1 to your computer and use it in GitHub Desktop.
Auto run bench for test commits on defenchess
#!/usr/bin/env python
import sys, os, subprocess
from sys import platform
subprocess_cmd = '/bin/sh'
if platform == "win32":
subprocess_cmd = 'C:/Windows/System32/bash.exe'
commit_msg_filepath = sys.argv[1]
with open(commit_msg_filepath, 'r') as fr:
first_line = fr.readline()
if "test_stc" in first_line:
with open(commit_msg_filepath, 'w') as fw:
proc = subprocess.Popen(subprocess_cmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
stdout, stderr = proc.communicate(b'make bench')
fw.write("test_stc:" + stdout.splitlines()[-2][8:].decode("utf-8") + first_line[8:])
@Dogacel
Copy link
Author

Dogacel commented Jun 13, 2018

Instructions:

  1. Open the Defenchess/.git/hooks folder
  2. Copy and paste the prepare-commit-msg file without changing the filename or extension
  3. chmod +x prepare-commit-msg
  4. Make sure you have python3 in your env and enjoy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment