Skip to content

Commit

Permalink
update validation workflow to run on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoKle committed Sep 9, 2024
1 parent d8ebd76 commit b321e23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/data-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: datavalidator

on:
workflow_dispatch:
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * 0"

Expand All @@ -26,6 +29,4 @@ jobs:
pip install -r requirements.txt
- name: Run Python script
env:
WORKFLOW_RUN_NUMBER: ${{ github.run_number }}
run: python src/validate_data.py
29 changes: 2 additions & 27 deletions src/validate_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import sys
import requests
from settings import ROOT_DIRECTORY, OUTPUT_DIRECTORY
from tasks.toml_data import TomlData

Expand All @@ -10,28 +8,5 @@
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())
if len(tomldata.errors) != 0:
sys.exit(1)

0 comments on commit b321e23

Please sign in to comment.