-
Notifications
You must be signed in to change notification settings - Fork 245
100 lines (92 loc) · 3.44 KB
/
ci-sample-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
name: Sample Validation
on:
workflow_dispatch:
pull_request:
branches:
- dev
- main
push:
branches:
- dev
- main
jobs:
sample-validation:
runs-on: ubuntu-latest
permissions:
actions: read
steps:
- name: Checkout Pull Request
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Checkout Branch
if: ${{ github.event_name != 'pull_request' }}
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref_name }}
repository: ${{ github.repository }}
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Validate Sample Config
run: |
node validation-tool/validate-config.js .config/samples-config-v3.json
exit $?
- name: Run Sample Validation Tool Based on Sample Config
run: |
# This script runs the validation tool against all samples in the samples-config-v3.json file.
# External samples are excluded from the validation.
exceptions=("incoming-webhook-notification")
samples=`jq -r ".samples | .[] | select(has(\"downloadUrlInfo\") | not) | .id" .config/samples-config-v3.json`
validationFailed="validation failed"
validationResult=true
while IFS= read -r line; do
if [[ ! ${exceptions[@]} =~ $line ]]
then
result=`node ./validation-tool/validator.cjs -p $line`
if grep -q "$validationFailed" <<< "$result"; then
printf "\nSample '$line' validation failed.\n"
echo "$result"
validationResult=false
fi
fi
done <<< "$samples"
if [ "$validationResult" = false ]; then
exit 1
fi
- name: Get Changed Folders
id: get_changed_folders
if: ${{ github.event_name == 'pull_request' }}
uses: Stockopedia/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
ignore: "**/+(.github)"
foldersOnly: true
format: json
- name: Run Sample Validation Tool on New Sample
if: ${{ github.event_name == 'pull_request' }}
run: |
# This script runs the validation tool against changed samples in the pull request.
# External samples are excluded from the validation.
exceptions=(".config" ".devcontainer" "assets" "templates" "validation-tool" "basic-blazor-tab-app" "incoming-webhook-notification" "stocks-update-notification-bot-dotnet" "whos-next-meeting-app")
samples=`jq -r ".[]" <<< '${{ steps.get_changed_folders.outputs.changed }}'`
validationFailed="validation failed"
validationResult=true
while IFS= read -r line; do
if [[ ! ${exceptions[@]} =~ $line ]]
then
result=`node ./validation-tool/validator.cjs -p $line`
if grep -q "$validationFailed" <<< "$result"; then
printf "\nSample '$line' validation failed.\n"
echo "$result"
validationResult=false
fi
fi
done <<< "$samples"
if [ "$validationResult" = false ]; then
exit 1
fi