Repository navigation
273 lines (240 loc) · 11.5 KB
/
Copy pathrelease.yml
File metadata and controls
273 lines (240 loc) · 11.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
# .github/workflows/release.yml
# Automated release workflow.
# How to trigger: git tag v1.2.3 && git push origin v1.2.3
#
# This workflow:
# 1. Validates the tag format
# 2. Auto-generates a changelog from commits since the last tag
# 3. Creates a GitHub Release with release notes
# 4. Attaches a deployment-ready docker-compose.yml as a release asset
name: 🚀 Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+" # v1.0.0
- "v[0-9]+.[0-9]+.[0-9]+-*" # v1.0.0-beta.1, v1.0.0-rc.1
permissions:
contents: write # needed to create releases and upload assets
packages: read
jobs:
# ──────────────────────────────────────────────────────────────────────────
# JOB 1: Validate the tag and extract version info
# ──────────────────────────────────────────────────────────────────────────
validate:
name: ✅ Validate Tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.parse.outputs.version }}
is_prerelease: ${{ steps.parse.outputs.is_prerelease }}
release_name: ${{ steps.parse.outputs.release_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Parse version tag
id: parse
run: |
TAG="${{ github.ref_name }}"
VERSION="${TAG#v}" # strip leading 'v'
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "release_name=PRISM $TAG" >> $GITHUB_OUTPUT
# Detect pre-release (anything with a hyphen: -beta, -rc, -alpha)
if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-.*$ ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
echo "::notice::Pre-release detected: $TAG"
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
echo "::notice::Stable release: $TAG"
fi
- name: Validate semver format
run: |
VERSION="${{ steps.parse.outputs.version }}"
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
echo "::error::Invalid semantic version: $VERSION"
exit 1
fi
echo "✅ Valid semantic version: $VERSION"
# ──────────────────────────────────────────────────────────────────────────
# JOB 2: Generate changelog from git commits
# ──────────────────────────────────────────────────────────────────────────
changelog:
name: 📝 Generate Changelog
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
run: |
CURRENT_TAG="${{ github.ref_name }}"
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -v "$CURRENT_TAG" | head -n 1)
echo "Current tag: $CURRENT_TAG"
echo "Previous tag: $PREVIOUS_TAG"
if [ -z "$PREVIOUS_TAG" ]; then
RANGE="HEAD"
SINCE_MSG="(initial release)"
else
RANGE="${PREVIOUS_TAG}..HEAD"
SINCE_MSG="since ${PREVIOUS_TAG}"
fi
# Write changelog directly to file — no GITHUB_OUTPUT needed
{
printf "## 📦 What's Changed (%s)\n\n" "$SINCE_MSG"
FEATURES=$(git log $RANGE --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" \
--grep="^feat\|^feature\|^add\|^new" -i 2>/dev/null || true)
if [ -n "$FEATURES" ]; then
printf "### ✨ New Features\n%s\n\n" "$FEATURES"
fi
FIXES=$(git log $RANGE --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" \
--grep="^fix\|^bug\|^hotfix\|^patch" -i 2>/dev/null || true)
if [ -n "$FIXES" ]; then
printf "### 🐛 Bug Fixes\n%s\n\n" "$FIXES"
fi
PERF=$(git log $RANGE --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" \
--grep="^perf\|^optim\|^improve\|^speed" -i 2>/dev/null || true)
if [ -n "$PERF" ]; then
printf "### ⚡ Performance\n%s\n\n" "$PERF"
fi
CI=$(git log $RANGE --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" \
--grep="^ci\|^docker\|^build\|^deploy\|^infra" -i 2>/dev/null || true)
if [ -n "$CI" ]; then
printf "### 🔧 Infrastructure\n%s\n\n" "$CI"
fi
OTHER=$(git log $RANGE --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" \
--invert-grep \
--grep="^feat\|^feature\|^add\|^new\|^fix\|^bug\|^hotfix\|^patch\|^perf\|^optim\|^improve\|^speed\|^ci\|^docker\|^build\|^deploy\|^infra" \
-i 2>/dev/null || true)
if [ -n "$OTHER" ]; then
printf "### 📌 Other Changes\n%s\n\n" "$OTHER"
fi
printf "%s\n\n" "---"
printf "### 🐳 Docker Images\n"
printf '```bash\n'
printf "# Pull this release\n"
printf "docker pull ghcr.io/${{ github.repository_owner }}/manufacturing-intelligence/mfg-backend:%s\n" "$CURRENT_TAG"
printf "docker pull ghcr.io/${{ github.repository_owner }}/manufacturing-intelligence/mfg-frontend:%s\n" "$CURRENT_TAG"
printf '```\n\n'
printf "**Full Diff:** https://github.com/${{ github.repository }}/compare/%s...%s\n" "$PREVIOUS_TAG" "$CURRENT_TAG"
} > CHANGELOG_RELEASE.md
echo "✅ Changelog written:"
cat CHANGELOG_RELEASE.md
- name: Upload changelog artifact
uses: actions/upload-artifact@v4
with:
name: changelog
path: CHANGELOG_RELEASE.md
# ──────────────────────────────────────────────────────────────────────────
# JOB 3: Build release assets (versioned docker-compose)
# ──────────────────────────────────────────────────────────────────────────
build-assets:
name: 📦 Build Release Assets
runs-on: ubuntu-latest
needs: [validate, changelog]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate versioned docker-compose
run: |
VERSION="${{ needs.validate.outputs.version }}"
TAG="${{ github.ref_name }}"
OWNER="${{ github.repository_owner }}"
{
echo "# PRISM ${TAG} — Production-ready docker-compose"
echo "# Generated automatically for release ${TAG}"
echo "# Usage: docker-compose -f docker-compose.release.yml up -d"
echo ""
echo "version: '3.8'"
echo ""
echo "services:"
echo " backend:"
echo " image: ghcr.io/${OWNER}/manufacturing-intelligence/mfg-backend:${TAG}"
echo " container_name: prism-backend-${VERSION}"
echo " ports:"
echo ' - "8000:8000"'
echo " volumes:"
echo " - ./data:/app/data"
echo " - ./models:/app/models"
echo " environment:"
echo " - APP_VERSION=${VERSION}"
echo " restart: unless-stopped"
echo " healthcheck:"
echo ' test: ["CMD", "curl", "-f", "http://localhost:8000/api/health"]'
echo " interval: 30s"
echo " timeout: 10s"
echo " retries: 3"
echo " start_period: 60s"
echo ""
echo " frontend:"
echo " image: ghcr.io/${OWNER}/manufacturing-intelligence/mfg-frontend:${TAG}"
echo " container_name: prism-frontend-${VERSION}"
echo " ports:"
echo ' - "3000:3000"'
echo " environment:"
echo " - NEXT_PUBLIC_API_URL=http://backend:8000"
echo " - APP_VERSION=${VERSION}"
echo " depends_on:"
echo " backend:"
echo " condition: service_healthy"
echo " restart: unless-stopped"
echo " healthcheck:"
echo ' test: ["CMD", "curl", "-f", "http://localhost:3000"]'
echo " interval: 30s"
echo " timeout: 10s"
echo " retries: 3"
echo " start_period: 30s"
echo ""
echo "networks:"
echo " default:"
echo " name: prism-network-${VERSION}"
} > docker-compose.release.yml
echo "✅ docker-compose.release.yml written:"
cat docker-compose.release.yml
- name: Upload release assets
uses: actions/upload-artifact@v4
with:
name: release-assets
path: docker-compose.release.yml
# ──────────────────────────────────────────────────────────────────────────
# JOB 4: Create the GitHub Release
# ──────────────────────────────────────────────────────────────────────────
release:
name: 🎉 Create GitHub Release
runs-on: ubuntu-latest
needs: [validate, changelog, build-assets]
steps:
- name: Download release assets
uses: actions/download-artifact@v4
with:
name: release-assets
- name: Download changelog
uses: actions/download-artifact@v4
with:
name: changelog
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: ${{ needs.validate.outputs.release_name }}
tag_name: ${{ github.ref_name }}
body_path: CHANGELOG_RELEASE.md
prerelease: ${{ needs.validate.outputs.is_prerelease == 'true' }}
draft: false
files: |
docker-compose.release.yml
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post release summary
run: |
echo "## 🚀 Release Created" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Pre-release:** ${{ needs.validate.outputs.is_prerelease }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Docker Images" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "mfg-backend:${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "mfg-frontend:${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY