-
-
Notifications
You must be signed in to change notification settings - Fork 1
301 lines (299 loc) · 12.3 KB
/
upgrade-documentation.yml
File metadata and controls
301 lines (299 loc) · 12.3 KB
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
name: Upgrade documentation (Wiki + README.md)
on: [workflow_dispatch, push]
jobs:
UML-export:
runs-on: ubuntu-latest
environment:
name: UML
steps:
- uses: actions/checkout@v2
- name: Export UML
uses: docker://rlespinasse/drawio-export:latest
with:
args: -f svg -o img
- name: git add & commit & upload repo
continue-on-error: true
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "help@castellanidavide.it"
git add *
git commit -m "Exported UML automatically"
git push https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git
upgrade-documentation:
runs-on: ubuntu-latest
environment:
name: documentation
steps:
- name: Initial setup
run: |
sudo apt update -y
sudo pip install BeautifulSoup4
{
git clone --recurse-submodules --depth 1 https://$.GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.wiki.git wiki
} || {
mkdir wiki
}
git clone --recurse-submodules --depth 1 https://$.GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git -b $(echo ${GITHUB_REF#refs/heads/}) repo
rm -f wiki/*.md
- name: Home file
run: |
cd wiki
python3 << EOF
def get_content():
""" Returns the file content
"""
file_content = "## :octocat: Description :octocat:\n"
file_content += "/img/createstructure.github.io-BMC.svg)\n\n"
return file_content
if __name__ == "__main__":
open("Home.md", "w+").write(str(get_content()))
EOF
- name: Repos structure file
run: |
cd wiki
python3 << EOF
import urllib.request
import json
from bs4 import BeautifulSoup
def get_json(repo):
""" Returns the json with REST description
"""
return json.loads(urllib.request.urlopen(f"$GITHUB_API_URL/repos/createstructure/{repo}").read().decode())
def get_social_img(repo):
""" Get social image
"""
soup = BeautifulSoup(urllib.request.urlopen(f"$GITHUB_SERVER_URL/createstructure/{repo}").read().decode(), 'html.parser')
return soup.find("meta", property="og:image")["content"]
def get_content(repo):
""" Returns the file content
"""
if repo in ["createstructure.github.io"]:
social_img = get_social_img(repo)
file_content = get_json(repo)["description"].replace(". ", ".\n\n").replace("wiki", f"[wiki]($GITHUB_SERVER_URL/createstructure/{repo}/wiki)") + "\n"
file_content += f"\n"
return file_content
else:
replacements = {
"## :octocat: Description :octocat:\n": "",
}
file = urllib.request.urlopen(f"https://raw.githubusercontent.com/wiki/createstructure/{repo}/Home.md").read().decode()
for key, value in replacements.items():
file = file.replace(key, value)
file = file.rstrip("\n")
file += "\n\n"
return file
def get_repos_structure(repos):
""" Returns the repos structure
"""
repos_structure = "## Repos structure\n\n"
for repo in repos:
repos_structure += f"### {repo}\n"
repos_structure += get_content(repo)
return repos_structure
if __name__ == "__main__":
repos = [
"app-createstructure",
"debian-createstructure",
"rest-createstructure",
"createstructure.github.io",
"manager-createstructure",
"core-createstructure",
"librerias-createstructure",
"default-template"
]
content = get_repos_structure(repos)
open("Repos-structure.md", "w+").write(content)
EOF
- name: Directory structure file
run: |
cd wiki
sudo apt install tree -y
echo "## :octocat: Directory structure :octocat:" > Directory-Structure.md
echo "" >> Directory-Structure.md
echo "\`\`\`" >> Directory-Structure.md
tree ../repo >> Directory-Structure.md
echo "\`\`\`" >> Directory-Structure.md
sed -i 's/docs/docs # documentation/g' Directory-Structure.md
- name: LICENSE file
run: |
cd wiki
echo "## :octocat: License :octocat:" > LICENSE.md
echo "" >> LICENSE.md
cat ../repo/LICENSE >> LICENSE.md
- name: Privacy policy file
run: |
cd wiki
echo "## :octocat: Privacy policy :octocat:" > Privacy-policy.md
echo "" >> Privacy-policy.md
cat ../repo/Privacy-Policy.md >> Privacy-policy.md
- name: CODE-OF-CONDUCT file
run: |
cd wiki
echo "## :octocat: Code of conduct :octocat:" > CODE-OF-CONDUCT.md
echo "" >> CODE-OF-CONDUCT.md
cat ../repo/CODE_OF_CONDUCT.md >> CODE-OF-CONDUCT.md
- name: Subscription to the service file
run: |
cd wiki
cat ../repo/subscription-to-the-service.md >> Subscription-to-the-service.md
sed -i 's/## Subscription to the service/## :octocat: Subscription to the service :octocat:/g' Subscription-to-the-service.md
- name: How to contribute file
run: |
cd wiki
cat ../repo/how-to-contribute.md >> How-to-contribute.md
sed -i 's/## How to contribute/## :octocat: How to contribute :octocat:/g' How-to-contribute.md
- name: How to use file
run: |
cd wiki
cat ../repo/how-to-use.md >> How-to-use.md
sed -i 's/## How to use/## :octocat: How to use :octocat:/g' How-to-use.md
- name: How to create your own template file
run: |
cd wiki
cat ../repo/how-to-create-your-own-template.md >> How-to-create-your-own-template.md
sed -i 's/## How to create your own template/## :octocat: How to create your own template :octocat:/g' How-to-create-your-own-template.md
- name: _Footer file
run: |
cd wiki
echo "---" > _Footer.md
echo "Made w/ :heart: by Castellani Davide" >> _Footer.md
echo "" >> _Footer.md
echo "If you want to contribute you can start with:" >> _Footer.md
echo "- [Discussion]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/discussions)" >> _Footer.md
echo "- [Issue]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/issues/new)" >> _Footer.md
- name: _Header file
run: |
cd wiki
echo "# createstructure" > _Header.md
echo "[]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/blob/$(echo ${GITHUB_REF#refs/heads/})/docs/LICENSE)" >> _Header.md
echo "" >> _Header.md
echo " " >> _Header.md
echo "" >> _Header.md
- name: Recreate README.md
run: |
cd repo
python3 << EOF
import urllib.request
import json
def get_link_table_of_contents(repo, spaces=4):
""" Returns the table of contents for the repo
"""
return spaces * " " + f"- [{repo}](#{repo})\n"
def get_intro():
""" Returns the intro
"""
return "# createstructure\n\n"
def get_table_of_contents(repos):
""" Returns the table of contents
"""
default = [
"- [createstructure](#createstructure)",
" - [Table of contents](#table-of-contents)",
" - [Description](#description)",
" - [subscription to the service](#subscription-of-the-service)",
" - [How to use](#how-to-use)",
" - [How to create your own template](#how-to-create-your-own-template)",
" - [How to contribute](#how-to-contribute)",
" - [Privacy Policy](#privacy-policy)",
" - [Repos structure](#repos-structure)",
]
table_of_contents = "## Table of Contents\n"
for d in default:
table_of_contents += d + "\n"
for repo in repos:
table_of_contents += get_link_table_of_contents(repo)
table_of_contents += "\n"
return table_of_contents
def get_description():
""" Returns the description
"""
description = open("../wiki/Home.md", "r+").read().replace(":octocat:", "")
description += "\n\n"
return description
def get_subscription_to_the_service():
""" Returns the subscription to the service
"""
return open("./subscription-to-the-service.md", "r+").read()
def get_how_to_contribute():
""" Returns the how to contribute
"""
return open("./how-to-contribute.md", "r+").read()
def get_how_to_use():
""" Returns the how to use
"""
return open("./how-to-use.md", "r+").read()
def get_how_to_create_your_own_template():
""" Returns the how to create your own template
"""
return open("./how-to-create-your-own-template.md", "r+").read()
def get_privacy_policy():
""" Returns the privacy policy
"""
privacy_policy = "## Privacy policy\n"
privacy_policy += "Press the image below to see the privacy policy.\n"
privacy_policy += "[](./Privacy-Policy.md)"
privacy_policy += "\n\n"
return privacy_policy
def get_repos_structure():
""" Returns the repos structure
"""
return open("../wiki/Repos-structure.md", "r+").read()
def get_outro():
""" Returns the outro
"""
outro = "---\n"
outro += "Made with ❤️ by @DavideC03\n\n"
outro += "If you have any questions, please contact my community and me:\n\n"
outro += "- [Discussion](https://github.com/createstructure/createstructure/discussions/new)\n"
outro += "- [Issues](https://github.com/createstructure/createstructure/issues/new)\n"
outro += "- [Mail](mailto:help@castellanidavide.it)\n"
return outro
def get_readme():
""" Returns the readme
"""
repos = [
"app-createstructure",
"debian-createstructure",
"rest-createstructure",
"createstructure.github.io",
"manager-createstructure",
"core-createstructure",
"librerias-createstructure",
"default-template"
]
readme = get_intro()
readme += get_table_of_contents(repos)
readme += get_description()
readme += get_subscription_to_the_service()
readme += get_how_to_use()
readme += get_how_to_create_your_own_template()
readme += get_how_to_contribute()
readme += get_privacy_policy()
readme += get_repos_structure()
readme += get_outro()
return readme
if __name__ == "__main__":
open("README.md", "w").write(get_readme())
EOF
- name: git add & commit & upload wiki
continue-on-error: true
run: |
{
ls wiki/.git/ > /dev/null
} && {
cd wiki
git config user.name "$GITHUB_ACTOR"
git config user.email "help@castellanidavide.it"
git add *
git commit -m "Upgrade by automatic action"
git push https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.wiki.git
}
- name: git add & commit & upload repo
continue-on-error: true
run: |
cd repo
git config user.name "$GITHUB_ACTOR"
git config user.email "help@castellanidavide.it"
git add *
git commit -m "Upgrade by automatic action"
git push https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git