From a890e79899d10ffe3d39e247bc951ddf3d83f64f Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:40:36 +0200 Subject: [PATCH] BEHAVIOR: update lock files by default (#436) * DX: rename workflow to "Update" Looks better in checks overview * FIX: always update trigger paths --- .github/workflows/lock.yml | 21 +++++++++++++++++++ src/compwa_policy/.github/workflows/lock.yml | 2 +- src/compwa_policy/check_dev_files/__init__.py | 2 +- .../check_dev_files/update_lock.py | 11 ++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/lock.yml diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml new file mode 100644 index 00000000..85fa09a8 --- /dev/null +++ b/.github/workflows/lock.yml @@ -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 }} diff --git a/src/compwa_policy/.github/workflows/lock.yml b/src/compwa_policy/.github/workflows/lock.yml index d8046dc2..fe897530 100644 --- a/src/compwa_policy/.github/workflows/lock.yml +++ b/src/compwa_policy/.github/workflows/lock.yml @@ -1,4 +1,4 @@ -name: Update lock files +name: Update concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/src/compwa_policy/check_dev_files/__init__.py b/src/compwa_policy/check_dev_files/__init__.py index 2015b5ff..7a83ca18 100644 --- a/src/compwa_policy/check_dev_files/__init__.py +++ b/src/compwa_policy/check_dev_files/__init__.py @@ -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" diff --git a/src/compwa_policy/check_dev_files/update_lock.py b/src/compwa_policy/check_dev_files/update_lock.py index 1e6a3202..707e18dd 100644 --- a/src/compwa_policy/check_dev_files/update_lock.py +++ b/src/compwa_policy/check_dev_files/update_lock.py @@ -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():