Skip to content

Commit

Permalink
Create token_consistency.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya0by0 committed Oct 20, 2024
1 parent 4968b3b commit 13e75ae
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/token_consistency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Check consistency of tokens.txt file

on: [push, pull_request]

jobs:
check_tokens:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Get previous tokens.txt version
run: |
git fetch origin main
git diff origin/main -- chebai/preprocessing/bin/smiles_token/tokens.txt > tokens_diff.txt || echo "No previous tokens.txt found"
- name: Check for deleted or added lines in tokens.txt
run: |
if [ -f tokens_diff.txt ]; then
# Check for deleted lines (lines starting with '-')
deleted_lines=$(grep '^-' tokens_diff.txt | grep -v '^---' | sed 's/^-//' || true)
if [ -n "$deleted_lines" ]; then
echo "Error: Lines have been deleted from tokens.txt. file"
echo -e "Deleted Lines: \n$deleted_lines"
exit 1
fi
# Check for added lines (lines starting with '+')
added_lines=$(grep '^+' tokens_diff.txt | grep -v '^+++' | sed 's/^+//' || true)
if [ -n "$added_lines" ]; then
# Count how many lines have been added
num_added_lines=$(echo "$added_lines" | wc -l)
# Get last `n` lines (equal to num_added_lines) of tokens.tx
last_lines=$(tail -n "$num_added_lines" chebai/preprocessing/bin/smiles_token/tokens.txt)
# Check if the added lines are at the end of the file
if [ "$added_lines" != "$last_lines" ]; then
# Find lines that were added but not appended at the end of the file
non_appended_lines=$(diff <(echo "$added_lines") <(echo "$last_lines") | grep '^<' | sed 's/^< //')
echo "Error: New lines have been added, but they are not at the end of tokens.txt."
echo -e "Added lines that are not at end of file: \n$non_appended_lines"
exit 1
fi
fi
if [ "$added_lines" == "" ]; then
echo "tokens.txt validation successful: No lines were deleted, and no new lines were added."
else
echo "tokens.txt validation successful: No lines were deleted, and new lines were correctly appended at the end."
fi
else
echo "No previous version of tokens.txt found."
fi

0 comments on commit 13e75ae

Please sign in to comment.