-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (153 loc) Β· 7.05 KB
/
deploy-production.yml
File metadata and controls
174 lines (153 loc) Β· 7.05 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
name: Deploy to Production
on:
workflow_dispatch:
inputs:
environment:
description: "Deployment environment"
required: false
default: "production"
type: choice
options:
- production
- test
branch_name:
description: "Branch name for test deployment (only used if environment=test)"
required: false
default: "test"
type: string
repository_dispatch:
types: [deploy-production]
push:
branches:
- main
paths-ignore:
- "**.md"
- "docs/**"
jobs:
deploy:
name: Deploy to Cloudflare Pages and Update Notion
runs-on: ubuntu-latest
steps:
- name: Checkout code (main branch)
uses: actions/checkout@v4
with:
ref: main
- name: Checkout content files from content branch
run: |
set -e # Exit on error
echo "π₯ Fetching content from content branch..."
git fetch origin content
echo "π Checking out content files..."
git checkout origin/content -- docs/ i18n/ static/images/
# Validate content exists
echo "π Validating content..."
# Count markdown files across all languages
# Guard against missing directories to avoid find failures
# Support both .md and .mdx files (Docusaurus accepts both)
if [ -d docs ]; then
DOCS_COUNT=$(find docs \( -name "*.md" -o -name "*.mdx" \) -type f 2>/dev/null | wc -l)
else
DOCS_COUNT=0
fi
if [ -d i18n ]; then
I18N_COUNT=$(find i18n \( -name "*.md" -o -name "*.mdx" \) -type f 2>/dev/null | wc -l)
else
I18N_COUNT=0
fi
TOTAL_CONTENT=$((DOCS_COUNT + I18N_COUNT))
if [ "$TOTAL_CONTENT" -eq 0 ]; then
echo "β Error: No documentation content found"
echo " Expected: At least one .md or .mdx file in docs/ or i18n/ directories"
echo " Found: 0 files"
echo "Cannot proceed with build - documentation content is required"
exit 1
fi
# Warn if default locale (English) has no content
if [ "$DOCS_COUNT" -eq 0 ]; then
echo "β οΈ WARNING: No English content in docs/ directory"
echo " Docusaurus build may fail if default locale has no content"
fi
if [ ! -d "static/images" ] || [ -z "$(ls -A static/images 2>/dev/null)" ]; then
echo "β οΈ Warning: static/images/ directory is empty or missing"
echo "Build will proceed but images may be unavailable"
fi
echo "β
Content validation successful"
echo "π Content statistics:"
echo " - English docs: $DOCS_COUNT"
echo " - Localized docs: $I18N_COUNT"
echo " - Total docs: $TOTAL_CONTENT"
find static/images -type f 2>/dev/null | wc -l | xargs echo " - Images:"
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build documentation
env:
# Only set IS_PRODUCTION=true for actual production deployments
# Test deployments should have noindex to prevent search engine indexing
IS_PRODUCTION: ${{ inputs.environment != 'test' && 'true' || 'false' }}
run: bun run build
- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: >-
pages deploy build --project-name comapeo-docs
${{ inputs.environment == 'test' && format('--branch {0}', inputs.branch_name) || '' }}
${{ inputs.environment == 'test' && '--commit-dirty=true' || '' }}
- name: Update Notion status to Published
if: inputs.environment != 'test'
run: bun run notionStatus:publish-production
env:
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
DATA_SOURCE_ID: ${{ secrets.DATA_SOURCE_ID }}
DATABASE_ID: ${{ secrets.DATABASE_ID }}
- name: Deployment summary
run: |
if [ "${{ inputs.environment }}" = "test" ]; then
BRANCH_NAME="${{ inputs.branch_name }}"
echo "π§ͺ **Test Deployment Complete!**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- β
Documentation built successfully" >> $GITHUB_STEP_SUMMARY
echo "- β
Deployed to Cloudflare Pages (test)" >> $GITHUB_STEP_SUMMARY
echo "- π Test URL: https://${BRANCH_NAME}.comapeo-docs.pages.dev" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Note**: This is a test deployment. Notion status not updated." >> $GITHUB_STEP_SUMMARY
else
echo "π **Production Deployment Complete!**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- β
Documentation built successfully" >> $GITHUB_STEP_SUMMARY
echo "- β
Deployed to Cloudflare Pages" >> $GITHUB_STEP_SUMMARY
echo "- β
Notion status updated: Staging β Published" >> $GITHUB_STEP_SUMMARY
echo "- π
Published date set to $(date -u +%Y-%m-%d)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "π Site available at: https://docs.comapeo.app" >> $GITHUB_STEP_SUMMARY
fi
- name: Notify Slack
if: always()
uses: slackapi/slack-github-action@v2.1.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "*Deploy to Cloudflare Pages*: ${{ job.status }}"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "*Deploy to Cloudflare Pages*: ${{ job.status }}\nEnvironment: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || github.event_name == 'repository_dispatch' && 'production' || 'production' }}"
- type: "section"
text:
type: "mrkdwn"
text: "Trigger: <https://github.com/${{ github.triggering_actor }}|${{ github.triggering_actor }}>\nDetails: ${{ github.event_name == 'pull_request' && github.event.pull_request.html_url || github.event.head_commit.url || format('{0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id) }}"
- type: "section"
text:
type: "mrkdwn"
text: "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'test' && format('Preview URL: https://{0}.comapeo-docs.pages.dev', github.event.inputs.branch_name) || 'Production URL: https://docs.comapeo.app' }}"