Skip to content

Commit

Permalink
GitHub Actions tweaked
Browse files Browse the repository at this point in the history
  • Loading branch information
mwgg committed Aug 21, 2024
1 parent 12e921c commit 04ccf2d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
File renamed without changes.
32 changes: 32 additions & 0 deletions .github/scripts/valid_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import json
import argparse
import sys

def check_json_validity(file_path):
try:
with open(file_path, 'r') as file:
json.load(file)
return True, ""
except json.JSONDecodeError as e:
return False, f"Invalid JSON: {e}"
except Exception as e:
return False, f"An unexpected error occurred: {e}"

def main():
parser = argparse.ArgumentParser(description="Check if a JSON file is valid.")
parser.add_argument("file", help="The path to the JSON file to check.")

args = parser.parse_args()
file_path = args.file

is_valid, message = check_json_validity(file_path)

if is_valid:
print(f"The JSON file '{file_path}' is valid.")
sys.exit(0)
else:
print(f"The JSON file '{file_path}' is invalid. Error: {message}")
sys.exit(1)

if __name__ == "__main__":
main()
25 changes: 25 additions & 0 deletions .github/workflows/check_valid_json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Valid JSON

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
sort-json:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Run JSON validator
run: python ./.github/scripts/valid_json.py airports.json
5 changes: 1 addition & 4 deletions .github/workflows/sort_airports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
sort-json:
Expand All @@ -22,7 +19,7 @@ jobs:
python-version: '3.x'

- name: Run JSON sorter
run: python sort.py airports.json airports.json icao
run: python ./.github/scripts/sort.py airports.json airports.json icao

- name: Check if airports.json file changed
id: file_changed
Expand Down

0 comments on commit 04ccf2d

Please sign in to comment.