-
Notifications
You must be signed in to change notification settings - Fork 0
228 lines (188 loc) · 6.97 KB
/
docs-deploy.yml
File metadata and controls
228 lines (188 loc) · 6.97 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
# .github/workflows/docs-deploy.yml
# GitHub Actions workflow to build and deploy the MkDocs documentation
# site to GitHub Pages with enhanced CI integration and error handling.
name: Deploy Documentation
# Controls when the workflow will run
on:
push:
branches:
- main # Deploy when changes are pushed to the main branch
paths: # Only run if documentation-related files change
- "docs/**"
- "mkdocs.yml"
- "src/**" # Re-deploy if source code (for mkdocstrings) changes
- ".github/workflows/docs-deploy.yml" # Re-deploy if this workflow changes
- "pyproject.toml" # Re-deploy if dependencies change
- "poetry.lock" # Re-deploy if lock file changes
workflow_dispatch: # Allows manual triggering
inputs:
environment:
description: 'Deployment environment'
required: false
default: 'production'
type: choice
options:
- production
- staging
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages-${{ github.ref }}"
cancel-in-progress: false
env:
PYTHON_VERSION: "3.11"
POETRY_VERSION: "1.7.1"
jobs:
# Pre-deployment validation job
validate:
name: Pre-deployment Validation
runs-on: ubuntu-latest
outputs:
should-deploy: ${{ steps.validation.outputs.should-deploy }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached Poetry virtual environment
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-docs-v2-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-docs-v2-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --no-interaction --with docs
- name: Verify mkdocs installation
run: |
echo "Checking mkdocs installation..."
poetry run which mkdocs || echo "mkdocs not found in PATH"
poetry run mkdocs --version || echo "mkdocs --version failed"
- name: Validate MkDocs configuration
id: validation
run: |
# Test build to validate configuration
poetry run mkdocs build --clean --strict --verbose
# Validate all internal links
echo "✅ MkDocs configuration is valid"
echo "should-deploy=true" >> $GITHUB_OUTPUT
- name: Run documentation linting
run: |
# Check for broken internal links in markdown files
echo "Checking documentation quality..."
# Basic markdown validation could go here
# You could add markdownlint or other tools
echo "✅ Documentation validation complete"
# Main deployment job
deploy-docs:
name: Build and Deploy
needs: validate
if: needs.validate.outputs.should-deploy == 'true'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for git info in docs
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached Poetry virtual environment
id: cached-poetry-dependencies-deploy
uses: actions/cache@v4
with:
path: .venv
key: venv-docs-v2-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-docs-v2-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --no-interaction --with docs
- name: Build MkDocs site
run: |
echo "🏗️ Building MkDocs site..."
poetry run mkdocs build --clean --strict --verbose
# Verify build output
if [ ! -d "site" ]; then
echo "❌ Build failed: site directory not found"
exit 1
fi
if [ ! -f "site/index.html" ]; then
echo "❌ Build failed: index.html not found"
exit 1
fi
echo "✅ Build completed successfully"
# Add CNAME file for custom domain AFTER build
# echo "docs.codebrief.com" > site/CNAME # Uncomment and replace with your custom domain if needed
- name: Optimize build output
run: |
echo "🎯 Optimizing build output..."
# Remove unnecessary files
find site -name "*.map" -delete
find site -name ".DS_Store" -delete
echo "✅ Optimization complete"
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./site
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Report deployment success
if: success()
run: |
echo "🎉 Documentation deployed successfully!"
echo "📖 Site URL: ${{ steps.deployment.outputs.page_url }}"
# Post-deployment validation
post-deploy-check:
name: Post-deployment Check
needs: deploy-docs
runs-on: ubuntu-latest
if: always() && needs.deploy-docs.result == 'success'
steps:
- name: Wait for deployment
run: sleep 30
- name: Check site accessibility
run: |
SITE_URL="${{ needs.deploy-docs.outputs.page_url || 'https://shorzinator.github.io/CodeBrief' }}"
echo "🔍 Checking site accessibility at: $SITE_URL"
# Basic HTTP check
if curl -f -s -I "$SITE_URL" > /dev/null; then
echo "✅ Site is accessible"
else
echo "⚠️ Site may not be immediately accessible (this is normal for first deployments)"
fi
- name: Notify on failure
if: failure()
run: |
echo "❌ Post-deployment check failed"
echo "This might indicate an issue with the deployment"