Skip to content

Commit

Permalink
feat: add check bq project name action
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfg committed Apr 17, 2024
1 parent f7d159b commit 6fe3e52
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/workflows/check-bq-project-name.yml
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
23 changes: 23 additions & 0 deletions .github/workflows/scripts/check_sql_files.py
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.")
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
)
}}
select
select
safe_cast(substr(mes_competencia, 1, 4) as int64) ano_competencia,
safe_cast(substr(mes_competencia, 5, 2) as int64) mes_competencia,
safe_cast(substr(mes_referencia, 1, 4) as int64) ano_referencia,
Expand Down

0 comments on commit 6fe3e52

Please sign in to comment.