-
Notifications
You must be signed in to change notification settings - Fork 16
237 lines (198 loc) · 8.02 KB
/
pr_checks.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
name: Pull Request Checks
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'playbooks/**'
jobs:
Required_files:
name: Checking for required files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- name: List all changed files
env:
MODIFIED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
for file in "${{ env.MODIFIED_FILES }}"; do
echo "$file was changed"
done
echo "MODIFIED_FILES=${{ env.MODIFIED_FILES }}" >> $GITHUB_ENV
- name: Get the list of assessment tools
run: |
tools=$(cat /home/runner/work/besecure-playbooks-store/besecure-playbooks-store/.github/scripts/assessment_tools.txt | tr '\n' '|')
tools=${tools%|}
echo "ASSESSMENT_TOOLS=$(echo "$tools")" >> $GITHUB_ENV
- run: echo "${{ env.ASSESSMENT_TOOLS }}"
- name: Check if steps file present
run: |
steps_flag=false
for file in ${{ env.MODIFIED_FILES }}; do
if (echo $file | grep -E "${{ env.ASSESSMENT_TOOLS }}" | grep '\-playbook\.sh$')
then
tool_name=$(echo "$file" | cut -d "-" -f 2)
version=$(echo "$file" | cut -d "-" -f 3)
if ! (echo "${{ env.MODIFIED_FILES }}" | grep "besman-$tool_name-$version-steps" || ls -R . | grep "besman-$tool_name-$version-steps"); then
steps_flag=true
echo -e "\e[31mCould not find steps file for \e[33mbesman-$tool_name-$version-playbook.sh\e[31m"
fi
fi
done
if [[ $steps_flag == true ]]
then
exit 1
fi
File_Name_Standard:
name: Check for file naming convention
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- name: List all changed files
env:
MODIFIED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
for file in "${MODIFIED_FILES}"; do
echo "$file was changed"
done
echo "MODIFIED_FILES=$MODIFIED_FILES" >> $GITHUB_ENV
- name: Print files
run: echo "${{ env.MODIFIED_FILES }}"
- name: Get the list of assessment tools
run: |
tools=$(cat /home/runner/work/besecure-playbooks-store/besecure-playbooks-store/.github/scripts/assessment_tools.txt | tr '\n' '|')
tools=${tools%|}
echo "ASSESSMENT_TOOLS=$(echo "$tools")" >> $GITHUB_ENV
- name: Print the list of required tools
run: echo "Required tools= ${{ env.ASSESSMENT_TOOLS }}"
- name: Check playbook naming convention
run: |
file_flag=false
for file in ${{env.MODIFIED_FILES}}; do
if [[ $file =~ playbooks\/(.*)-(.*)-(.*)-((playbook\.sh)|(steps\.(sh|md|ipynb)))$ ]]; then
file_name=$(echo $file | cut -d "/" -f 2)
if ! [[ $file_name =~ ^besman-(${{ env.ASSESSMENT_TOOLS }})-[0-9]+\.[0-9]+\.[0-9]+-((playbook\.sh)|(steps\.(sh|md|ipynb)))$ ]]; then
echo -e "\e[31mThe file \e[33m$file_name \e[31m does not match standard naming convention.\e[0m"
file_flag=true
fi
fi
done
if [[ $file_flag == true ]]
then
exit 1
fi
Check_if_metadata_update:
name: Checking for playbook in metadata
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- name: List all changed files
env:
MODIFIED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
for file in "${MODIFIED_FILES}"; do
echo "$file was changed"
done
echo "MODIFIED_FILES=$MODIFIED_FILES" >> $GITHUB_ENV
- name: Print files
run: echo "${{ env.MODIFIED_FILES }}"
- name: Get the list of assessment tools
run: |
tools=$(cat /home/runner/work/besecure-playbooks-store/besecure-playbooks-store/.github/scripts/assessment_tools.txt | tr '\n' '|')
tools=${tools%|}
echo "ASSESSMENT_TOOLS=$(echo "$tools")" >> $GITHUB_ENV
- name: Print the list of required tools
run: echo "Required tools= ${{ env.ASSESSMENT_TOOLS }}"
- name: Install jq
run: |
sudo apt-get update
sudo apt-get install jq -y
- name: Check for metadata file
run: |
metadata_json_path=""
if echo "${{ env.MODIFIED_FILES }}" | grep -q "playbook-metadata.json"; then
metadata_json_path="playbook-metadata.json"
else
metadata_json_path="/home/runner/work/besecure-playbooks-store/besecure-playbooks-store/playbook-metadata.json"
fi
echo "metadata_json_path=$metadata_json_path"
json_flag=false
for file in ${{env.MODIFIED_FILES}}; do
found=""
if [[ $file =~ ^playbooks\/(.*)-(.*)-(.*)-playbook\.sh$ ]]; then
name=$(echo $file | cut -d "/" -f 2 | cut -d "-" -f 2)
version=$(echo $file | cut -d "/" -f 2 | cut -d "-" -f 3)
found=$(cat "$metadata_json_path" | jq --arg name "$name" --arg version "$version" '.playbooks[] | select(.name == $name and .version == $version)')
if [[ -z $found ]]; then
echo -e "\e[31mPlaybook \e[33m$file \e[31m with version \e[33m$version \e[31m not found in $metadata_json_path\e[0m"
json_flag=true
fi
fi
done
if [[ $json_flag == true ]]
then
exit 1
fi
Required_functions:
name: Checking for required functions
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- name: List all changed files
env:
MODIFIED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
for file in "${MODIFIED_FILES}"; do
echo "$file was changed"
done
echo "MODIFIED_FILES=$MODIFIED_FILES" >> $GITHUB_ENV
- name: Print files
run: echo "${{ env.MODIFIED_FILES }}"
- name: Get the list of required functions
id: get_functions
run: |
functions=$(cat .github/scripts/playbook_functions.txt)
echo "PLAYBOOK_FUNCTIONS=$(echo "$functions" | tr '\n' ' ')" >> $GITHUB_ENV
- name: Get the list of assessment tools
run: |
tools=$(cat .github/scripts/assessment_tools.txt | tr '\n' '|')
tools=${tools%|}
echo "ASSESSMENT_TOOLS=$(echo "$tools")" >> $GITHUB_ENV
- name: Print the list of required functions
run: echo "Required functions= ${{ env.PLAYBOOK_FUNCTIONS }}"
- name: Print the list of required tools
run: echo "Required tools= ${{ env.ASSESSMENT_TOOLS }}"
- name: Check for required functions
run: |
function_flag=false
for file in ${{ env.MODIFIED_FILES }};do
# Check if the file ends with "-playbook.sh"
if [[ $file =~ playbooks\/(.*)-(.*)-(.*)-playbook\.sh ]]; then
for f in ${{ env.PLAYBOOK_FUNCTIONS }}; do
if ! grep -q -w "function $f" $file
then
echo -e "\e[31mMissing function \e[33m$f\e[31m in \e[33m$file\e[0m"
function_flag=true
fi
done
if [[ $function_flag == true ]]
then
exit 1
fi
fi
done