generated from CommonGateway/PetStoreBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
440 lines (383 loc) · 17.6 KB
/
plugin-documentation.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# Generates documentation for the schema's
name: Generate PlantUML and SVG files from JSON Schema
on:
push: # Trigger on any push
jobs:
generate-puml:
runs-on: ubuntu-latest
name: Generate PUML and markdown files
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install PlantUML
run: |
sudo apt-get update -y
sudo apt-get install -y plantuml
- name: Create docs/action directory if it doesn't exist
run: |
mkdir -p docs/action
- name: Create docs/collection directory if it doesn't exist
run: |
mkdir -p docs/collection
- name: Create docs/cronjob directory if it doesn't exist
run: |
mkdir -p docs/cronjob
- name: Create docs/mapping directory if it doesn't exist
run: |
mkdir -p docs/mapping
- name: Create docs/schema directory if it doesn't exist
run: |
mkdir -p docs/schema
- name: Create docs/security directory if it doesn't exist
run: |
mkdir -p docs/security
- name: Create docs/source directory if it doesn't exist
run: |
mkdir -p docs/source
- name: Find JSON files and Generate PUMl
run: |
# Embedded Python script to generate .puml files from JSON Schema
python << 'EOF'
import json
import os
repo_url = f"https://github.com/{os.environ['GITHUB_REPOSITORY']}/blob/{os.environ['GITHUB_REF'].split('/')[-1]}"
repo_name = os.environ['GITHUB_REPOSITORY'].split('/')[-1]
repo_owner = os.environ['GITHUB_REPOSITORY'].split('/')[0]
# Replace underscores and hyphens with spaces
repo_name = repo_name.replace('_', ' ').replace('-', ' ')
repo_owner = repo_owner.replace('_', ' ').replace('-', ' ')
# Capitalize each word
repo_name = repo_name.title()
repo_owner = repo_owner.title()
all_action_classes = []
all_collection_classes = []
all_cronjob_classes = []
all_mapping_classes = []
all_schema_classes = []
all_security_classes = []
all_source_classes = []
def generate_schema_puml(schema, puml_file_path):
title = schema.get('title', 'Untitled').replace(" ", "") # Remove spaces from title
class_def = [f"class {title} {{"]
properties = schema.get('properties', {})
for prop, details in properties.items():
class_def.append(f" + {prop}: {details.get('type', 'Any')}")
class_def.append("}")
all_schema_classes.append("\n".join(class_def))
with open(puml_file_path, 'w') as puml_file:
puml_file.write("@startuml\n")
puml_file.write(f"title: {title}\n")
puml_file.write(f"footer: Common Gateway Plugin | {repo_owner} | {repo_name} \n")
puml_file.write("header: Schema\n\n")
puml_file.write("\n".join(class_def))
puml_file.write("\n@enduml\n")
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith("schema.json"):
schema_file_path = os.path.join(root, file)
with open(schema_file_path, 'r') as f:
schema = json.load(f)
puml_file_name = os.path.basename(schema_file_path).replace("schema.json", "puml")
puml_file_path = os.path.join("docs/schema", puml_file_name)
generate_schema_puml(schema, puml_file_path)
# Generate an additional .puml file that includes all classes
with open("docs/action/all_action_classes.puml", 'w') as f:
f.write("@startuml\n")
f.write("title: All actions\n")
f.write(f"footer: Common Gateway Plugin | {repo_owner} | {repo_name} \n")
f.write("header: Action\n")
f.write("\n".join(all_action_classes))
f.write("\n@enduml\n")
with open("docs/collection/all_collection_classes.puml", 'w') as f:
f.write("@startuml\n")
f.write("title: All collections\n")
f.write(f"footer: Common Gateway Plugin | {repo_owner} | {repo_name} \n")
f.write("header: Collection\n")
f.write("\n".join(all_collection_classes))
f.write("\n@enduml\n")
with open("docs/cronjob/all_cronjob_classes.puml", 'w') as f:
f.write("@startuml\n")
f.write("title: All cronjobs\n")
f.write(f"footer: Common Gateway Plugin | {repo_owner} | {repo_name} \n")
f.write("header: Cronjob\n")
f.write("\n".join(all_cronjob_classes))
f.write("\n@enduml\n")
with open("docs/mapping/all_mapping_classes.puml", 'w') as f:
f.write("@startuml\n")
f.write("title: All mappings\n")
f.write(f"footer: Common Gateway Plugin | {repo_owner} | {repo_name} \n")
f.write("header: Mapping\n")
f.write("\n".join(all_mapping_classes))
f.write("\n@enduml\n")
with open("docs/schema/all_schema_classes.puml", 'w') as f:
f.write("@startuml\n")
f.write("title: All schemas\n")
f.write(f"footer: Common Gateway Plugin | {repo_owner} | {repo_name} \n")
f.write("header: Schema\n")
f.write("\n".join(all_schema_classes))
f.write("\n@enduml\n")
with open("docs/security/all_security_classes.puml", 'w') as f:
f.write("@startuml\n")
f.write("title: All security groups")
f.write(f"footer: Common Gateway Plugin | {repo_owner} | {repo_name} \n")
f.write("header: Security\n")
f.write("\n".join(all_security_classes))
f.write("\n@enduml\n")
with open("docs/source/all_source_classes.puml", 'w') as f:
f.write("@startuml\n")
f.write("title: All sources\n")
f.write(f"footer: Common Gateway Plugin | {repo_owner} | {repo_name} \n")
f.write("header: Source\n")
f.write("\n".join(all_source_classes))
f.write("\n@enduml\n")
EOF
# Let create the mardown documents
- name: Find JSON files and Generate Markdown
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF: ${{ github.ref }}
run: |
# Embedded Python script to generate .md files from JSON Schema
python << 'EOF'
import json
import os
repo_url = f"https://github.com/{os.environ['GITHUB_REPOSITORY']}/blob/{os.environ['GITHUB_REF'].split('/')[-1]}"
repo_name = os.environ['GITHUB_REPOSITORY'].split('/')[-1]
repo_owner = os.environ['GITHUB_REPOSITORY'].split('/')[0]
# Replace underscores and hyphens with spaces
repo_name = repo_name.replace('_', ' ').replace('-', ' ')
repo_owner = repo_owner.replace('_', ' ').replace('-', ' ')
# Capitalize each word
repo_name = repo_name.title()
repo_owner = repo_owner.title()
all_action_classes = []
all_collection_classes = []
all_cronjob_classes = []
all_mapping_classes = []
all_schema_classes = []
all_security_classes = []
all_source_classes = []
def generate_markdown(schema, md_file_path, svg_file_name):
with open(md_file_path, 'w') as md_file:
title = schema.get('title', 'Untitled')
md_file.write(f"# {title}\n\n")
md_file.write(f"{schema.get('description', 'No description available.')}\n\n")
absolute_svg_url = f"{repo_url}/docs/schema/{svg_file_name}"
md_file.write(f"![Class Diagram]({absolute_svg_url})\n\n")
md_file.write("## Properties\n\n")
md_file.write("| Property | Type | Description | Required |\n")
md_file.write("|----------|------|-------------|----------|\n")
required_fields = schema.get('required', [])
properties = schema.get('properties', {})
for prop, details in properties.items():
is_required = "Yes" if prop in required_fields else "No"
md_file.write(f"| {prop} | {details.get('type', 'Any')} | {details.get('description', 'N/A')} | {is_required} |\n")
all_schema_classes.append((title, md_file_path))
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith("schema.json"):
schema_file_path = os.path.join(root, file)
with open(schema_file_path, 'r') as f:
schema = json.load(f)
base_name = os.path.basename(schema_file_path).replace(".schema.json", "")
md_file_name = base_name + ".md"
svg_file_name = base_name + ".svg"
md_file_path = os.path.join("docs/schema", md_file_name)
generate_markdown(schema, md_file_path, svg_file_name)
# Generate a generic README.md in docs/action
with open("docs/action/README.md", 'w') as f:
f.write("# Action Documentation\n\n")
f.write("## Table of Actions\n\n")
f.write("| Action | Documentation |\n")
f.write("|-------|--------------|\n")
for title, md_file_path in all_action_classes:
md_file_name = os.path.basename(md_file_path)
f.write(f"| {title} | [{md_file_name}]({md_file_name}) |\n")
# Generate a generic README.md in docs/collection
with open("docs/collection/README.md", 'w') as f:
f.write("# Collection Documentation\n\n")
f.write("## Table of collections\n\n")
f.write("| Collection | Documentation |\n")
f.write("|-------|--------------|\n")
for title, md_file_path in all_collection_classes:
md_file_name = os.path.basename(md_file_path)
f.write(f"| {title} | [{md_file_name}]({md_file_name}) |\n")
# Generate a generic README.md in docs/cronjob
with open("docs/cronjob/README.md", 'w') as f:
f.write("# cronjob Documentation\n\n")
f.write("## Table of Cronjobs\n\n")
f.write("| cronjob | Documentation |\n")
f.write("|-------|--------------|\n")
for title, md_file_path in all_cronjob_classes:
md_file_name = os.path.basename(md_file_path)
f.write(f"| {title} | [{md_file_name}]({md_file_name}) |\n")
# Generate a generic README.md in docs/mapping
with open("docs/mapping/README.md", 'w') as f:
f.write("#Mapping Documentation\n\n")
f.write("## Table of mappings\n\n")
f.write("| Mapping | Documentation |\n")
f.write("|-------|--------------|\n")
for title, md_file_path in all_mapping_classes:
md_file_name = os.path.basename(md_file_path)
f.write(f"| {title} | [{md_file_name}]({md_file_name}) |\n")
# Generate a generic README.md in docs/schema
with open("docs/schema/README.md", 'w') as f:
f.write("# Schema Documentation\n\n")
f.write("## Table of Classes\n\n")
f.write("| Class | Documentation |\n")
f.write("|-------|--------------|\n")
for title, md_file_path in all_schema_classes:
md_file_name = os.path.basename(md_file_path)
f.write(f"| {title} | [{md_file_name}]({md_file_name}) |\n")
# Generate a generic README.md in docs/security
with open("docs/security/README.md", 'w') as f:
f.write("# Security Documentation\n\n")
f.write("## Table of Security Groups\n\n")
f.write("| Security | Documentation |\n")
f.write("|-------|--------------|\n")
for title, md_file_path in all_security_classes:
md_file_name = os.path.basename(md_file_path)
f.write(f"| {title} | [{md_file_name}]({md_file_name}) |\n")
# Generate a generic README.md in docs/source
with open("docs/source/README.md", 'w') as f:
f.write("#Source Documentation\n\n")
f.write("## Table of Sources\n\n")
f.write("| Class | Documentation |\n")
f.write("|-------|--------------|\n")
for title, md_file_path in all_source_classes:
md_file_name = os.path.basename(md_file_path)
f.write(f"| {title} | [{md_file_name}]({md_file_name}) |\n")
EOF
# Commit and push changes
- name: Commit and Push Generated Files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git pull
git add .
git commit -m "Add generated puml,svg,md and README files based on plugin installation files" || echo "No changes to commit"
git push
# Generate puml files
generate-plantuml:
runs-on: ubuntu-latest
name: Generate plant UML files
needs: generate-puml
steps:
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: plantuml
id: plantuml
uses: grassedge/[email protected]
with:
message: "Render PlantUML files"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# clean up the php code
php-cbf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: cs2pr, phpcbf
- name: Run phpcbf
run: phpcbf .
continue-on-error: true
- name: Git commit
run: |
git config user.name "GitHub Actions"
git config user.email ""
git add src
git commit -m "Update src from PHP Codesniffer" || echo "No changes to commit"
git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase --autostash
git push
generate-php-documentation:
name: Genereate php documentation
runs-on: ubuntu-latest
needs: [php-cbf]
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
with:
php_version: "7.4"
php_extensions: redis exif mongodb intl pdo_pgsql zip mysqli pdo_mysql pcntl gd gmp
version: 2.x
command: require clean/phpdoc-md
- name: Build the docs
run: vendor/bin/phpdoc-md
- name: Git commit
run: |
git config user.name "GitHub Actions"
git config user.email ""
git add docs/classes
git commit -m "Update phpdoc" || echo "No changes to commit"
git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase --autostash
git push
# clean up the markdowncode
remark-lint:
name: runner / remark-lint
runs-on: ubuntu-latest
needs: [generate-php-documentation,generate-puml]
steps:
- uses: actions/checkout@v2
- name: install remark presets
run: npm install remark-cli remark-preset-lint-consistent remark-preset-lint-recommended remark-lint-list-item-indent
shell: bash
- name: run remark
run: npx remark . --output --use remark-preset-lint-consistent --use remark-preset-lint-recommended --use remark-lint-list-item-indent
- name: Git commit
run: |
git config user.name "GitHub Actions"
git config user.email ""
git add .
git reset package.json
git reset package-lock.json
git reset node_modules
git commit -m "Update src from remark-lint" || echo "No changes to commit"
git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase --autostash
git push
# Create a pdf from the documentation
convert-to-pdf:
name: Build PDF
runs-on: ubuntu-latest
needs: [remark-lint,generate-plantuml]
steps:
- uses: actions/checkout@v3
- name: Build book
run: |-
npm install -g md-to-pdf
echo; echo "Adding root to PDF"
for f in *.md; do cat $f; echo; done | md-to-pdf > docs/manual.pdf
cd docs
echo; echo "Input Folder docs"
ls
echo; echo "Adding docs to PDF"
for f in *.md; do cat $f; echo; done | md-to-pdf > manual.pdf
cd features
echo; echo "Input Folder docs/features"
ls
echo; echo "Adding features to PDF"
for f in *.md; do cat $f; echo; done | md-to-pdf > ../manual.pdf
cd ../
echo; echo "Output DOCS Folder Listing"
ls
cd ..
- name: Git commit
run: |
git config user.name "GitHub Actions"
git config user.email ""
git add .
git reset package.json
git reset package-lock.json
git reset node_modules
git commit -m "Update src from remark-lint" || echo "No changes to commit"
git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase --autostash
git push