generated from github/actions-learning-pathway
-
Notifications
You must be signed in to change notification settings - Fork 0
246 lines (198 loc) · 7.68 KB
/
hello-world.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
# name: hello-world
# on: push
# jobs:
# hello-world-job:
# name: Random action
# runs-on: ubuntu-latest
# steps:
# - name: Check original working directory
# shell: bash
# run: |
# echo "$(pwd)"
# - name: Create some random file
# shell: bash
# run: |
# echo "random text." > /tmp/randomtext.txt
# echo "$(pwd)"
# - name: Check out repository code
# uses: actions/checkout@v4
# - name: Show directory layout
# run: |
# echo "$(ls -lA /tmp)"
# echo "$(ls -lA /home/runner/work/ci_cd/ci_cd)"
# - name: Copy randomtext.txt into some location in repo
# shell: bash
# run:
# name: hello-world
# on: push
# jobs:
# upload-sample-file:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# - name: Install Python
# uses: actions/setup-python@v5
# with:
# python-version: '3.13'
# - name: Install dependencies
# run: pip install -r requirements.txt
# - name: Run script
# working-directory: ./src
# run: python create_file.py
# - name: Upload sample file
# uses: actions/upload-artifact@v4
# with:
# name: sample-file
# #working-directory: ./src
# path: src/sample_file.txt
# #path: ./output_files/sample_file.txt
# name: Update index.html in GH Pages and generate global sitemap
# on: push
# permissions: write-all
# jobs:
# run-global-sitemap-script-and-update-gh-pages:
# runs-on: ubuntu-latest
# steps:
# - name: Install Python
# uses: actions/setup-python@v5
# with:
# python-version: '3.13'
# - name: Install dependencies
# shell: bash
# run: |
# python -m pip install --upgrade pip
# pip install requests
# - name: Write script
# shell: bash
# run: |
# cat > /tmp/catsitemap.py << "EOF"
# import re
# import xml.etree.ElementTree as ET
# import requests
# from xml.dom import minidom
# def extract_urls_and_headers(url: str) -> tuple:
# """This function extracts projects names and sitemap.xml urls for each project
# Args:
# url (str): link to the .rst file of the PyAnsys documentation landing page
# Returns:
# tuple: returns a tuple of list of project names and list of urls to projects' sitemap.xml files
# """
# try:
# response = requests.get(url, timeout=10)
# except requests.exceptions.Timeout:
# print("Timed out while trying to get request")
# raise
# content = response.text
# # Extract section headers and URLs (modify regex based on your needs)
# project_names = [project_name.strip() for project_name in re.findall(r'\.\. grid-item-card:: ([\w\s-]+)', content)]
# urls = re.findall(r':link: (https://[\w./-]+)', content)
# # Modify URLs
# updated_urls = [re.match(r"^(https:\/\/[^\/]+)", url).group(1) + "/sitemap.xml" for url in urls]
# # Filter none existent URLS
# valid_project_names = []
# valid_urls = []
# for index, url in enumerate(updated_urls):
# if requests.get(url).status_code == 404:
# continue
# else:
# valid_project_names.append(project_names[index])
# valid_urls.append(url)
# return valid_project_names, valid_urls
# def generate_sitemap_index(url: str) -> None:
# """This function generates a sitemap_index.xml file indexing other sitemap.xml files
# Args:
# url (str): link to the .rst file of the PyAnsys documentation landing page
# """
# # Create the root element with namespace
# sitemap_index = ET.Element("sitemapindex", xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
# # Build the list of urls
# urls = extract_urls_and_headers(url)[1]
# # Create sitemap elements for each URL
# for url in urls:
# sitemap = ET.SubElement(sitemap_index, "sitemap")
# loc = ET.SubElement(sitemap, "loc")
# loc.text = url
# # Format XML with indentation
# rough_string = ET.tostring(sitemap_index, 'utf-8')
# reparsed = minidom.parseString(rough_string)
# pretty_xml = reparsed.toprettyxml(indent=" ")
# # Create the tree and write to XML file
# with open("globalsitemap.xml", "w") as f:
# f.write(pretty_xml)
# # URL of the .rst
# URL = "https://docs.pyansys.com/version/dev/_sources/index.rst.txt"
# generate_sitemap_index(URL)
# EOF
# - name: Run above script
# working-directory: /tmp
# shell: bash
# run: |
# python catsitemap.py
# - name: Checkout repository
# uses: actions/checkout@v4
# #with:
# #ref: gh-pages
# #- name: Replace 'version/stable' with 'version/dev' in index.html
# #run: |
# # Replace landing page with the dev version
# #cp version/dev/index.html index.html
# #sed -i 's/href="\([^:"]*\)"/href="version\/dev\/\1"/g' index.html
# #sed -i 's/src="\([^:"]*\)"/src="version\/dev\/\1"/g' index.html
# # Replace "version/stable" with "version/dev" in the sitemap.xml
# #sed -i 's/version\/stable/version\/dev/g' sitemap.xml
# - name: Copy globalsitemap.xml to root of gh-pages
# shell: bash
# run: |
# mv /tmp/globalsitemap.xml /home/runner/work/ci_cd/ci_cd/
# - name: "Commit changes"
# uses: EndBug/add-and-commit@v9
# with:
# default_author: github_actions
# message: "testing action script, especially that file is added"
name: Custom GH Pages Post-processing
on: push
# workflow_dispatch:
# workflow_call:
permissions: write-all
env:
MAIN_PYTHON_VERSION: '3.13'
jobs:
update-gh-pages:
runs-on: ubuntu-latest
steps:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install requests
- name: Checkout repository current branch
uses: actions/checkout@v4
- name: Copy tools folder to /tmp and run sitemap script
working-directory: /tmp
run: |
cp -r /home/runner/work/ci_cd/ci_cd/tools/ .
python ./tools/catsitemap.py
- name: Checkout repository test-branch branch
uses: actions/checkout@v4
with:
ref: test-branch
#- name: Replace 'version/stable' with 'version/dev' in index.html
#run: |
# Replace landing page with the dev version
#cp version/dev/index.html index.html
#sed -i 's/href="\([^:"]*\)"/href="version\/dev\/\1"/g' index.html
#sed -i 's/src="\([^:"]*\)"/src="version\/dev\/\1"/g' index.html
# Replace "version/stable" with "version/dev" in the sitemap.xml
#sed -i 's/version\/stable/version\/dev/g' sitemap.xml
- name: Move sitemaps/ to test-branch root
run: |
rm -rf sitemaps/ && mv /tmp/sitemaps/ .
- name: "Commit changes"
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "update sitemaps folder"