forked from stardew-valley-dedicated-server/server
-
Notifications
You must be signed in to change notification settings - Fork 0
230 lines (205 loc) · 8.64 KB
/
deploy-docs.yml
File metadata and controls
230 lines (205 loc) · 8.64 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
name: Deploy Documentation
on:
workflow_call:
inputs:
version:
description: 'Which version was just built (latest or preview)'
required: true
type: string
workflow_dispatch:
inputs:
rebuild_latest:
description: 'Rebuild latest docs from Docker image'
required: false
default: false
type: boolean
rebuild_preview:
description: 'Rebuild preview docs from Docker image'
required: false
default: false
type: boolean
use_preview_for_latest:
description: 'Build latest docs from preview image (for bootstrapping before first release)'
required: false
default: false
type: boolean
concurrency:
group: deploy-docs
cancel-in-progress: false
permissions:
contents: read
pages: write
id-token: write
actions: read
jobs:
# Optionally rebuild docs if requested via manual trigger
build-latest:
name: Build Latest Docs
if: inputs.rebuild_latest == true || inputs.use_preview_for_latest == true
uses: ./.github/workflows/build-docs.yml
with:
version: latest
image_tag: ${{ inputs.use_preview_for_latest == true && 'preview' || 'latest' }}
secrets: inherit
build-preview:
name: Build Preview Docs
if: inputs.rebuild_preview == true || inputs.use_preview_for_latest == true
uses: ./.github/workflows/build-docs.yml
with:
version: preview
image_tag: preview
secrets: inherit
deploy:
name: Deploy to GitHub Pages
needs: [build-latest, build-preview]
if: always() && !failure() && !cancelled()
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
# Try to download from current workflow run first
# This works when called from build-release.yml/build-preview.yml which run build-docs first
- name: Download latest docs (current run)
id: current-latest
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: docs-latest
path: dist
continue-on-error: true
- name: Download preview docs (current run)
id: current-preview
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: docs-preview
path: dist/preview
continue-on-error: true
# If not found in current run, fetch from previous workflow runs
# Try build-release.yml first (primary source for latest docs)
- name: Download latest docs (from release workflow)
id: release-latest
if: steps.current-latest.outcome != 'success'
uses: dawidd6/action-download-artifact@2536c51d3d126276eb39f74d6bc9c72ac6ef30d3 # v16
with:
workflow: build-release.yml
name: docs-latest
path: dist
if_no_artifact_found: ignore
allow_forks: false
continue-on-error: true
# Fallback: check deploy-docs.yml for manually rebuilt latest docs
- name: Download latest docs (from manual rebuild)
if: steps.current-latest.outcome != 'success' && steps.release-latest.outcome != 'success'
uses: dawidd6/action-download-artifact@2536c51d3d126276eb39f74d6bc9c72ac6ef30d3 # v16
with:
workflow: deploy-docs.yml
name: docs-latest
path: dist
if_no_artifact_found: warn
allow_forks: false
# Try build-preview.yml first (primary source for preview docs)
- name: Download preview docs (from build-preview workflow)
id: build-preview-artifact
if: steps.current-preview.outcome != 'success'
uses: dawidd6/action-download-artifact@2536c51d3d126276eb39f74d6bc9c72ac6ef30d3 # v16
with:
workflow: build-preview.yml
name: docs-preview
path: dist/preview
if_no_artifact_found: ignore
allow_forks: false
continue-on-error: true
# Fallback: check deploy-docs.yml for manually rebuilt preview docs
- name: Download preview docs (from manual rebuild)
if: steps.current-preview.outcome != 'success' && steps.build-preview-artifact.outcome != 'success'
uses: dawidd6/action-download-artifact@2536c51d3d126276eb39f74d6bc9c72ac6ef30d3 # v16
with:
workflow: deploy-docs.yml
name: docs-preview
path: dist/preview
if_no_artifact_found: warn
allow_forks: false
- name: Check artifacts exist
id: check
run: |
VERSION="${{ inputs.version }}"
HAS_LATEST=false
HAS_PREVIEW=false
# Check for latest docs
if [ -d "dist" ] && [ -n "$(ls -A dist 2>/dev/null | grep -v preview)" ]; then
echo "Latest docs: $(du -sh dist --exclude=dist/preview 2>/dev/null | cut -f1 || du -sh dist | cut -f1)"
HAS_LATEST=true
fi
# Check for preview docs
if [ -d "dist/preview" ] && [ -n "$(ls -A dist/preview 2>/dev/null)" ]; then
echo "Preview docs: $(du -sh dist/preview | cut -f1)"
HAS_PREVIEW=true
fi
echo "has_latest=$HAS_LATEST" >> $GITHUB_OUTPUT
echo "has_preview=$HAS_PREVIEW" >> $GITHUB_OUTPUT
# Latest docs are required for deployment (main site content)
if [ "$HAS_LATEST" != "true" ]; then
echo "::warning::No docs-latest artifact found. The artifact may have expired (14 day retention)."
echo "::warning::Skipping deployment. To fix: Run deploy-docs workflow manually with rebuild_latest=true, or trigger a release."
echo "should_deploy=false" >> $GITHUB_OUTPUT
exit 0
fi
# Preview docs are optional but warn if missing
if [ "$HAS_PREVIEW" != "true" ]; then
echo "::warning::No preview docs artifact found. Preview docs will not be available."
fi
echo "should_deploy=true" >> $GITHUB_OUTPUT
- name: Setup Pages
if: steps.check.outputs.should_deploy == 'true'
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
- name: Upload merged artifact
if: steps.check.outputs.should_deploy == 'true'
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
with:
path: dist
- name: Deploy to GitHub Pages
id: deployment
if: steps.check.outputs.should_deploy == 'true'
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
- name: Build summary
if: steps.check.outputs.should_deploy == 'true'
run: |
echo "### Documentation Deployed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Site URL:** ${{ steps.deployment.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Versions deployed:**" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check.outputs.has_latest }}" == "true" ]; then
echo "- Latest: ${{ steps.deployment.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ steps.check.outputs.has_preview }}" == "true" ]; then
echo "- Preview: ${{ steps.deployment.outputs.page_url }}preview/" >> $GITHUB_STEP_SUMMARY
fi
- name: Skipped summary
if: steps.check.outputs.should_deploy != 'true'
run: |
echo "### Documentation Deployment Skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "No docs-latest artifact was found. This can happen when:" >> $GITHUB_STEP_SUMMARY
echo "- The artifact expired (14 day retention)" >> $GITHUB_STEP_SUMMARY
echo "- No release has been published yet" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**To fix:** Run the deploy-docs workflow manually with \`rebuild_latest=true\`, or trigger a release." >> $GITHUB_STEP_SUMMARY
- name: Discord notification
if: success() && steps.check.outputs.should_deploy == 'true'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
if [ -n "$DISCORD_WEBHOOK" ]; then
curl -H "Content-Type: application/json" \
-d '{
"embeds": [{
"title": "Documentation Updated",
"color": 3447003,
"fields": [
{"name": "View Docs", "value": "[stardew-valley-dedicated-server.github.io/server](${{ steps.deployment.outputs.page_url }})"}
]
}]
}' \
"$DISCORD_WEBHOOK"
fi