Skip to content

Commit

Permalink
fix: Embed directory search script into action since files are not ca…
Browse files Browse the repository at this point in the history
…rried with the action (#15)
  • Loading branch information
bryantbiggs authored Nov 13, 2022
1 parent 1378076 commit f0a8fb0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
39 changes: 37 additions & 2 deletions directories/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,41 @@ runs:
shell: bash
id: search
run: |
ls -la
DIRS=$(python ./directories/directories.py)
cat > directories.py <<EOL
import json
import mmap
import os
import re
import glob
def get_directories():
"""
Return all Terraform (*.tf) files that contain the 'required_version'
string, but does not contain 'wrapper' in the path.
"""
terraform_files = glob.glob('./**/*.tf', recursive=True)
directories = []
for file in terraform_files:
file_size = os.stat(file)
if file_size.st_size > 0:
with open(file, 'rb', 0) as rfile:
contents = mmap.mmap(rfile.fileno(), 0, access=mmap.ACCESS_READ)
if contents.find(b'required_version') != -1 and 'wrapper' not in file:
formatted = "/".join(file.split('/')[:-1])
directories.append(formatted)
return json.dumps([x for x in directories if not re.match(r'^.+/_', x)])
if __name__ == '__main__':
print(get_directories())
EOL
DIRS=$(python ./directories.py)
echo $DIRS
rm directories.py
echo "directories=$DIRS" >> $GITHUB_OUTPUT
13 changes: 7 additions & 6 deletions directories/directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import mmap
import os
import re
from glob import glob
import glob


def get_directories():
"""
Return all Terraform (*.tf) files that contain the `required_version`
string, but does not contain `wrapper` in the path.
Return all Terraform (*.tf) files that contain the 'required_version'
string, but does not contain 'wrapper' in the path.
"""

terraform_files = glob('./**/*.tf', recursive=True)
terraform_files = glob.glob('./**/*.tf', recursive=True)
directories = []

for file in terraform_files:
Expand All @@ -21,9 +21,10 @@ def get_directories():
with open(file, 'rb', 0) as rfile:
contents = mmap.mmap(rfile.fileno(), 0, access=mmap.ACCESS_READ)
if contents.find(b'required_version') != -1 and 'wrapper' not in file:
directories.append(file)
formatted = "/".join(file.split('/')[:-1])
directories.append(formatted)

return json.dumps([x.replace('/versions.tf', '') for x in directories if not re.match(r'^.+/_', x)])
return json.dumps([x for x in directories if not re.match(r'^.+/_', x)])


if __name__ == '__main__':
Expand Down

0 comments on commit f0a8fb0

Please sign in to comment.