Skip to content

Commit

Permalink
BEHAVIOR: update lock files by default (#436)
Browse files Browse the repository at this point in the history
* DX: rename workflow to "Update"
  Looks better in checks overview
* FIX: always update trigger paths
  • Loading branch information
redeboer authored Oct 16, 2024
1 parent a013ee0 commit a890e79
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Update

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: |-
${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}
on:
pull_request:
branches:
- main
- epic/*
paths:
- .pre-commit-config.yaml
workflow_dispatch:

jobs:
lock:
uses: ComPWA/actions/.github/workflows/lock.yml@v2
secrets:
token: ${{ secrets.PAT }}
2 changes: 1 addition & 1 deletion src/compwa_policy/.github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update lock files
name: Update

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion src/compwa_policy/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def _create_argparse() -> ArgumentParser:
parser.add_argument(
"--update-lock-files",
choices=update_lock.Frequency.__args__, # type:ignore[attr-defined]
default="no",
default="outsource",
help=(
"Add a workflow to update lock files, like uv.lock, .pre-commit-config.yml, "
"and pip .constraints/ files. The argument is the frequency of the cron job"
Expand Down
11 changes: 9 additions & 2 deletions src/compwa_policy/check_dev_files/update_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ def overwrite_workflow(workflow_file: str) -> None:
)
yaml = create_prettier_round_trip_yaml()
expected_data = yaml.load(expected_workflow_path)
original_paths = expected_data["on"]["pull_request"]["paths"]
existing_paths = filter_patterns(original_paths)
if not existing_paths:
msg = (
"No paths defined for pull_request trigger. Expecting any of "
", ".join(original_paths)
)
raise ValueError(msg)
expected_data["on"]["pull_request"]["paths"] = existing_paths
if frequency == "outsource":
del expected_data["on"]["schedule"]
else:
paths = filter_patterns(expected_data["on"]["pull_request"]["paths"])
expected_data["on"]["pull_request"]["paths"] = paths
expected_data["on"]["schedule"][0]["cron"] = _to_cron_schedule(frequency)
workflow_path = CONFIG_PATH.github_workflow_dir / workflow_file
if not workflow_path.exists():
Expand Down

0 comments on commit a890e79

Please sign in to comment.