From 938f3fedd3d0494b300b519e688821632cf12d60 Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Mon, 27 Jul 2026 13:28:28 +0200 Subject: [PATCH 1/2] Move GitHub Actions to their own repos The list-make-prerequisites and make-prerequisites-changed actions now live in colluca/list-make-prerequisites and colluca/make-prerequisites-changed respectively, so their uses: reference matches the action name instead of a path into this repo. --- .github/workflows/ci.yml | 46 ++++++++++++---------------------------- README.md | 10 ++++++--- action.yml | 40 ---------------------------------- 3 files changed, 20 insertions(+), 76 deletions(-) delete mode 100644 action.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 532ca4a..3da0057 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,49 +4,29 @@ on: [push, pull_request] jobs: - test-action: + test-cli: - name: Test Github Action + name: Test CLI runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Install package + run: | + python -m pip install . - name: List prerequisites non-recursively - id: non-recursive-prerequisites - uses: ./ - with: - working-directory: test - target: test1 - - name: Check non-recursive prerequisites + working-directory: test run: | - test "${{ steps.non-recursive-prerequisites.outputs.prerequisites }}" = "prereq" - echo ${{ steps.non-recursive-prerequisites.outputs.hash }} - - name: List recursive prerequisites - id: recursive-prerequisites - uses: ./ - with: - working-directory: test - target: test1 - flags: --recursive - - name: Check recursive prerequisites + test "$(list-make-prerequisites test1)" = "prereq" + - name: List prerequisites recursively + working-directory: test run: | - test "${{ steps.recursive-prerequisites.outputs.prerequisites }}" = "preprereq1 preprereq2" - echo ${{ steps.recursive-prerequisites.outputs.hash }} + test "$(list-make-prerequisites test1 --recursive | xargs)" = "preprereq1 preprereq2" - name: Hash directory prerequisite - id: hash-dir-prerequisite - uses: ./ - with: - working-directory: test - target: test2 - flags: --recursive - - name: Check directory prerequisite hash - run: | - test "${{ steps.hash-dir-prerequisite.outputs.prerequisites }}" = "dirprereq" - test "${{ steps.hash-dir-prerequisite.outputs.hash }}" = "c64a77871513eadd52ec0e278bfbac1db866b77f66ebe91725b378b8bf43e29c" - - name: Install package + working-directory: test run: | - python -m pip install . + test "$(list-make-prerequisites test2 --recursive --hash)" = "c64a77871513eadd52ec0e278bfbac1db866b77f66ebe91725b378b8bf43e29c" - name: List dependent targets non-recursively working-directory: test run: | diff --git a/README.md b/README.md index 4de168d..05dde5a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # pymakeutils -A collection of CLI utilities and actions to extract information from Makefiles: -- list-make-prerequisites: List all prerequisites of a target (optionally recursively) -- list-dependent-make-targets: List all targets that depend on a certain prerequisite (optionally recursively) +A collection of CLI utilities to extract information from Makefiles: +- `list-make-prerequisites`: List all prerequisites of a target (optionally recursively) +- `list-dependent-make-targets`: List all targets that depend on a certain prerequisite (optionally recursively) + +## Related GitHub Actions +- [colluca/list-make-prerequisites](https://github.com/colluca/list-make-prerequisites): List a target's prerequisites and their combined hash +- [colluca/make-prerequisites-changed](https://github.com/colluca/make-prerequisites-changed): Check whether any of a target's prerequisites changed since a base commit diff --git a/action.yml b/action.yml deleted file mode 100644 index 0bcbe37..0000000 --- a/action.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: "List Make Prerequisites Action" -description: "List all prerequisites of a Makefile target" -author: "Luca Colagrande" - -inputs: - target: - description: "Target to list prerequisites for" - required: true - working-directory: - description: "Working directory to run Make in" - required: false - default: '.' - flags: - description: "Additional flags to pass to list-make-prerequisites.py" - required: false - default: '' - -outputs: - hash: - description: "Hash of all prerequisite file contents" - value: ${{ steps.list-make-prerequisites.outputs.hash }} - prerequisites: - description: "List of all prerequisite files" - value: ${{ steps.list-make-prerequisites.outputs.prerequisites }} - -runs: - using: "composite" - steps: - - name: Install Package - shell: bash - run: python -m pip install . - - name: List Make Prerequisites - id: list-make-prerequisites - shell: bash - working-directory: ${{ inputs.working-directory }} - run: | - hash=$(list-make-prerequisites ${{ inputs.target }} ${{ inputs.flags }} --hash) - prerequisites=$(list-make-prerequisites ${{ inputs.target }} ${{ inputs.flags }} | xargs) - echo "hash=$hash" >> $GITHUB_OUTPUT - echo "prerequisites=$prerequisites" >> $GITHUB_OUTPUT From 2b690cfadbf8c12149036439bf95eb0823a7cb40 Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Mon, 27 Jul 2026 13:38:57 +0200 Subject: [PATCH 2/2] Add pytest-based test suite for the CLIs Replaces the inline bash assertions in ci.yml with actual pytest tests under test/, invoked via subprocess so argument parsing and console-script wiring are covered too. --- .github/workflows/ci.yml | 24 +++--------------------- pyproject.toml | 8 +++++++- test/test_cli.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 test/test_cli.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3da0057..71099f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,24 +14,6 @@ jobs: - uses: actions/checkout@v4 - name: Install package run: | - python -m pip install . - - name: List prerequisites non-recursively - working-directory: test - run: | - test "$(list-make-prerequisites test1)" = "prereq" - - name: List prerequisites recursively - working-directory: test - run: | - test "$(list-make-prerequisites test1 --recursive | xargs)" = "preprereq1 preprereq2" - - name: Hash directory prerequisite - working-directory: test - run: | - test "$(list-make-prerequisites test2 --recursive --hash)" = "c64a77871513eadd52ec0e278bfbac1db866b77f66ebe91725b378b8bf43e29c" - - name: List dependent targets non-recursively - working-directory: test - run: | - test $(list-dependent-make-targets preprereq1) = prereq - - name: List dependent targets recursively - working-directory: test - run: | - test "$(list-dependent-make-targets preprereq1 -r | xargs)" = ".DEFAULT_GOAL prereq test1" \ No newline at end of file + python -m pip install .[test] + - name: Run tests + run: pytest \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b5655ac..7483de9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,13 @@ where = ["src"] [tool.setuptools.dynamic] dependencies = { file = ["requirements.txt"] } +[project.optional-dependencies] +test = ["pytest"] + # Expose your scripts as console commands [project.scripts] list-make-prerequisites = "pymakeutils.list_make_prerequisites:main" -list-dependent-make-targets = "pymakeutils.list_dependent_make_targets:main" \ No newline at end of file +list-dependent-make-targets = "pymakeutils.list_dependent_make_targets:main" + +[tool.pytest.ini_options] +testpaths = ["test"] \ No newline at end of file diff --git a/test/test_cli.py b/test/test_cli.py new file mode 100644 index 0000000..ab47902 --- /dev/null +++ b/test/test_cli.py @@ -0,0 +1,40 @@ +"""Tests for the list-make-prerequisites and list-dependent-make-targets CLIs. + +Both CLIs are exercised as subprocesses (rather than calling their `main()` +directly) so that the tests also cover argument parsing and console-script +wiring, running against the Makefile fixtures in this directory. +""" + +import subprocess +from pathlib import Path + +FIXTURES_DIR = Path(__file__).parent + + +def run_cli(*args): + result = subprocess.run( + args, cwd=FIXTURES_DIR, capture_output=True, text=True, check=True) + return result.stdout.strip() + + +def test_list_prerequisites_non_recursive(): + assert run_cli('list-make-prerequisites', 'test1') == 'prereq' + + +def test_list_prerequisites_recursive(): + prerequisites = run_cli('list-make-prerequisites', 'test1', '--recursive').splitlines() + assert prerequisites == ['preprereq1', 'preprereq2'] + + +def test_hash_directory_prerequisite(): + hash_value = run_cli('list-make-prerequisites', 'test2', '--recursive', '--hash') + assert hash_value == 'c64a77871513eadd52ec0e278bfbac1db866b77f66ebe91725b378b8bf43e29c' + + +def test_list_dependent_targets_non_recursive(): + assert run_cli('list-dependent-make-targets', 'preprereq1') == 'prereq' + + +def test_list_dependent_targets_recursive(): + targets = run_cli('list-dependent-make-targets', 'preprereq1', '--recursive').splitlines() + assert targets == ['.DEFAULT_GOAL', 'prereq', 'test1']