@@ -130,39 +130,46 @@ jobs:
130130 pr_no : ${{ github.event.pull_request.number }}
131131 GH_TOKEN : ${{ github.token }}
132132 run : |
133- echo "GitHub Token: $GH_TOKEN"
134-
133+
135134 # Fetch the latest changes from the main branch
136135 git fetch origin main
136+
137137 # Get the list of changed files
138- git diff origin/main...HEAD --name-only > mydiff
138+ git diff origin/main...HEAD --name-only > diff
139139
140140 echo "Changed files:"
141- cat mydiff
142-
143- echo "Changed SQL files:"
141+ cat diff
144142
143+ echo "Changed SQL files-:"
145144 # Filter SQL files from the list of changed files
146- awk '/scripts\/sql\//' mydiff
145+ awk '/scripts\/sql\//' diff
147146
148- # Count the number of changed SQL files
149- count=$(awk '/scripts\/sql\//' mydiff | wc -l)
147+ # Count the number of changed SQL files in the 'scripts/sql' directory
148+ count=$(awk '/scripts\/sql\//' diff | wc -l)
150149
150+ # Check if no SQL files were changed
151151 if [[ $count == "0" ]]; then
152- echo "No SQL files were added. Exiting from this action."
152+ echo "No SQL files were added, Exiting from this action."
153153 exit 0
154154 fi
155155
156156 # Iterate through each changed SQL file
157- for filename in $(awk '/scripts\/sql\//' mydiff ); do
157+ for filename in $(awk '/scripts\/sql\//' diff ); do
158158 echo "Checking File: $filename"
159159
160- # Check if the SQL file name is in the correct format
160+ # Check if the SQL file name is in the correct format (i.e., it ends with either '.up.sql' or '.down.sql')
161161 if [[ "$filename" =~ \.(up|down)\.sql$ ]]; then
162- echo "File name is in the correct format: $filename"
162+
163+ # Print a message that the file name is in the correct format
164+ echo "File name: $filename is in the correct format"
163165 else
166+ # Print an error message
164167 echo "Error: The SQL file name is not in the correct format: $filename."
165- gh pr comment $pr_no --body "Error: The SQL file name is not in the correct format: $filename."
168+
169+ # Post a comment on a GitHub pull request with the error message
170+ gh pr comment $pr_no --body "The SQL file name: $filename is not in the correct format."
171+
172+ # Exit the script with a non-zero status code
166173 exit 1
167174 fi
168175
@@ -180,23 +187,20 @@ jobs:
180187 migration_files_present_of_this_no=$(ls | cut -d "_" -f 1 | grep -w -c "$migration_no")
181188
182189 # Navigate back to the original directory
183- cd -
184-
185- echo "Current directory: $(pwd)"
186- echo "Migration Number: $migration_no"
187- echo "Number of files with this migration number: $migration_files_present_of_this_no"
190+ cd ../..
188191
189192 # Check the conditions based on the number of files with the same migration number
190193 if [[ $migration_files_present_of_this_no == "2" ]]; then
191194 echo "All looks good for this migration number."
192195 elif [[ $migration_files_present_of_this_no == "1" ]]; then
193- echo "Issue detected: Only $filename is present for this migration number."
194- echo "A single migration file was expected for this No- $migration_no"
196+ # Only one file is present for this migration number
197+ echo "Only single migration file was present for migration no.: $migration_no. either up or down migration is missing! EXITING "
195198 gh pr comment $pr_no --body "Error: Only a single migration file was present for this number: $migration_no."
196199 exit 1
197200 else
201+ # Migration number is repeated
198202 echo "Error: Migration number is repeated."
199- gh pr comment $pr_no --body "Error: The SQL file number is duplicated : $migration_no. "
203+ gh pr comment $pr_no --body "Error: The SQL file number: $migration_no is duplicated "
200204 exit 1
201205 fi
202206 done
0 commit comments