-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (189 loc) · 7.08 KB
/
deploy-docs.yml
File metadata and controls
210 lines (189 loc) · 7.08 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
name: Deploy Documentation to Cloudflare Pages v2
on:
push:
branches:
- main
- develop
paths:
- 'docs/**'
- '.github/workflows/deploy-docs.yml'
pull_request:
branches:
- main
- develop
paths:
- 'docs/**'
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'preview'
type: choice
options:
- preview
- production
env:
MDBOOK_VERSION: '0.4.40'
# 1Password secret references
OP_API_TOKEN: op://TerraphimPlatform/terraphim-md-book-cloudflare/workers-api-token
OP_ACCOUNT_ID: op://TerraphimPlatform/terraphim-md-book-cloudflare/account_id
OP_ZONE_ID: op://TerraphimPlatform/terraphim-md-book-cloudflare/zone-id
jobs:
build:
name: Build Documentation
runs-on: [self-hosted, linux, x64]
steps:
- name: Pre-checkout cleanup
run: |
sudo rm -rf "${{ github.workspace }}/target" "${{ github.workspace }}/desktop/dist" "${{ github.workspace }}/desktop/node_modules" "${{ github.workspace }}/terraphim_server/dist" 2>/dev/null || true
- name: Checkout repository
uses: actions/checkout@v6
- name: Clone md-book fork
run: |
rm -rf /tmp/md-book || true
git clone https://github.com/terraphim/md-book.git /tmp/md-book
cd /tmp/md-book
cargo build --release
- name: Build documentation with md-book
working-directory: docs
run: |
echo "=== DEBUG: Starting documentation build ==="
echo "DEBUG: Current directory: $(pwd)"
echo "DEBUG: Listing files:"
ls -la
echo "DEBUG: Checking md-book binary:"
ls -la /tmp/md-book/target/release/ || echo "md-book binary not found"
echo "DEBUG: Building with md-book fork..."
rm -rf book/
/tmp/md-book/target/release/md-book -i . -o book || true
echo "DEBUG: Build completed with exit code: $?"
- name: Upload build artifact
uses: actions/upload-artifact@v5
with:
name: docs-build
path: docs/book/
retention-days: 7
deploy-preview:
name: Deploy Preview
needs: build
if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'preview')
runs-on: [self-hosted, linux, x64]
permissions:
contents: read
deployments: write
pull-requests: write
id-token: write
environment:
name: docs-preview
url: ${{ steps.deploy.outputs.deployment-url }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: docs-build
path: docs/book/
- name: Load secrets from 1Password
id: op-load-secrets
uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ env.OP_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ env.OP_ACCOUNT_ID }}
- name: Deploy to Cloudflare Pages (Preview)
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ env.CLOUDFLARE_API_TOKEN }}
accountId: ${{ env.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy docs/book --project-name=terraphim-docs --branch=${{ github.head_ref || github.ref_name }}
- name: Comment PR with preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v8
with:
script: |
const deploymentUrl = '${{ steps.deploy.outputs.deployment-url }}';
const comment = `## Documentation Preview
Your documentation changes have been deployed to:
**${deploymentUrl}**
This preview will be available until the PR is closed.`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
deploy-production:
name: Deploy Production
needs: build
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
runs-on: [self-hosted, linux, x64]
permissions:
contents: read
deployments: write
id-token: write
environment:
name: docs-production
url: https://docs.terraphim.ai
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: docs-build
path: docs/book/
- name: Load secrets from 1Password
id: op-load-secrets
uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ env.OP_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ env.OP_ACCOUNT_ID }}
CLOUDFLARE_ZONE_ID: ${{ env.OP_ZONE_ID }}
- name: Deploy to Cloudflare Pages (Production)
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ env.CLOUDFLARE_API_TOKEN }}
accountId: ${{ env.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy docs/book --project-name=terraphim-docs --branch=main --commit-dirty=true
- name: Deployment Summary
run: |
echo "## Deployment Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Documentation has been deployed to:" >> $GITHUB_STEP_SUMMARY
echo "- **Production URL**: https://docs.terraphim.ai" >> $GITHUB_STEP_SUMMARY
echo "- **Cloudflare Pages URL**: ${{ steps.deploy.outputs.deployment-url }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Triggered by**: @${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
# Optional: Purge CDN cache after production deployment
purge-cache:
name: Purge CDN Cache
needs: deploy-production
runs-on: [self-hosted, linux, x64]
permissions:
id-token: write
steps:
- name: Load secrets from 1Password
id: op-load-secrets
uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ env.OP_API_TOKEN }}
CLOUDFLARE_ZONE_ID: ${{ env.OP_ZONE_ID }}
- name: Purge Cloudflare Cache
run: |
curl -X POST "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/purge_cache" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}' || true