From fa4f26010b4e6f6237d243e2968a4b3fa41bec30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Gusm=C3=A3o?= Date: Tue, 16 Apr 2024 19:53:11 -0300 Subject: [PATCH] feat: add action to check bucket name --- .github/workflows/scripts/check_sql_files.py | 35 ++++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/.github/workflows/scripts/check_sql_files.py b/.github/workflows/scripts/check_sql_files.py index 3ad74e0f..6a6720aa 100644 --- a/.github/workflows/scripts/check_sql_files.py +++ b/.github/workflows/scripts/check_sql_files.py @@ -1,21 +1,28 @@ import os +import json + +def get_changed_files(): + changed_files = [] + with open(os.environ['GITHUB_EVENT_PATH'], 'r') as f: + event = json.load(f) + for file in event['pull_request']['files']: + if file['filename'].endswith('.sql'): + changed_files.append(file['filename']) + return changed_files def check_sql_files(): + changed_files = get_changed_files() found_staging = False - for root, dirs, files in os.walk("."): - for file in files: - if file.endswith(".sql"): - with open(os.path.join(root, file), "r") as f: - lines = f.readlines() - for line in lines: - if "basedosdados-staging" in line: - found_staging = True - print(f"Found 'basedosdados-staging' in {os.path.join(root, file)}") - break - if found_staging: - break - if found_staging: - break + for file in changed_files: + with open(file, "r") as f: + lines = f.readlines() + for line in lines: + if "basedosdados-staging" in line: + found_staging = True + print(f"Found 'basedosdados-staging' in {file}") + break + if found_staging: + break if found_staging: exit(1)