Skip to content

Commit

Permalink
fix workflow logic
Browse files Browse the repository at this point in the history
add faulty url to test workflow

fix workflow logic
  • Loading branch information
LeoKle committed Sep 4, 2024
1 parent 9c6579e commit c52e2ff
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/data-validation.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: databuilder
name: datavalidator

on:
workflow_dispatch:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion data/EDGG/EDDF.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ url = "https://virtual-fra.com/"
[[airport.links]]
category = "Scenery"
name = "MSFS Scenery by Aviotek"
url = "https://orbxdirect.com/product/aviotek-eddf-msfs"
url = "https://www.google.com/404"
4 changes: 1 addition & 3 deletions src/tasks/toml_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 32 additions & 1 deletion src/validate_data.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit c52e2ff

Please sign in to comment.