-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #549 from basedosdados/add-bq-project-check-action
[feat]: add action to check bq project name
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Check BQ project name | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
paths: | ||
- '**/*.sql' | ||
|
||
jobs: | ||
check_bucket_name: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get changed files | ||
id: get_files | ||
uses: dorny/paths-filter@v2 | ||
with: | ||
list-files: shell | ||
filters: | | ||
pr: | ||
- added|deleted|modified: '**' | ||
- name: Install Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Run Python script | ||
run: | | ||
for file in ${{ steps.get_files.outputs.pr_files }}; do | ||
if [[ $file == *.sql ]]; then | ||
echo "SQL file detected: $file" | ||
python .github/workflows/scripts/check_sql_files.py $file | ||
else | ||
echo "Não é um arquivo SQL: $file" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import argparse | ||
|
||
def check_sql_files(file): | ||
found_staging = False | ||
if file.endswith(".sql"): | ||
with open(file, "r") as f: | ||
lines = f.readlines() | ||
for line in lines: | ||
if "basedosdados-dev" in line: | ||
found_staging = True | ||
print(f"Found 'basedosdados-dev' in {file}") | ||
break | ||
return found_staging | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Check for 'basedosdados-dev' occurrences in SQL files.") | ||
parser.add_argument("file", help="Path to the SQL file to check") | ||
args = parser.parse_args() | ||
|
||
if check_sql_files(args.file): | ||
exit(1) | ||
else: | ||
print("No occurrences of 'basedosdados-dev' found in SQL files.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters