From f20b85835654fd6af35d17c9c6a3a70e1d9c0d28 Mon Sep 17 00:00:00 2001 From: LeoKle Date: Wed, 4 Sep 2024 14:06:46 +0200 Subject: [PATCH] fix workflow logic fix EDDF url --- .github/workflows/data-validation.yml | 4 +++- src/tasks/toml_data.py | 4 +--- src/validate_data.py | 33 ++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.github/workflows/data-validation.yml b/.github/workflows/data-validation.yml index 29ceb67..c41d198 100644 --- a/.github/workflows/data-validation.yml +++ b/.github/workflows/data-validation.yml @@ -1,4 +1,4 @@ -name: databuilder +name: datavalidator on: workflow_dispatch: @@ -26,4 +26,6 @@ jobs: pip install -r requirements.txt - name: Run Python script + env: + WORKFLOW_RUN_NUMBER: ${{ github.run_number }} run: python src/validate_data.py diff --git a/src/tasks/toml_data.py b/src/tasks/toml_data.py index c93fe46..7c92ed7 100644 --- a/src/tasks/toml_data.py +++ b/src/tasks/toml_data.py @@ -74,11 +74,9 @@ def check_errors(self): for error in self.errors: print(error) - sys.exit(1) - def export_data_json(self): if len(self.errors) != 0: - return + sys.exit(1) try: json_data = self.data.model_dump(mode="json") diff --git a/src/validate_data.py b/src/validate_data.py index 32e4007..8ff3157 100644 --- a/src/validate_data.py +++ b/src/validate_data.py @@ -1,6 +1,37 @@ +import os +import sys +import requests from settings import ROOT_DIRECTORY, OUTPUT_DIRECTORY from tasks.toml_data import TomlData if __name__ == "__main__": - TomlData(data_dir=ROOT_DIRECTORY, output_dir=OUTPUT_DIRECTORY, export=False) + tomldata = TomlData( + data_dir=ROOT_DIRECTORY, output_dir=OUTPUT_DIRECTORY, export=False + ) + + if len(tomldata.errors) == 0: + sys.exit(0) + + GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") + REPO_OWNER = os.getenv("REPO_OWNER") + REPO_NAME = os.getenv("REPO_NAME") + workflow_run_number = os.getenv("WORKFLOW_RUN_NUMBER") + + issue_title = f"Error on workflow run {workflow_run_number}" + issue_body = "\n".join(tomldata.errors) + + url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/issues" + headers = { + "Authorization": f"token {GITHUB_TOKEN}", + "Accept": "application/vnd.github.v3+json", + } + data = {"title": issue_title, "body": issue_body} + + response = requests.post(url, json=data, headers=headers, timeout=5) + + if response.status_code == 201: + print("Issue created successfully.") + else: + print(f"Failed to create issue: {response.status_code}") + print(response.json())