Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 2 additions & 8 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,9 @@ jobs:
with:
persist-credentials: false

- name: Set up Python environment
uses: actions/setup-python@v5

- name: Install dependencies
run: |
pip install pytest ruyaml

- name: Run tests
run: |
pytest
pipx install uv
uvx --with ruyaml pytest
env:
GH_TOKEN: ${{ github.token }}
5 changes: 4 additions & 1 deletion .github/workflows/update_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
paths:
- ".github/workflows/update_actions.yml"
- ".github/workflows/dummy.yml"
- gateway/*

permissions:
contents: read
Expand All @@ -28,8 +29,10 @@ jobs:
with:
persist-credentials: true

- run: pip install ruyaml

- name: Update actions.yml
shell: python
shell: python
run: |
import sys
sys.path.append("./gateway/")
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/update_dummy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
paths:
- ".github/workflows/update_dummy.yml"
- "actions.yml"
- gateway/*

permissions: {}

Expand All @@ -28,8 +29,10 @@ jobs:
# We have to use a PAT to commit the workflow file
token: ${{ secrets.ALLOWLIST_WORKFLOW_TOKEN || github.token }}

- run: pip install ruyaml

- name: Update Workflow
shell: python
shell: python
run: |
import sys
sys.path.append("./gateway/")
Expand Down
23 changes: 18 additions & 5 deletions gateway/gateway.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "ruyaml",
# ]
# ///

import os
from datetime import date, timedelta
from io import StringIO
from pathlib import Path
from typing import Dict, NotRequired, TypedDict

import ruyaml


class RefDetails(TypedDict):
"""
Type definition for reference details of GitHub Actions for actions.yml
Expand Down Expand Up @@ -66,6 +75,11 @@ def write_yaml(path: Path, yaml_dict: dict | list):
yaml = ruyaml.YAML()
yaml.dump(yaml_dict, file)

def to_yaml_string(yaml_dict: dict | list):
yaml = ruyaml.YAML()
stream = StringIO()
yaml.dump(yaml_dict, stream)
return stream.getvalue()

def write_str(path: Path, content: str):
with open(path, "w") as file:
Expand Down Expand Up @@ -182,10 +196,9 @@ def update_actions(dummy_path: Path, actions_path: Path):
actions: ActionsYAML = load_yaml(actions_path)

update_refs(steps, actions)
gha_print(yaml.safe_dump(actions), "Generated List")
gha_print(to_yaml_string(actions), "Generated List")
write_yaml(actions_path, actions)


def create_pattern(actions: ActionsYAML) -> list[str]:
"""
Create a pattern list of valid action references.
Expand Down Expand Up @@ -218,8 +231,8 @@ def update_patterns(pattern_path: Path, list_path: Path):
"""
actions: ActionsYAML = load_yaml(list_path)
patterns = create_pattern(actions)
comment = f"# This file was generated from {pattern_path} by gateway/gateway.py. DO NOT UPDATE MANUALLY.\n"
patterns_str = comment + yaml.safe_dump(patterns)
comment = f"# This file was generated from {list_path} by gateway/gateway.py. DO NOT UPDATE MANUALLY.\n"
patterns_str = comment + to_yaml_string(patterns)
gha_print(patterns_str, "Generated Patterns")
write_str(pattern_path, patterns_str)

Expand Down Expand Up @@ -273,5 +286,5 @@ def clean_actions(actions_path: Path):
"""
actions: ActionsYAML = load_yaml(actions_path)
remove_expired_refs(actions)
gha_print(yaml.safe_dump(actions), "Cleaned Actions")
gha_print(to_yaml_string(actions), "Cleaned Actions")
write_yaml(actions_path, actions)