diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31fa175..6825b8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: uses: ./ with: working-directory: test - target: test + target: test1 - name: Check non-recursive prerequisites run: | test "${{ steps.non-recursive-prerequisites.outputs.prerequisites }}" = "prereq" @@ -27,9 +27,20 @@ jobs: uses: ./ with: working-directory: test - target: test + target: test1 flags: --recursive - name: Check recursive prerequisites run: | test "${{ steps.recursive-prerequisites.outputs.prerequisites }}" = "preprereq1 preprereq2" echo ${{ steps.recursive-prerequisites.outputs.hash }} + - 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" diff --git a/list-make-prerequisites.py b/list-make-prerequisites.py index 7836625..650c249 100755 --- a/list-make-prerequisites.py +++ b/list-make-prerequisites.py @@ -5,6 +5,7 @@ from anytree import Node, RenderTree import argparse import hashlib +from pathlib import Path import re import subprocess import sys @@ -137,9 +138,18 @@ def hash_files(file_list): # Create a new SHA-256 hash object hasher = hashlib.sha256() + # If any prerequisite is a directory, replace it with its (recursive) contents + expanded_file_list = [] for file_name in file_list: - # Open each file in binary mode - try: + file = Path(file_name) + if file.is_dir(): + expanded_file_list.extend([str(f) for f in file.rglob('*') if f.is_file()]) + else: + expanded_file_list.append(file_name) + + # Hash file contents + for file_name in expanded_file_list: + try: with open(file_name, 'rb') as f: # Read the file content in chunks to avoid memory issues with large files while chunk := f.read(8192): # 8192 bytes per chunk diff --git a/test/Makefile b/test/Makefile index 750deca..f1db02f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,6 +1,8 @@ -test: prereq +test1: prereq cp $< $@ prereq: preprereq1 preprereq2 cp $< $@ cat preprereq2 >> $@ + +test2: dirprereq \ No newline at end of file diff --git a/test/dirprereq/dir/prereq.txt b/test/dirprereq/dir/prereq.txt new file mode 100644 index 0000000..96638e5 --- /dev/null +++ b/test/dirprereq/dir/prereq.txt @@ -0,0 +1 @@ +prereq \ No newline at end of file