-
Notifications
You must be signed in to change notification settings - Fork 0
322 lines (283 loc) · 12.5 KB
/
Copy pathrelease.yml
File metadata and controls
322 lines (283 loc) · 12.5 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
name: "Semantic Release"
on:
workflow_dispatch:
inputs:
DRY_RUN:
required: false
default: false
type: boolean
description: "Run in dry run mode (no actual release)"
SKIP_RELEASE:
required: false
default: false
type: boolean
description: "Skip semantic release and use existing version (for recovery)"
RELEASE_VERSION:
required: false
type: string
description: "Manually specify release version (only for manual publish/docs jobs)"
SKIP_CI:
required: false
default: false
type: boolean
description: "Skip CI gate (use for recovery)"
permissions:
contents: write
pages: write
id-token: write
jobs:
# ── Gate: wait for CI to pass ─────────────────────────────────
CI_GATE:
if: ${{ !inputs.SKIP_CI }}
uses: ./.github/workflows/ci.yml
# ── Semantic Release: version bump + changelog + tag ──────────
SEMANTIC_RELEASE:
needs: CI_GATE
if: always() && (needs.CI_GATE.result == 'success' || inputs.SKIP_CI) && !inputs.SKIP_RELEASE
runs-on: ubuntu-latest
outputs:
new_release_version: ${{ steps.semantic-release.outputs.new_release_version }}
release_created: ${{ steps.semantic-release.outputs.new_release_published }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install semantic-release
run: uv pip install --system python-semantic-release>=9.0
# Build frontend before semantic-release runs build_command
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Build frontend
run: |
cd frontend && npm ci && npm run build && cd ..
mkdir -p src/holysheet/renderer/assets
cp frontend/dist/index.html src/holysheet/renderer/index.html
cp frontend/dist/assets/*.js src/holysheet/renderer/assets/app.js
cp frontend/dist/assets/*.css src/holysheet/renderer/assets/app.css 2>/dev/null || touch src/holysheet/renderer/assets/app.css
- name: Verify renderer assets
run: |
test -f src/holysheet/renderer/assets/app.js || (echo "FATAL: app.js missing" && exit 1)
echo "✓ Renderer assets verified: $(du -sh src/holysheet/renderer/assets/)"
# ── Run semantic-release via CLI (same approach as FlowyML) ──
- name: Semantic Release
id: semantic-release
run: |
if [[ "${{ inputs.DRY_RUN }}" == "true" ]]; then
echo "Running in dry-run mode"
semantic-release version --print
echo "new_release_published=false" >> $GITHUB_OUTPUT
else
semantic-release version
if [ $? -eq 0 ]; then
VERSION=$(semantic-release version --print)
echo "new_release_published=true" >> $GITHUB_OUTPUT
echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT
echo "✅ Released version: $VERSION"
else
echo "new_release_published=false" >> $GITHUB_OUTPUT
echo "⚠️ No release created"
fi
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Show release information
shell: bash
run: |
echo "Release created: ${{ steps.semantic-release.outputs.new_release_published }}"
echo "New version: ${{ steps.semantic-release.outputs.new_release_version }}"
- name: Save release version for recovery
if: steps.semantic-release.outputs.new_release_published == 'true'
run: |
mkdir -p .github/recovery
echo "${{ steps.semantic-release.outputs.new_release_version }}" > .github/recovery/last_release_version.txt
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add .github/recovery/last_release_version.txt
git commit -m "chore: save last release version for recovery [skip ci]" || echo "No changes to commit"
git push || echo "Failed to push recovery file"
- name: Release summary
if: always()
run: |
echo "## Semantic Release Summary" >> $GITHUB_STEP_SUMMARY
echo "| Key | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-----|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Released | \`${{ steps.semantic-release.outputs.new_release_published || 'false' }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${{ steps.semantic-release.outputs.new_release_version || 'N/A' }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Dry Run | \`${{ inputs.DRY_RUN }}\` |" >> $GITHUB_STEP_SUMMARY
# ── Publish to PyPI ───────────────────────────────────────────
PYPI_PUBLISH:
needs: [SEMANTIC_RELEASE]
if: always() && (needs.SEMANTIC_RELEASE.outputs.release_created == 'true' || inputs.SKIP_RELEASE) && !failure()
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 1
- name: Get version to publish
id: get_version
run: |
if [[ "${{ inputs.SKIP_RELEASE }}" == "true" ]]; then
if [[ -n "${{ inputs.RELEASE_VERSION }}" ]]; then
echo "Using manually specified version: ${{ inputs.RELEASE_VERSION }}"
echo "VERSION=${{ inputs.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
else
if [[ -f ".github/recovery/last_release_version.txt" ]]; then
VERSION=$(cat .github/recovery/last_release_version.txt)
echo "Using recovered version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
else
echo "ERROR: No version specified and no recovery file found"
exit 1
fi
fi
else
echo "Using version from semantic-release: ${{ needs.SEMANTIC_RELEASE.outputs.new_release_version }}"
echo "VERSION=${{ needs.SEMANTIC_RELEASE.outputs.new_release_version }}" >> $GITHUB_OUTPUT
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install build tools
run: uv pip install --system build twine
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Build frontend
run: |
cd frontend && npm ci && npm run build && cd ..
mkdir -p src/holysheet/renderer/assets
cp frontend/dist/index.html src/holysheet/renderer/index.html
cp frontend/dist/assets/*.js src/holysheet/renderer/assets/app.js
cp frontend/dist/assets/*.css src/holysheet/renderer/assets/app.css 2>/dev/null || touch src/holysheet/renderer/assets/app.css
- name: Verify renderer assets
run: |
test -f src/holysheet/renderer/assets/app.js || (echo "FATAL: app.js missing" && exit 1)
echo "✓ Renderer assets verified"
- name: Set version
run: |
echo "Setting package version to ${{ steps.get_version.outputs.VERSION }}"
sed -i 's/^version = .*/version = "${{ steps.get_version.outputs.VERSION }}"/' pyproject.toml
sed -i 's/^__version__ = .*/__version__ = "${{ steps.get_version.outputs.VERSION }}"/' src/holysheet/__init__.py
- name: Build package
run: python -m build
- name: Publish to PyPI
id: publish_pypi
run: |
twine upload dist/* --username __token__ --password "$PYPI_TOKEN"
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
continue-on-error: true
- name: Retry PyPI publish on failure
if: steps.publish_pypi.outcome == 'failure'
run: |
echo "First attempt failed, retrying..."
sleep 10
rm -rf dist
python -m build
twine upload dist/* --username __token__ --password "$PYPI_TOKEN"
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
- name: Publish summary
if: always()
run: |
echo "## PyPI Publish Summary" >> $GITHUB_STEP_SUMMARY
echo "| Key | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-----|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${{ steps.get_version.outputs.VERSION }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Status | \`${{ steps.publish_pypi.outcome || 'skipped' }}\` |" >> $GITHUB_STEP_SUMMARY
# ── Update Documentation ─────────────────────────────────────
UPDATE_DOCS:
needs: [SEMANTIC_RELEASE, PYPI_PUBLISH]
if: always() && (needs.SEMANTIC_RELEASE.outputs.release_created == 'true' || inputs.SKIP_RELEASE) && !failure()
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- name: Get version for docs
id: get_docs_version
run: |
if [[ "${{ inputs.SKIP_RELEASE }}" == "true" ]]; then
if [[ -n "${{ inputs.RELEASE_VERSION }}" ]]; then
echo "VERSION=${{ inputs.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
else
if [[ -f ".github/recovery/last_release_version.txt" ]]; then
VERSION=$(cat .github/recovery/last_release_version.txt)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
else
echo "ERROR: No version specified and no recovery file found"
exit 1
fi
fi
else
echo "VERSION=${{ needs.SEMANTIC_RELEASE.outputs.new_release_version }}" >> $GITHUB_OUTPUT
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install docs dependencies
run: |
pip install \
"mkdocs>=1.6" \
"mkdocs-material>=9.5" \
"mkdocstrings[python]>=0.24" \
"mkdocs-minify-plugin>=0.8" \
"mike>=2.1"
- name: Configure Git for mike
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch gh-pages branch
run: git fetch origin gh-pages:gh-pages || echo "No gh-pages branch exists yet"
- name: Deploy versioned docs
id: deploy_docs
run: |
VERSION="${{ steps.get_docs_version.outputs.VERSION }}"
# Extract major.minor for mike alias
MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2)
echo "Deploying documentation for version $MAJOR_MINOR (from $VERSION)"
mike deploy --push --update-aliases "$MAJOR_MINOR" latest
mike set-default --push latest
echo "✅ Deployed $MAJOR_MINOR with 'latest' alias and set as default"
continue-on-error: true
- name: Retry docs deploy on failure
if: steps.deploy_docs.outcome == 'failure'
run: |
echo "First attempt failed, retrying with --force..."
git fetch origin gh-pages:gh-pages --force
VERSION="${{ steps.get_docs_version.outputs.VERSION }}"
MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2)
mike deploy --push --update-aliases --force "$MAJOR_MINOR" latest
mike set-default --push latest
- name: Docs summary
if: always()
run: |
echo "## Docs Deploy Summary" >> $GITHUB_STEP_SUMMARY
echo "| Key | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-----|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${{ steps.get_docs_version.outputs.VERSION }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Status | \`${{ steps.deploy_docs.outcome || 'skipped' }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| URL | https://unicolab.github.io/holysheet/ |" >> $GITHUB_STEP_SUMMARY