-
Notifications
You must be signed in to change notification settings - Fork 27
211 lines (189 loc) · 6.68 KB
/
deploy-docs.yml
File metadata and controls
211 lines (189 loc) · 6.68 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
name: Deploy Documentation to GitHub Pages
on:
push:
branches:
- main
- Feb2026 # Feature branch for February 2026 release preview
paths:
- 'docs/**'
- 'docs/package.json'
- '.github/workflows/deploy-docs.yml'
- 'CHANGELOG.md'
pull_request:
branches:
- main
paths:
- 'docs/**'
- 'docs/package.json'
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: false
jobs:
security-scan:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 'docs/package-lock.json'
- name: Install dependencies
run: cd docs && npm ci
- name: Run security audit
continue-on-error: true
run: |
cd docs
npm audit --audit-level=moderate || true
- name: Check for vulnerabilities
continue-on-error: true
run: |
cd docs
AUDIT_RESULT=$(npm audit --json || true)
echo "$AUDIT_RESULT"
if command -v jq &> /dev/null; then
VULNERABILITIES=$(echo "$AUDIT_RESULT" | jq '.metadata.vulnerabilities.total // 0' 2>/dev/null || echo "0")
if [ "$VULNERABILITIES" -gt 0 ] 2>/dev/null; then
echo "::warning::Found $VULNERABILITIES vulnerabilities in documentation dependencies"
fi
else
echo "::notice::jq not available, skipping detailed vulnerability analysis"
fi
build:
name: Build Documentation
runs-on: ubuntu-latest
needs: security-scan
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for VitePress lastUpdated feature
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 'docs/package-lock.json'
- name: Cache VitePress build
uses: actions/cache@v4
with:
path: |
docs/.vitepress/.temp
docs/.vitepress/cache
key: ${{ runner.os }}-vitepress-${{ hashFiles('docs/**/*.md', 'docs/.vitepress/**') }}
restore-keys: |
${{ runner.os }}-vitepress-
- name: Install dependencies
run: cd docs && npm ci
- name: Build VitePress documentation
run: cd docs && npm run docs:build
- name: Verify build output
run: |
if [ ! -d "docs/.vitepress/dist" ]; then
echo "Error: Build output directory not found"
exit 1
fi
if [ ! -f "docs/.vitepress/dist/index.html" ]; then
echo "Error: index.html not found in build output"
exit 1
fi
echo "Build verification successful"
- name: Check for broken links
id: link-check
continue-on-error: true
run: |
cd docs/.vitepress/dist
# Install broken-link-checker
npm install -g broken-link-checker
# Start a simple HTTP server in the background
npx http-server -p 8080 -s &
SERVER_PID=$!
sleep 5
# Check for broken links (excluding external links for speed)
blc http://localhost:8080 -ro --exclude external --filter-level 3 || true
# Clean up
kill $SERVER_PID || true
- name: Report link check results
if: steps.link-check.outcome == 'failure'
run: echo "::warning::Broken links detected in documentation"
- name: Setup GitHub Pages
if: github.event_name != 'pull_request'
uses: actions/configure-pages@v4
- name: Upload artifact
if: github.event_name != 'pull_request'
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
retention-days: 1
- name: Upload PR preview artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: pr-preview-${{ github.event.pull_request.number }}
path: docs/.vitepress/dist
retention-days: 7
deploy:
name: Deploy to GitHub Pages
if: github.event_name != 'pull_request'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
outputs:
page_url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
notify:
name: Deployment Notification
if: github.event_name != 'pull_request' && always()
needs: [build, deploy]
runs-on: ubuntu-latest
steps:
- name: Send deployment notification
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
DEPLOY_STATUS: ${{ needs.deploy.result }}
DEPLOY_URL: ${{ needs.deploy.outputs.page_url }}
run: |
if [ -n "$SLACK_WEBHOOK_URL" ]; then
EMOJI="✅"
COLOR="good"
if [ "$DEPLOY_STATUS" != "success" ]; then
EMOJI="❌"
COLOR="danger"
fi
DOCS_URL="${DEPLOY_URL:-https://sap-samples.github.io/hana-developer-cli-tool-example/}"
curl -X POST "$SLACK_WEBHOOK_URL" \
-H 'Content-Type: application/json' \
-d "{
\"text\": \"$EMOJI Documentation Deployment: $DEPLOY_STATUS\",
\"attachments\": [{
\"color\": \"$COLOR\",
\"fields\": [
{\"title\": \"Repository\", \"value\": \"${{ github.repository }}\", \"short\": true},
{\"title\": \"Branch\", \"value\": \"${{ github.ref_name }}\", \"short\": true},
{\"title\": \"Commit\", \"value\": \"<${{ github.event.head_commit.url }}|${GITHUB_SHA:0:7}>\", \"short\": true},
{\"title\": \"URL\", \"value\": \"<$DOCS_URL|View Documentation>\", \"short\": true}
]
}]
}"
else
echo "Slack webhook not configured. Skipping notification."
echo "To enable notifications, add SLACK_WEBHOOK_URL secret to repository settings."
fi
- name: Comment on PR
if: github.event_name == 'pull_request'
run: |
echo "Documentation preview built successfully for PR #${{ github.event.pull_request.number }}"
echo "Artifact: pr-preview-${{ github.event.pull_request.number }}"