Skip to content

Commit

Permalink
feat: added pre-commit hooks to auto encrypt and stage lab_members.js…
Browse files Browse the repository at this point in the history
…on file when it is updated
  • Loading branch information
shanto268 committed Jul 27, 2024
1 parent e0dbd02 commit e9eab79
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ This project serves as a lab manager for the [Levenson-Falk Lab](https://dornsif
4. **Commit Encrypted Files to Repository:**
Commit and push the encrypted files (`*.enc`) to your repository.

5. Run the following command to set up Git hooks:

```bash
./scripts/setup-hooks.sh
```

### GitHub Actions Setup

1. **Create GitHub Secrets:**
Expand Down
23 changes: 23 additions & 0 deletions scripts/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Check if lab_members.json is staged for commit
if git diff --cached --name-only | grep -q 'lab_members.json'; then
echo "lab_members.json has changed. Encrypting the file..."

# Prompt for the secret key
read -sp "Enter encryption key: " SECRET_KEY
echo

# Encrypt lab_members.json
openssl aes-256-cbc -salt -a -e -in lab_members.json -out lab_members.json.enc -pass pass:$SECRET_KEY -pbkdf2

# Clear the secret key variable
unset SECRET_KEY

# Stage the encrypted file
git add lab_members.json.enc

# Notify the user
echo "lab_members.json has been encrypted and lab_members.json.enc has been staged for commit."
fi

8 changes: 8 additions & 0 deletions scripts/setup_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Copy hooks to .git/hooks
cp scripts/hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

echo "Git hooks installed."

0 comments on commit e9eab79

Please sign in to comment.