Skip to content

Commit

Permalink
chore:Worflow to find delete statement in sql file
Browse files Browse the repository at this point in the history
  • Loading branch information
rnithinpaladin committed Feb 5, 2024
1 parent 3b1450f commit 6fe89dd
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/mysqldeletecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ jobs:
with:
fetch-depth: 0 # fetch the entire history

- name: Check for DELETE statements in changed files
- name: Check for DELETE statements in commit
id: check
run: |
FILES=$(git diff --name-only HEAD HEAD~1)
for FILE in $FILES
CHANGED_SQL_FILES=$(git diff --name-only HEAD^ HEAD | grep '\.sql$')
for FILE in $CHANGED_SQL_FILES
do
if [[ $FILE == *.sql ]]
ADDED_LINES=$(git diff HEAD^ HEAD -- $FILE | grep '^+' | grep -v '++')
if echo "$ADDED_LINES" | grep -q 'DELETE'
then
if grep -q 'DELETE' "$FILE"
then
echo "::set-output name=delete_found::true"
break
fi
echo "::set-output name=delete_found::true"
break
fi
done
Expand All @@ -36,9 +34,9 @@ jobs:
uses: actions/github-script@v5
with:
script: |
github.issues.createComment({
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '⚠️ DELETE statement found in SQL files.'
body: '⚠️ DELETE statement found in the changes of SQL files.'
})

0 comments on commit 6fe89dd

Please sign in to comment.