-
Notifications
You must be signed in to change notification settings - Fork 29
212 lines (186 loc) · 7.82 KB
/
cleanup-pr-docs.yml
File metadata and controls
212 lines (186 loc) · 7.82 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
name: Cleanup PR Documentation
on:
pull_request:
types: [closed]
env:
http_proxy: http://proxy-dmz.intel.com:912
https_proxy: http://proxy-dmz.intel.com:912
permissions:
contents: write
jobs:
cleanup-pr-docs:
runs-on: [self-hosted, Linux]
if: github.repository_owner == 'intel-innersource'
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages-repo
clean: false
continue-on-error: true
- name: Remove PR documentation
run: | #bash
if [ ! -d "gh-pages-repo/.git" ]; then
echo "gh-pages branch doesn't exist, nothing to clean up"
exit 0
fi
cd gh-pages-repo
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Determine PR directory name
PR_DIR="pr-${{ github.event.pull_request.number }}"
# Check if the PR directory exists
if [ ! -d "$PR_DIR" ]; then
echo "No documentation found for $PR_DIR, nothing to clean up"
exit 0
fi
echo "Removing documentation for $PR_DIR..."
rm -rf "$PR_DIR"
# Update the index page to reflect the removal
python3 <<'PYTHON'
import os
import json
from datetime import datetime
versions = []
# Scan for all directories
for item in os.listdir('.'):
if os.path.isdir(item) and item not in ['.git', '.github']:
# Check if it has an index.html (valid documentation)
if os.path.exists(os.path.join(item, 'index.html')):
# Determine if it's a PR or branch
if item.startswith('pr-'):
pr_num = item[3:]
name = f"PR #{pr_num}"
sort_key = ('pr', int(pr_num))
elif item == 'master':
name = "Master Documentation"
sort_key = ('master', 0)
else:
name = f"{item.replace('_', ' ').title()} Branch"
sort_key = ('branch', item)
versions.append({
'name': name,
'branch': item,
'url': f'./{item}/index.html',
'updated': datetime.now().strftime('%Y-%m-%d %H:%M:%S UTC'),
'sort_key': sort_key
})
# Sort versions: master first, then PRs (newest first), then branches alphabetically
versions.sort(key=lambda x: (
x['sort_key'][0] != 'master',
x['sort_key'][0] != 'pr',
-x['sort_key'][1] if isinstance(x['sort_key'][1], int) else x['sort_key'][1]
))
# Remove sort_key from output
for v in versions:
del v['sort_key']
# Create index.html template
html_template = '''<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Level Zero Specification Documentation</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
max-width: 900px;
margin: 50px auto;
padding: 20px;
line-height: 1.6;
color: #333;
}
h1 {
color: #0066cc;
border-bottom: 3px solid #0066cc;
padding-bottom: 10px;
}
.version-card {
background: #f5f5f5;
border-left: 4px solid #0066cc;
padding: 20px;
margin: 20px 0;
border-radius: 4px;
}
.version-card h2 {
margin-top: 0;
color: #0066cc;
}
.version-card a {
display: inline-block;
background: #0066cc;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 4px;
margin-top: 10px;
}
.version-card a:hover {
background: #0052a3;
}
.branch-name {
font-family: 'Courier New', monospace;
background: #e0e0e0;
padding: 2px 6px;
border-radius: 3px;
}
.updated {
color: #666;
font-size: 0.9em;
}
</style>
</head>
<body>
<h1>Level Zero Specification Documentation</h1>
<p>Welcome to the Level Zero Specification documentation. Select a version below to view the documentation.</p>
<div id="versions"></div>
<script>
// This will be populated by the deployment script
const versions = VERSIONS_PLACEHOLDER;
const container = document.getElementById('versions');
versions.forEach(version => {
const card = document.createElement('div');
card.className = 'version-card';
card.innerHTML = `
<h2>${version.name}</h2>
<p>Branch: <span class="branch-name">${version.branch}</span></p>
<p class="updated">Last updated: ${version.updated}</p>
<a href="${version.url}">View Documentation →</a>
`;
container.appendChild(card);
});
</script>
</body>
</html>'''
# Replace the placeholder with actual version data
versions_json = json.dumps(versions, indent=2)
html = html_template.replace('VERSIONS_PLACEHOLDER', versions_json)
# Write the updated index.html
with open('index.html', 'w') as f:
f.write(html)
print(f"Updated index with {len(versions)} version(s)")
PYTHON
# Add all changes
git add .
# Commit if there are changes
if git diff --staged --quiet; then
echo "No changes to commit"
else
if [ "${{ github.event.pull_request.merged }}" = "true" ]; then
git commit -m "Remove documentation for PR #${{ github.event.pull_request.number }} (merged)"
else
git commit -m "Remove documentation for PR #${{ github.event.pull_request.number }} (closed)"
fi
git push origin gh-pages
echo "✅ PR documentation cleaned up successfully!"
fi
- name: Output cleanup info
run: | #bash
echo "🧹 Cleaned up documentation for PR #${{ github.event.pull_request.number }}"
if [ "${{ github.event.pull_request.merged }}" = "true" ]; then
echo " Status: Merged and removed"
else
echo " Status: Closed and removed"
fi