-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
action.yml
56 lines (46 loc) · 1.68 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
name: directories
description: Collects list of Terraform directories
outputs:
directories:
description: Array of directories that contain a `versions.tf` file
value: ${{ steps.search.outputs.directories }}
runs:
using: composite
steps:
- name: Get Terraform directories for evaluation
shell: bash
id: search
run: |
cat > directories.py <<EOL
import json
import mmap
import os
import re
import glob
from pathlib import Path
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:
p = Path(file)
if p.is_dir():
continue
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