forked from thrixxy-technologies/flavorsnap
-
Notifications
You must be signed in to change notification settings - Fork 0
272 lines (231 loc) · 8.88 KB
/
Copy pathrelease.yml
File metadata and controls
272 lines (231 loc) · 8.88 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
name: Create Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g., v1.0.0)"
required: true
type: string
dry_run:
description: "Dry run (create draft release without publishing)"
required: false
default: "false"
type: boolean
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
validate-version:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version
id: get_version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Validate version format
run: |
if [[ ! "${{ steps.get_version.outputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format vX.Y.Z (e.g., v1.0.0)"
exit 1
fi
- name: Check if tag already exists
run: |
if git rev-parse "${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
echo "Error: Tag ${{ steps.get_version.outputs.version }} already exists"
exit 1
fi
generate-changelog:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [validate-version]
outputs:
changelog: ${{ steps.changelog.outputs.changelog }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get previous tag
id: previous_tag
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
- name: Generate changelog
id: changelog
run: |
echo "# Release ${{ needs.validate-version.outputs.version }}" > changelog.md
echo "" >> changelog.md
if [ -n "${{ steps.previous_tag.outputs.previous_tag }}" ]; then
echo "## Changes since ${{ steps.previous_tag.outputs.previous_tag }}" >> changelog.md
echo "" >> changelog.md
git log ${{ steps.previous_tag.outputs.previous_tag }}..HEAD --pretty=format:"- %s (%h)" >> changelog.md
else
echo "## Initial Release" >> changelog.md
echo "" >> changelog.md
git log --pretty=format:"- %s (%h)" >> changelog.md
fi
echo "" >> changelog.md
echo "" >> changelog.md
echo "## Contributors" >> changelog.md
echo "" >> changelog.md
git shortlog -sn ${{ steps.previous_tag.outputs.previous_tag }}..HEAD | awk '{$1=""; print "- "$0}' | sed 's/^ //' >> changelog.md
CHANGELOG=$(cat changelog.md)
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Upload changelog
uses: actions/upload-artifact@v4
with:
name: changelog
path: changelog.md
build-release-artifacts:
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [validate-version]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Build frontend
working-directory: frontend
run: |
npm ci
npm run build
- name: Create frontend distribution
run: |
tar -czf flavorsnap-frontend-${{ needs.validate-version.outputs.version }}.tar.gz -C frontend .next public
- name: Prepare Python package
run: |
mkdir -p flavorsnap-python
cp -r src ml-model-api models flavorsnap-python/
cp requirements.txt requirements-dev.txt flavorsnap-python/
tar -czf flavorsnap-python-${{ needs.validate-version.outputs.version }}.tar.gz flavorsnap-python
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-artifacts
path: |
flavorsnap-frontend-*.tar.gz
flavorsnap-python-*.tar.gz
build-docker-images:
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [validate-version]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push release image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.validate-version.outputs.version }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: |
org.opencontainers.image.version=${{ needs.validate-version.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ needs.validate-version.outputs.version }}
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
create-release:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [validate-version, generate-changelog, build-release-artifacts, build-docker-images]
steps:
- name: Download changelog
uses: actions/download-artifact@v4
with:
name: changelog
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
name: release-artifacts
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.validate-version.outputs.version }}
release_name: Release ${{ needs.validate-version.outputs.version }}
body: |
${{ needs.generate-changelog.outputs.changelog }}
## Installation
### Docker
\`\`\`bash
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.validate-version.outputs.version }}
\`\`\`
### Frontend Distribution
\`\`\`bash
wget https://github.com/${{ github.repository }}/releases/download/${{ needs.validate-version.outputs.version }}/flavorsnap-frontend-${{ needs.validate-version.outputs.version }}.tar.gz
\`\`\`
### Python Package
\`\`\`bash
wget https://github.com/${{ github.repository }}/releases/download/${{ needs.validate-version.outputs.version }}/flavorsnap-python-${{ needs.validate-version.outputs.version }}.tar.gz
\`\`\`
draft: ${{ github.event.inputs.dry_run == 'true' }}
prerelease: false
- name: Upload frontend artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./flavorsnap-frontend-${{ needs.validate-version.outputs.version }}.tar.gz
asset_name: flavorsnap-frontend-${{ needs.validate-version.outputs.version }}.tar.gz
asset_content_type: application/gzip
- name: Upload python artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./flavorsnap-python-${{ needs.validate-version.outputs.version }}.tar.gz
asset_name: flavorsnap-python-${{ needs.validate-version.outputs.version }}.tar.gz
asset_content_type: application/gzip
notify-release:
runs-on: ubuntu-latest
needs: [create-release]
if: always()
steps:
- name: Send release notification
run: |
if [ "${{ needs.create-release.result }}" == "success" ]; then
echo "✅ Release ${{ needs.validate-version.outputs.version }} created successfully!"
echo "📦 Docker image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.validate-version.outputs.version }}"
else
echo "❌ Release creation failed!"
exit 1
fi