forked from meshery/meshery.io
-
Notifications
You must be signed in to change notification settings - Fork 0
235 lines (206 loc) · 9.56 KB
/
add-catalog.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
name: Add Cloud Native Catalog Items
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
repository_dispatch:
types: [add_catalog]
jobs:
UpdateCloudNativeCatalog:
runs-on: ubuntu-22.04
outputs:
contentID: ${{ steps.update_catalog_patterns.outputs.contentID }}
assetLocation: ${{ steps.update_catalog_patterns.outputs.assetLocation }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACCESS_TOKEN }}
- name: Set env
run : |
echo "MESHERY_CLOUD_BASE_URL=https://meshery.layer5.io" >> $GITHUB_ENV
echo "MESHERY_CATALOG_FILES_DIR=catalog" >> $GITHUB_ENV
- name: Cleanup
run: |
find $MESHERY_CATALOG_FILES_DIR ! -name 'index.html' -maxdepth 1 -type f -delete
cd ./collections/_catalog
for dir in */; do find $dir -maxdepth 1 -type f -delete; done
cd ../../
- id: update_catalog_patterns
name: Update Catalog Patterns
shell: bash
if: ${{ success() }}
run: |
catalogPatterns=$(curl -sS "$MESHERY_CLOUD_BASE_URL/api/catalog/content/pattern" 2>./err.txt)
if [[ "$(<err.txt)" != "" ]]; then
>&2 echo "Error connecting to Meshery Cloud"
>&2 echo "$(<err.txt)"
fi
echo "$catalogPatterns" | jq -r '.patterns' > temp.json
patternCount=$(echo "$catalogPatterns" | jq '.total_count')
echo "Found $patternCount catalog patterns"
for (( idx=0; idx<$patternCount; idx++ ))
do
designId=$(jq -r .[$idx].id temp.json)
patternInfo="$(jq -r .[$idx].catalog_data.pattern_info temp.json)"
patternCaveats="$(jq -r .[$idx].catalog_data.pattern_caveats temp.json)"
patternType="$(jq -r .[$idx].catalog_data.type temp.json)"
patternName="$(jq -r .[$idx].name temp.json)"
patternImageURL="$(jq -r .[$idx].catalog_data.imageURL temp.json)"
patternFile="$(jq -r .[$idx].pattern_file temp.json)"
if [[ $patternImageURL == "null" || $patternImageURL == "" ]]; then
patternImageURL=https://raw.githubusercontent.com/layer5labs/meshery-extensions-packages/master/action-assets/design-assets/$designId.png
fi
compatibility=""
echo "contentID=$designId" >> $GITHUB_OUTPUT
echo "assetLocation=$patternImageURL" >> $GITHUB_OUTPUT
# check if directory doesn't exists; then create it
if [ ! -d "./collections/_catalog/"$(echo $patternType | tr '[:upper:]' '[:lower:]')"" ]; then
echo "$(echo $patternType | tr '[:upper:]' '[:lower:]') doesn't exist."
echo "Creating directory...$(echo $patternType | tr '[:upper:]' '[:lower:]')"
mkdir "./collections/_catalog/"$(echo $patternType | tr '[:upper:]' '[:lower:]')""
fi
if [[ $patternInfo == "null" ]]; then
patternInfo="\"\""
fi
if [[ $patternCaveats == "null" ]]; then
patternCaveats="\"\""
fi
if [[ $patternType == "null" ]]; then
patternType="Deployment"
fi
compatLength=$(jq -r ".[$idx].catalog_data.compatibility | length" temp.json)
for (( compatIdx=0; compatIdx<$compatLength; compatIdx++ ))
do
compatibility+="
"
compatibility+=" - $(jq -r ".[$idx].catalog_data.compatibility[$compatIdx]" temp.json)"
done
echo "$patternFile" > $MESHERY_CATALOG_FILES_DIR/$designId.yaml
services=$(yq '.services' $MESHERY_CATALOG_FILES_DIR/$designId.yaml 2>/dev/null)
if [[ $services == "null" || $services == "" ]]; then
patternImageURL="/assets/images/logos/service-mesh-pattern.svg"
fi
userId=$(jq -r .[$idx].user_id temp.json)
userInfo=$(curl -sS "$MESHERY_CLOUD_BASE_URL/api/identity/users/profile/$userId" 2>./err1.txt)
if [[ "$(<err1.txt)" != "" ]]; then
>&2 echo "Error fetching User details"
>&2 echo "$(<err1.txt)"
fi
echo "$userInfo" > info.json
userFullName="$(jq -r .first_name info.json) $(jq -r .last_name info.json)"
userAvatarURL="$(jq -r .avatar_url info.json)"
echo "---
layout: item
name: $patternName
userId: $userId
userName: $userFullName
userAvatarURL: $userAvatarURL
type: $patternType
compatibility: $compatibility
patternId: $designId
image: $patternImageURL
patternInfo: |
$patternInfo
patternCaveats: |
$patternCaveats
URL: 'https://raw.githubusercontent.com/meshery/meshery.io/master/$MESHERY_CATALOG_FILES_DIR/$designId.yaml'
downloadLink: $designId.yaml
---" > ./collections/_catalog/"$(echo $patternType | tr '[:upper:]' '[:lower:]')"/$designId.md
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_ACCESS_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/meshery/meshery.io/actions/workflows/meshmap.yml/dispatches" \
-d '{"ref":"master","inputs":{"contentID":"'$designId'","assetLocation":"'$patternImageURL'"}}'
done
rm temp.json
rm err.txt
rm info.json
rm err1.txt
- name: Update Catalog Filters
if: ${{ success() }}
run: |
catalogFilters=$(curl -sS "$MESHERY_CLOUD_BASE_URL/api/catalog/content/filter" 2>./err.txt)
if [[ "$(<err.txt)" != "" ]]; then
>&2 echo "Error connecting to Meshery Cloud"
>&2 echo "$(<err.txt)"
fi
echo "$catalogFilters" | jq -r '.filters' > temp.json
filterCount=$(echo "$catalogFilters" | jq '.total_count')
echo "Found $filterCount catalog filters"
echo "Found $filterCount catalog filters"
for (( idx=0; idx<$filterCount; idx++ ))
do
filterId=$(jq -r .[$idx].id temp.json)
filterInfo="$(jq -r .[$idx].catalog_data.filter_info temp.json)"
filterCaveats="$(jq -r .[$idx].catalog_data.filter_caveats temp.json)"
filterType="$(jq -r .[$idx].catalog_data.type temp.json)"
filterName="$(jq -r .[$idx].name temp.json)"
filterImageURL="$(jq -r .[$idx].catalog_data.imageURL temp.json)"
compatibility=""
echo "contentID=$designId" >> $GITHUB_OUTPUT
echo "assetLocation=$patternImageURL" >> $GITHUB_OUTPUT
# check if directory doesn't exists; then create it
if [ ! -d "./collections/_catalog/"$(echo $filterType | tr '[:upper:]' '[:lower:]')"" ]; then
echo "$(echo $filterType | tr '[:upper:]' '[:lower:]') doesn't exist."
echo "Creating directory...$(echo $filterType | tr '[:upper:]' '[:lower:]')"
mkdir "./collections/_catalog/"$(echo $filterType | tr '[:upper:]' '[:lower:]')""
fi
if [[ $filterInfo == "null" ]]; then
filterInfo="\"\""
fi
if [[ $filterCaveats == "null" ]]; then
filterCaveats="\"\""
fi
if [[ $filterType == "null" ]]; then
patternType="wasm filter"
fi
compatLength=$(jq -r ".[$idx].catalog_data.compatibility | length" temp.json)
for (( compatIdx=0; compatIdx<$compatLength; compatIdx++ ))
do
compatibility+="
"
compatibility+=" - $(jq -r ".[$idx].catalog_data.compatibility[$compatIdx]" temp.json)"
done
filterFile="$(jq -r .[$idx].filter_file temp.json)"
echo "$filterFile" > $MESHERY_CATALOG_FILES_DIR/$filterId.yaml
userId=$(jq -r .[$idx].user_id temp.json)
userInfo=$(curl -sS "$MESHERY_CLOUD_BASE_URL/api/identity/users/profile/$userId" 2>./err1.txt)
if [[ "$(<err1.txt)" != "" ]]; then
>&2 echo "Error fetching User details"
>&2 echo "$(<err1.txt)"
fi
echo "$userInfo" > info.json
userFullName="$(jq -r .first_name info.json) $(jq -r .last_name info.json)"
userAvatarURL="$(jq -r .avatar_url info.json)"
echo "---
layout: item
name: $filterName
userId: $userId
userName: $userFullName
userAvatarURL: $userAvatarURL
type: $filterType
compatibility: $compatibility
patternId: $filterId
image: /assets/images/webassembly_logo.svg
filterInfo: |
$filterInfo
filterCaveats: |
$filterCaveats
URL: 'https://raw.githubusercontent.com/meshery/meshery.io/master/$MESHERY_CATALOG_FILES_DIR/$filterId.yaml'
downloadLink: $filterId.yaml
---" > ./collections/_catalog/"$(echo $filterType | tr '[:upper:]' '[:lower:]')"/$filterId.md
done
rm temp.json
rm err.txt
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: catalog/* collections/_catalog/*
commit_user_name: l5io
commit_user_email: [email protected]
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
commit_options: '--signoff'
commit_message: '[Catalog] Update Catalog items'