Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

380 sync task registry update ak requirements and measures synchronization #78

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_DEV }}
TEXT: |
Wijziging geconstateerd in bestanden van het Algoritmekader die invloed hebben op het Task Registry.
[Link naar de GitHub Action run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
```
${{ needs.sync.outputs.file_contents }}
```
Expand Down
45 changes: 25 additions & 20 deletions script/conversion/add_links_to_measures
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import os
import sys
from pathlib import Path
from typing import Any, TextIO

Expand Down Expand Up @@ -50,26 +51,30 @@ def link_measures_to_requirements(measure_folder: Path) -> dict[Any, Any]:
@click.argument("requirement_folder", type=click.Path(exists=True, file_okay=False, dir_okay=True, path_type=Path))
@click.argument("measure_folder", type=click.Path(exists=False, file_okay=False, dir_okay=True, path_type=Path))
def insert_into_requirements(requirement_folder: Path, measure_folder: Path): # noqa
urns_to_original = link_measures_to_requirements(measure_folder)

for filename in sorted(os.listdir(requirement_folder)):
if filename.endswith(".yaml"):
with open(os.path.join(requirement_folder, filename)) as file:
data: dict[Any, Any] = ordered_load(file, loader=yaml.FullLoader) # Load while preserving order

if "links" in data and isinstance(data["links"], list):
# Create reverse links based on the URN
data["links"] = urns_to_original.get(data.get("urn"), [])

if "ai_act_profile" in data:
for profile in data["ai_act_profile"]:
for key in profile:
if isinstance(profile[key], list):
profile[key] = [rename_ai_act_labels_dict.get(item, item) for item in profile[key]]

# Write out the modified data to the secondary folder
with open(os.path.join(requirement_folder, filename), "w") as new_file:
ordered_dump(data, new_file) # Dump with order preserved
try:
urns_to_original = link_measures_to_requirements(measure_folder)

for filename in sorted(os.listdir(requirement_folder)):
if filename.endswith(".yaml"):
with open(os.path.join(requirement_folder, filename)) as file:
data: dict[Any, Any] = ordered_load(file, loader=yaml.FullLoader) # Load while preserving order

if "links" in data and isinstance(data["links"], list):
# Create reverse links based on the URN
data["links"] = urns_to_original.get(data.get("urn"), [])

if "ai_act_profile" in data:
for profile in data["ai_act_profile"]:
for key in profile:
if isinstance(profile[key], list):
profile[key] = [rename_ai_act_labels_dict.get(item, item) for item in profile[key]]

# Write out the modified data to the secondary folder
with open(os.path.join(requirement_folder, filename), "w") as new_file:
ordered_dump(data, new_file) # Dump with order preserved
except Exception as e: # Catch any exception
print(f"Error: {e}", file=sys.stderr) # Print error to stderr
sys.exit(1)


insert_into_requirements()
23 changes: 14 additions & 9 deletions script/conversion/convert_mkdocs_to_yaml_lifecycles
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import re
import sys
from pathlib import Path

import click
Expand All @@ -11,17 +12,21 @@ import yaml
@click.argument("source", type=click.Path(exists=True, file_okay=True, dir_okay=False, path_type=Path))
@click.argument("destination", type=click.Path(exists=False, file_okay=False, dir_okay=True, path_type=Path))
def do_sync(source: Path, destination: Path) -> None:
destination.mkdir(parents=True, exist_ok=True)
with open(source, encoding="utf-8") as file:
document = file.read()
regex = r"[\s\t]?<li>\s?<a href=\".*\">(.*)</a></li>"
matches = re.findall(regex, document)
if not matches:
regex = r"\d\.[\s\t]*\[(.*)\]\(.*\)"
try:
destination.mkdir(parents=True, exist_ok=True)
with open(source, encoding="utf-8") as file:
document = file.read()
regex = r"[\s\t]?<li>\s?<a href=\".*\">(.*)</a></li>"
matches = re.findall(regex, document)
if not matches:
regex = r"\d\.[\s\t]*\[(.*)\]\(.*\)"
matches = re.findall(regex, document)

with open(destination / Path("lifecycles.yaml"), "w", encoding="utf-8") as file:
yaml.dump({"lifecycles": matches}, file, allow_unicode=True, sort_keys=False)
with open(destination / Path("lifecycles.yaml"), "w", encoding="utf-8") as file:
yaml.dump({"lifecycles": matches}, file, allow_unicode=True, sort_keys=False)
except Exception as e: # Catch any exception
print(f"Error: {e}", file=sys.stderr) # Print error to stderr
sys.exit(1)


do_sync()
15 changes: 10 additions & 5 deletions script/conversion/convert_mkdocs_to_yaml_measure
laurensWe marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import os
import re
import sys
from pathlib import Path

import click
Expand Down Expand Up @@ -81,11 +82,15 @@ def parse_markdown_to_yaml(input_file: str, destination: Path) -> None:
@click.argument("source", type=click.Path(exists=True, file_okay=False, dir_okay=True, path_type=Path))
@click.argument("destination", type=click.Path(exists=False, file_okay=False, dir_okay=True, path_type=Path))
def read_folder(source: Path, destination: Path) -> None:
destination.mkdir(parents=True, exist_ok=True)
for filename in sorted(os.listdir(source)):
file_path: str = os.path.join(source, filename)
if os.path.isfile(file_path) and "index" not in file_path:
parse_markdown_to_yaml(file_path, destination)
try:
destination.mkdir(parents=True, exist_ok=True)
for filename in sorted(os.listdir(source)):
file_path: str = os.path.join(source, filename)
if os.path.isfile(file_path) and "index" not in file_path:
parse_markdown_to_yaml(file_path, destination)
except Exception as e: # Catch any exception
print(f"Error: {e}", file=sys.stderr) # Print error to stderr
sys.exit(1)


read_folder()
31 changes: 18 additions & 13 deletions script/conversion/convert_mkdocs_to_yaml_requirements
laurensWe marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import re
import sys
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -96,19 +97,23 @@ def parse_markdown_to_yaml(input_file: str, destination: Path) -> None:
@click.argument("source", type=click.Path(exists=False, file_okay=False, dir_okay=True, path_type=Path))
@click.argument("destination", type=click.Path(exists=False, file_okay=False, dir_okay=True, path_type=Path))
def read_folder(source: Path, destination: Path) -> None:
requirements_destination = destination / Path("requirements")
requirements_destination.mkdir(parents=True, exist_ok=True)
for filename in sorted(os.listdir(source)):
file_path: str = os.path.join(source, filename)
if os.path.isfile(file_path) and "index" not in file_path:
parse_markdown_to_yaml(file_path, requirements_destination)

labels_destination = destination / Path("labels")
labels_destination.mkdir(parents=True, exist_ok=True)
# prepare data for yaml
yaml_output = {"ai-act": {key: sorted(value) for key, value in ai_act_values.items()}}
with open(labels_destination / Path("labels.yaml"), "w", encoding="utf-8") as file:
yaml.dump(yaml_output, file, allow_unicode=True, sort_keys=False)
try:
requirements_destination = destination / Path("requirements")
requirements_destination.mkdir(parents=True, exist_ok=True)
for filename in sorted(os.listdir(source)):
file_path: str = os.path.join(source, filename)
if os.path.isfile(file_path) and "index" not in file_path:
parse_markdown_to_yaml(file_path, requirements_destination)

labels_destination = destination / Path("labels")
labels_destination.mkdir(parents=True, exist_ok=True)
# prepare data for yaml
yaml_output = {"ai-act": {key: sorted(value) for key, value in ai_act_values.items()}}
with open(labels_destination / Path("labels.yaml"), "w", encoding="utf-8") as file:
yaml.dump(yaml_output, file, allow_unicode=True, sort_keys=False)
except Exception as e: # Catch any exception
print(f"Error: {e}", file=sys.stderr) # Print error to stderr
sys.exit(1)


read_folder()
23 changes: 14 additions & 9 deletions script/conversion/convert_mkdocs_to_yaml_roles
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import re
import sys
from pathlib import Path
from typing import Any

Expand All @@ -23,15 +24,19 @@ def extract_title_from_file(input_file: str) -> str:
@click.argument("source", type=click.Path(exists=False, file_okay=False, dir_okay=True, path_type=Path))
@click.argument("destination", type=click.Path(exists=False, file_okay=False, dir_okay=True, path_type=Path))
def create_roles_file(source: Path, destination: Path) -> None:
destination.mkdir(parents=True, exist_ok=True)
roles: list[str] = []
for filename in sorted(os.listdir(source)):
file_path: str = os.path.join(source, filename)
if os.path.isfile(file_path) and "index" not in file_path:
roles.append(extract_title_from_file(file_path))

with open(destination / Path("roles.yaml"), "w", encoding="utf-8") as file:
yaml.dump({"roles": sorted(roles)}, file, allow_unicode=True, sort_keys=False)
try:
destination.mkdir(parents=True, exist_ok=True)
roles: list[str] = []
for filename in sorted(os.listdir(source)):
file_path: str = os.path.join(source, filename)
if os.path.isfile(file_path) and "index" not in file_path:
roles.append(extract_title_from_file(file_path))

with open(destination / Path("roles.yaml"), "w", encoding="utf-8") as file:
yaml.dump({"roles": sorted(roles)}, file, allow_unicode=True, sort_keys=False)
except Exception as e: # Catch any exception
print(f"Error: {e}", file=sys.stderr) # Print error to stderr
sys.exit(1)


create_roles_file()
20 changes: 15 additions & 5 deletions script/sync
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ if [ "$UPDATE" = "commit" ] && [ "$RECENT_COMMITS" = "" ]; then
fi

# Run the conversion scripts
poetry run ../script/conversion/convert_mkdocs_to_yaml_measure algoritmekader/docs/maatregelen "${DESTINATION}"/measures
poetry run ../script/conversion/convert_mkdocs_to_yaml_requirements algoritmekader/docs/vereisten "${DESTINATION}"
poetry run ../script/conversion/add_links_to_measures "${DESTINATION}"/requirements "${DESTINATION}"/measures
poetry run ../script/conversion/convert_mkdocs_to_yaml_lifecycles algoritmekader/docs/levenscyclus/index.md "${DESTINATION}"/lifecycles
poetry run ../script/conversion/convert_mkdocs_to_yaml_roles algoritmekader/docs/rollen "${DESTINATION}"/roles
commands=(
"poetry run ../script/conversion/convert_mkdocs_to_yaml_measure algoritmekader/docs/voldoen-aan-wetten-en-regels/maatregelen \"${DESTINATION}\"/measures"
"poetry run ../script/conversion/convert_mkdocs_to_yaml_requirements algoritmekader/docs/voldoen-aan-wetten-en-regels/vereisten \"${DESTINATION}\""
"poetry run ../script/conversion/add_links_to_measures \"${DESTINATION}\"/requirements \"${DESTINATION}\"/measures"
"poetry run ../script/conversion/convert_mkdocs_to_yaml_lifecycles algoritmekader/docs/levenscyclus/index.md \"${DESTINATION}\"/lifecycles"
"poetry run ../script/conversion/convert_mkdocs_to_yaml_roles algoritmekader/docs/rollen \"${DESTINATION}\"/roles"
)

for command in "${commands[@]}"; do
eval "$command"
if [[ $? -ne 0 ]]; then
echo "Error: $(basename "$command") failed"
exit 1 # Example: Exit the script on error
fi
done

if [ "$MODE" = "compare" ]; then
diff -burN "${DESTINATION}"/measures ../measures; (( exit_status = exit_status || $? ))
Expand Down
Loading