-
-
Notifications
You must be signed in to change notification settings - Fork 16
253 lines (217 loc) · 10.4 KB
/
pr_validation.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
name: PR-Testing the action
on:
pull_request:
workflow_dispatch:
# declare default GITHUB_TOKEN permissions as read only.
permissions: read-all
jobs:
test-load-from-user: # test the action for the user space
name: PR - User space
runs-on: ubuntu-latest
env:
user: ${{ vars.USER }}
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
# make sure we have a new build, in case the dist folder was not updated
- name: Compile with NPM
run: |
npm ci
npm run all
# run the test
- uses: ./
name: Load available actions
with:
PAT: ${{ secrets.GITHUB_TOKEN }}
user: ${{ env.user }}
id: load-actions
# check if the result file is not empty
- name: Check if the result file is not empty
run: |
if [ ! -s "${{ steps.load-actions.outputs.actions-file-path }}" ]; then
echo "The result file is empty" | tee "$GITHUB_STEP_SUMMARY"
exit 1
fi
echo "Found [$(jq '.actions | length' "${{ steps.load-actions.outputs.actions-file-path }}")] actions in the user space of [${{ env.user }}]" | tee "$GITHUB_STEP_SUMMARY"
- name: Check if the result file has actions in it
run: |
# check if the file has actions in it
if [ "$(jq '.actions | length' "${{ steps.load-actions.outputs.actions-file-path }}")" -eq 0 ]; then
echo ":warning: The result file does not contain any actions" | tee "$GITHUB_STEP_SUMMARY"
exit 1
fi
- name: Check if the results file has duplicate actions
run: |
# check if the file has actions in it
# this is WIP, it seems like there where duplicates of the actions results since we picked up the normal repos in the forks search as well (was fixed)
echo "Actions array length = $(jq '.actions | length' "${{ steps.load-actions.outputs.actions-file-path }}")"
echo "Unique actions by name = $(jq '.actions | unique_by({name, repo}) | length' "${{ steps.load-actions.outputs.actions-file-path }}")"
if [ "$(jq '.actions | length' "${{ steps.load-actions.outputs.actions-file-path }}")" -ne "$(jq '.actions | unique_by({name, repo}) | length' "${{ steps.load-actions.outputs.actions-file-path }}")" ]; then
echo "The result file contains duplicate actions" | tee "$GITHUB_STEP_SUMMARY"
# group the actions to find the duplicates
jq '.actions | group_by({name, repo}) | map(select(length > 1))' "${{ steps.load-actions.outputs.actions-file-path }}"
exit 1
fi
# upload the second result file as an artefact
- name: Upload result file as artefact
if: always()
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: actions-user
path: ${{ steps.load-actions.outputs.actions-file-path }}
# run the test with a different filename
- uses: ./
name: Load available actions
with:
PAT: ${{ secrets.GITHUB_TOKEN }}
user: ${{ vars.USER }}
outputFilename: actions-second-run.json
id: load-actions-second-run
# check if the second result file is not empty
- name: Check if the second result file is not empty
run: |
if [ ! -s '${{ steps.load-actions-second-run.outputs.actions-file-path }}' ]; then
echo "The result file is empty" | tee "$GITHUB_STEP_SUMMARY"
exit 1
fi
# upload the second result file as an artefact
- name: Upload result file as artefact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: actions-user
path: ${{ steps.load-actions-second-run.outputs.actions-file-path }}
# validate that the two files have different names
- name: Validate that the two files have different names
run: |
if [ ${{ steps.load-actions.outputs.actions-file-path }} == ${{ steps.load-actions-second-run.outputs.actions-file-path }} ]; then
echo ":warning: The two files have the same name, this is not good" | tee "$GITHUB_STEP_SUMMARY"
exit 1
else
echo "The two files have different names, this is good" | tee "$GITHUB_STEP_SUMMARY"
fi
test-load-from-organization-with-forks: # test the action for the organization space
needs: test-load-from-user
runs-on: ubuntu-latest
concurrency: single-run-${{ github.EVENT_NAME }}-${{ github.REF }}
name: PR - Org with forks
env:
organization: ${{ vars.ORGANIZATION }}
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
# make sure we have a new build, in case the dist folder was not updated
- name: Compile with NPM
run: |
npm ci
npm run all
# run the test
- uses: ./
name: Load available actions
with:
PAT: ${{ secrets.GITHUB_TOKEN }}
organization: ${{ env.organization }}
id: load-actions
# check if the result file is not empty
- name: Check if the result file is not empty
run: |
if [ ! -s "${{ steps.load-actions.outputs.actions-file-path }}" ]; then
echo "The result file is empty" | tee "$GITHUB_STEP_SUMMARY"
exit 1
fi
echo "Found [$(jq '.actions | length' "${{ steps.load-actions.outputs.actions-file-path }}")] actions in the organization [${{ env.organization }}]" | tee "$GITHUB_STEP_SUMMARY"
- name: Check if the result file has actions in it
run: |
# check if the file has actions in it
if [ "$(jq '.actions | length' "${{ steps.load-actions.outputs.actions-file-path }}")" -eq 0 ]; then
echo ":warning: The result file does not contain any actions" | tee "$GITHUB_STEP_SUMMARY"
exit 1
fi
- name: Upload result file as artefact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
if: always()
with:
name: actions-organization-with-forks
path: ${{ steps.load-actions.outputs.actions-file-path }}
test-load-from-organization: # test the action for the organization space
name: PR - Org without forks
runs-on: ubuntu-latest
concurrency: single-run-${{ github.EVENT_NAME }}-${{ github.REF }}
env:
organization: actions # load from github.com/actions
if: always()
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
# make sure we have a new build, in case the dist folder was not updated
- name: Compile with NPM
run: |
npm ci
npm run all
# run the test
- uses: ./
name: Load available actions
with:
PAT: ${{ secrets.GITHUB_TOKEN }}
organization: ${{ env.organization }}
id: load-actions
# check if the result file is not empty
- name: Check if the result file is not empty
run: |
if [ ! -s '${{ steps.load-actions.outputs.actions-file-path }}' ]; then
echo "The result file is empty"
exit 1
fi
echo "Found [$(jq '.actions | length' "${{ steps.load-actions.outputs.actions-file-path }}")] actions in the organization [${{ env.organization }}]<br>Found [$(jq '.workflows| length' "${{ steps.load-actions.outputs.actions-file-path }}")] workflows in the organization [${{ env.organization }}]" | tee "$GITHUB_STEP_SUMMARY"
- name: Check if the result file has actions in it
run: |
# check if the file has actions in it
if [ "$(jq ".actions | length" "${{ steps.load-actions.outputs.actions-file-path }}")" -eq 0 ]; then
echo ":warning: The result file does not contain any actions" | tee "$GITHUB_STEP_SUMMARY"
exit 1
fi
- name: Check if the result file has workflows in it
run: |
# check if the file has workflows in it
if [ "$(jq ".workflows | length" "${{ steps.load-actions.outputs.actions-file-path }}")" -eq 0 ]; then
echo ":warning: The result file does not contain any workflows" | tee "$GITHUB_STEP_SUMMARY"
exit 1
fi
- name: Upload result file as artefact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: actions-organization
path: ${{ steps.load-actions.outputs.actions-file-path }}
Consolidate:
runs-on: ubuntu-latest
needs:
- test-load-from-user
- test-load-from-organization
- test-load-from-organization-with-forks
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
- run: |
ls -la
# make sure the three expected directories exists
if [ ! -d "actions-user" ]; then
echo "actions-user directory does not exist"
fi
if [ ! -d "actions-organization" ]; then
echo "actions-organization directory does not exist"
fi
if [ ! -d "actions-organization-with-forks" ]; then
echo "actions-organization-with-forks directory does not exist"
fi
# load the actions from the user
userActionsLength=$(jq -s '.[]' "./actions-user/actions.json")
organizationActionsLength=$(jq -s '.[]' "./actions-organization/actions.json")
organizationWithForksActionsLength=$(jq -s '.[]' "./actions-organization-with-forks/actions.json")
# test if the lenghts are all different
if ((userActionsLength == organizationActionsLength)); then
echo "The user actions and the organization actions are the same length, which should not be the case"
exit 1
fi
if ((organizationWithForksActionsLength == organizationActionsLength)); then
echo "The organization with forks actions and the organization actions are the same length, which should not be the case"
exit 1
fi
if ((userActionsLength == organizationWithForksActionsLength)); then
echo "The user actions and the organization with forks actions are the same length, which should not be the case"
exit 1
fi