-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI workflow and code review changes
workflow for schema update has been added. Somre refactoring to get 100 test coverage requirement and apply code review comments.
- Loading branch information
emikeb
committed
Jul 29, 2024
1 parent
b4a87fc
commit 0fee64e
Showing
10 changed files
with
152 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
name: Update Schema | ||
|
||
"on": | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
inputs: {} | ||
|
||
jobs: | ||
generate-schema: | ||
name: Generate and Upload Schema | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Install | ||
run: python -m pip install retasc | ||
|
||
- name: Generate schema | ||
run: retasc generate-schema schema.yaml | ||
|
||
- name: Prepare deployment directory | ||
run: | | ||
mkdir -p public | ||
cp schema.yaml public/ | ||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: public | ||
publish_branch: gh-pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...etasc/validator/schemas/example_rule.yaml → src/retasc/validator/example_rule.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
version: 1 | ||
name: "Example Rule" | ||
prerequisites: | ||
pp_schedule_item_name: "Release Date" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import sys | ||
import logging | ||
|
||
import yaml | ||
|
||
from retasc.validator.models import Rule | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def generate_schema(output_path="src/retasc/validator/schemas/rules_schema.yaml"): | ||
|
||
def generate_schema(output_path: str) -> None: | ||
schema = Rule.model_json_schema() | ||
schema_yaml = yaml.dump(schema, sort_keys=False) | ||
with open(output_path, "w") as schema_file: | ||
schema_file.write(schema_yaml) | ||
|
||
|
||
if __name__ == "__main__": | ||
generate_schema(sys.argv[1]) | ||
try: | ||
with open(output_path, "w") as schema_file: | ||
schema_file.write(schema_yaml) | ||
except Exception as e: | ||
logger.error(f"Error generating schema: {e}") | ||
raise e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
import logging | ||
import sys | ||
|
||
import yaml | ||
from pydantic import ValidationError | ||
|
||
from retasc.retasc_logging import init_logging | ||
from retasc.validator.models import Rule | ||
|
||
init_logging() | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def validate_rule(rule_file): | ||
def validate_rule(rule_file: str) -> bool: | ||
with open(rule_file) as file: | ||
rule_data = yaml.safe_load(file) | ||
return validate_rule_dict(rule_data) | ||
|
||
|
||
def validate_rule_dict(rule_data): | ||
def validate_rule_dict(rule_data: dict) -> bool: | ||
try: | ||
Rule(**rule_data) | ||
logger.info("The rule is valid.") | ||
return True | ||
except ValidationError as err: | ||
logger.error(f"The rule is invalid: {err}") | ||
return False | ||
|
||
|
||
if __name__ == "__main__": | ||
validate_rule(sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.