Skip to content

Commit

Permalink
fix: get correct job from workflow to insert python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Dec 2, 2021
1 parent 777272f commit 1949fbe
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/repoma/check_dev_files/update_pip_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- https://github.com/ComPWA/update-pre-commit
"""

from pathlib import Path

from ruamel.yaml.main import YAML
from ruamel.yaml.scalarstring import DoubleQuotedScalarString

from repoma.errors import PrecommitError
Expand Down Expand Up @@ -42,21 +45,24 @@ def overwrite_workflow(workflow_file: str) -> None:
map(DoubleQuotedScalarString, supported_python_versions)
)
jobs = list(expected_data["jobs"])
first_job = jobs[0]
expected_data["jobs"][first_job]["strategy"]["matrix"][
pip_constraint_job = jobs[1]
expected_data["jobs"][pip_constraint_job]["strategy"]["matrix"][
"python-version"
] = formatted_python_versions
workflow_path = CONFIG_PATH.github_workflow_dir / workflow_file
if not workflow_path.exists():
yaml.dump(expected_data, workflow_path)
raise PrecommitError(f'Created "{workflow_path}" workflow')
__update_workflow(yaml, expected_data, workflow_path)
existing_data = yaml.load(workflow_path)
if existing_data != expected_data:
yaml.dump(expected_data, workflow_path)
raise PrecommitError(f'Updated "{workflow_path}" workflow')
__update_workflow(yaml, expected_data, workflow_path)

executor = Executor()
executor(overwrite_workflow, "requirements-cron.yml")
executor(overwrite_workflow, "requirements-pr.yml")
if executor.error_messages:
raise PrecommitError(executor.merge_messages())


def __update_workflow(yaml: YAML, config: dict, path: Path) -> None:
yaml.dump(config, path)
raise PrecommitError(f'Updated "{path}" workflow')

0 comments on commit 1949fbe

Please sign in to comment.