Skip to content

Commit

Permalink
Merge pull request #549 from basedosdados/add-bq-project-check-action
Browse files Browse the repository at this point in the history
[feat]: add action to check bq project name
  • Loading branch information
arthurfg authored Apr 17, 2024
2 parents f7d159b + 5f9ee9c commit 3120bb9
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 @@ -27,7 +27,7 @@ select
safe_cast(nis as string) nis_favorecido,
safe_cast(t1.nome as string) nome_favorecido,
safe_cast(valor as float64) valor_parcela,
from `basedosdados-dev.br_cgu_beneficios_cidadao_staging.novo_bolsa_familia` t1
from `basedosdados-staging.br_cgu_beneficios_cidadao_staging.novo_bolsa_familia` t1
left join
`basedosdados.br_bd_diretorios_brasil.municipio` t2
on safe_cast(t1.id_municipio_siafi as int64)
Expand Down

0 comments on commit 3120bb9

Please sign in to comment.