-
Notifications
You must be signed in to change notification settings - Fork 5
328 lines (289 loc) · 13.8 KB
/
dartdoc-gh-pages.yml
File metadata and controls
328 lines (289 loc) · 13.8 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# =============================================================================
# Dartdoc Deployment Workflow
# =============================================================================
#
# This workflow generates API documentation using Dartdoc for the ouds_core
# package and deploys it to GitHub Pages.
#
# 🌐 Production URL: https://flutter.unified-design-system.orange.com/
# 🔍 PR Preview URL: https://flutter.unified-design-system.orange.com/prPreview/<PR_NUMBER>/
#
# Architecture:
# - Branch: gh-pages
# - Folder: /docs (configured in GitHub Pages settings)
# - Custom domain: flutter.unified-design-system.orange.com (via CNAME)
#
# Jobs overview:
# ┌─────────────────┬────────────────────────────────────────────────────────┐
# │ Job │ Description │
# ├─────────────────┼────────────────────────────────────────────────────────┤
# │ build │ Generates dartdoc and uploads as artifact │
# │ deploy │ Deploys to production (push/dispatch only) │
# │ deploy-preview │ Deploys PR preview to /prPreview/<number>/ │
# │ cleanup-preview │ Removes PR preview when PR is closed/merged │
# └─────────────────┴────────────────────────────────────────────────────────┘
#
# Trigger matrix:
# ┌─────────────────────┬───────┬────────┬────────────────┬─────────────────┐
# │ Event │ build │ deploy │ deploy-preview │ cleanup-preview │
# ├─────────────────────┼───────┼────────┼────────────────┼─────────────────┤
# │ push main/develop │ ✅ │ ✅ │ ❌ │ ❌ │
# │ workflow_dispatch │ ✅ │ ✅ │ ❌ │ ❌ │
# │ PR opened/sync │ ✅ │ ❌ │ ✅ │ ❌ │
# │ PR closed/merged │ ❌ │ ❌ │ ❌ │ ✅ │
# └─────────────────────┴───────┴────────┴────────────────┴─────────────────┘
# =============================================================================
name: Deploy Dartdoc with GitHub Pages dependencies preinstalled
# -----------------------------------------------------------------------------
# Triggers
# -----------------------------------------------------------------------------
on:
# Deploy production docs when code is pushed to main or develop
push:
branches:
- main
- develop
# Allow manual trigger from GitHub Actions UI
workflow_dispatch:
# Handle pull requests for preview deployments and cleanup
pull_request:
types:
- opened # New PR → deploy preview
- synchronize # New commits pushed → update preview
- closed # PR merged/closed → cleanup preview
permissions:
read-all
# -----------------------------------------------------------------------------
# Concurrency
# -----------------------------------------------------------------------------
# Each PR gets its own concurrency group to avoid conflicts.
# Push events use the git ref as group key.
# cancel-in-progress ensures only the latest build runs for each PR.
concurrency:
group: "pages-${{ github.event.pull_request.number || github.ref }}"
cancel-in-progress: true
jobs:
# ===========================================================================
# JOB: build
# ===========================================================================
# Generates the Dartdoc documentation from ouds_core and uploads it as an
# artifact. Runs for all events EXCEPT when a PR is closed (no need to
# rebuild docs just to clean up).
# ===========================================================================
build:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive
- name: Setup Dart
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c # v1.7.1
with:
sdk: stable
- name: Setup environment
uses: ./.github/actions/setup
- name: Setup Pages
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
- name: Setup Ruby
uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0
with:
ruby-version: 3.3.4
# Generate API documentation from ouds_core package
- name: Build with Dartdoc
run: |
cd ouds_core
dart pub get
dart doc .
# Move generated docs to a clean directory for upload
- name: Move DartDoc output
run: |
mkdir -p ./docs
mv ouds_core/doc/api/* ./docs
# Include branding assets in the documentation
- name: Copy images files (orange logo and banner)
run: |
mkdir -p ./docs/assets
cp ouds_core/assets/doc/orange_logo.svg ./docs/assets/
cp ouds_core/assets/doc/banner.png ./docs/assets/
# Upload as GitHub Pages artifact (creates a tar archive named "github-pages")
- name: Upload artifact
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
with:
path: ./docs
# ===========================================================================
# JOB: deploy
# ===========================================================================
# Deploys the documentation to the PRODUCTION site.
# Only runs on push to main/develop or manual workflow_dispatch.
# Never runs on pull_request events.
#
# Deployment target:
# Branch: gh-pages
# Folder: docs/
# URL: https://flutter.unified-design-system.orange.com/
#
# Important: Preserves the prPreview/ subdirectory so that active PR
# previews are not destroyed by a production deployment.
# ===========================================================================
deploy:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
pages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download artifact
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
with:
name: github-pages
- name: Extract artifact into temporary directory
run: |
mkdir -p /tmp/docs-output
tar -xvf artifact.tar -C /tmp/docs-output
ls -la /tmp/docs-output
- name: Commit changes and push to gh-pages
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git fetch origin gh-pages || true
git checkout gh-pages || git checkout --orphan gh-pages
# Backup prPreview/ so active PR previews survive the deploy
if [ -d "docs/prPreview" ]; then
cp -r docs/prPreview /tmp/prPreview-backup
fi
# Clean everything and replace with new docs
git rm -rf . || true
git clean -fd || true
mkdir -p docs
cp -r /tmp/docs-output/* docs/
# Restore PR previews
if [ -d "/tmp/prPreview-backup" ]; then
cp -r /tmp/prPreview-backup docs/prPreview
fi
# CNAME file is required for custom domain resolution
echo "flutter.unified-design-system.orange.com" > docs/CNAME
git add docs/
commit_message="doc: deploy site to GitHub Pages - Version $(date +%Y%m%d)"
git commit -m "$commit_message" || echo "No changes to commit"
git push origin gh-pages --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ===========================================================================
# JOB: deploy-preview
# ===========================================================================
# Deploys a PR-specific preview of the documentation to a unique URL.
# This allows reviewers to check documentation changes before merging.
#
# Preview URL pattern:
# https://flutter.unified-design-system.orange.com/prPreview/<PR_NUMBER>/
#
# Example for PR #707:
# https://flutter.unified-design-system.orange.com/prPreview/707/
#
# A comment is automatically posted/updated on the PR with the preview link.
# ===========================================================================
deploy-preview:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download artifact
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
with:
name: github-pages
- name: Extract artifact
run: |
mkdir -p /tmp/docs-output
tar -xvf artifact.tar -C /tmp/docs-output
- name: Deploy PR preview to gh-pages
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git fetch origin gh-pages || true
git checkout gh-pages || git checkout --orphan gh-pages
# Remove old preview for this PR (if updating after new commits)
rm -rf docs/prPreview/${{ github.event.pull_request.number }}
# Deploy new preview to docs/prPreview/<PR_NUMBER>/
mkdir -p docs/prPreview/${{ github.event.pull_request.number }}
cp -r /tmp/docs-output/* docs/prPreview/${{ github.event.pull_request.number }}/
git add docs/prPreview/${{ github.event.pull_request.number }}/
git commit -m "doc: deploy PR #${{ github.event.pull_request.number }} preview" || echo "No changes to commit"
git push origin gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Post or update a comment on the PR with the preview URL
- name: Comment PR with preview URL
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://flutter.unified-design-system.orange.com/prPreview/${prNumber}/`;
const body = `📖 **Documentation preview deployed!**\n\n🔗 ${previewUrl}`;
// Check if a preview comment already exists (avoid duplicate comments)
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.data.find(c => c.body.includes('Documentation preview deployed'));
if (existing) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body,
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body,
});
}
# ===========================================================================
# JOB: cleanup-preview
# ===========================================================================
# Removes the PR preview directory when the PR is closed or merged.
# This keeps the gh-pages branch clean and avoids accumulating stale previews.
# ===========================================================================
cleanup-preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Remove PR preview
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git fetch origin gh-pages || true
git checkout gh-pages || true
# Only remove if the preview directory exists
if [ -d "docs/prPreview/${{ github.event.pull_request.number }}" ]; then
rm -rf docs/prPreview/${{ github.event.pull_request.number }}
git add -A
git commit -m "doc: remove PR #${{ github.event.pull_request.number }} preview" || echo "No changes to commit"
git push origin gh-pages
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}