|
| 1 | +# At the moment this script will only filter out the easystack files |
| 2 | +# Next step could be to filter out other subpaths |
| 3 | +# by using the GITHUB action environment variables and argsparse. |
| 4 | + |
| 5 | +# Can also distiguish between modified, added, ... files |
| 6 | +# That information is in the string that is generated by git diff |
| 7 | +# For filtering easystacks this was however not necessary |
| 8 | +# since we want to check both added and modified files |
| 9 | + |
| 10 | +# Todo: This script should eventually be its own github action. When it can be used for filtering more files. And all the todo have been addressed. |
| 11 | + |
| 12 | +import os |
| 13 | + |
| 14 | +diff = os.getenv('CHANGED') |
| 15 | +env_file = os.getenv('GITHUB_ENV') |
| 16 | + |
| 17 | +diff_list = diff.split('\n') |
| 18 | + |
| 19 | +diff_filter_path = 'easystacks' |
| 20 | + |
| 21 | +diff_filtered = '' |
| 22 | + |
| 23 | +for line in diff_list: |
| 24 | + status = line.split('\t')[0] |
| 25 | + file = line.split('\t')[1] |
| 26 | + if file.startswith(diff_filter_path): |
| 27 | + # Ignoring the status assigned to the file |
| 28 | + diff_filtered += file + ' ' |
| 29 | + |
| 30 | +if diff_filtered != '': |
| 31 | + # Todo: Can only handle 1 level paths now |
| 32 | + # If we want to pass multi-level paths this will need to be updated |
| 33 | + # Name of the env_var can change based on the file or path |
| 34 | + env_var = 'CHANGED_' + diff_filter_path.upper() |
| 35 | + set_var = env_var + "=" + diff_filtered |
| 36 | + |
| 37 | + # This adds the environment variable to the github action environment |
| 38 | + with open(env_file, 'a') as file: |
| 39 | + file.write(set_var) |
0 commit comments