-
Notifications
You must be signed in to change notification settings - Fork 1
261 lines (229 loc) · 7.99 KB
/
release.yml
File metadata and controls
261 lines (229 loc) · 7.99 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
name: Release
on:
push:
branches:
- main
- develop
paths:
- 'apps/**'
- 'package.json'
- 'package-lock.json'
- '.releaserc.yaml'
workflow_dispatch:
inputs:
build_arm64:
description: 'Build ARM64 images (slow, uses QEMU emulation)'
type: boolean
default: false
# Prevent concurrent releases
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: ghcr.io/myelectricaldata/myelectricaldata_new
jobs:
# ===========================================
# STEP 1: Build & Test (must pass before release)
# ===========================================
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: apps/web/package-lock.json
- name: Install dependencies
working-directory: apps/web
run: npm ci
- name: Build
working-directory: apps/web
run: npm run build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: apps/web/dist
retention-days: 1
build-backend:
name: Build Backend
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install dependencies
working-directory: apps/api
run: uv sync
- name: Lint
working-directory: apps/api
run: uv run ruff check src
- name: Type check
working-directory: apps/api
run: uv run mypy src --ignore-missing-imports
# ===========================================
# STEP 2: Semantic Release (only if builds pass)
# ===========================================
release:
name: Semantic Release
needs: [build-frontend, build-backend]
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v4
with:
extra_plugins: |
@semantic-release/changelog@6.0.3
@semantic-release/git@10.0.1
semantic-release-replace-plugin@1.2.7
conventional-changelog-conventionalcommits@8.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release info
if: steps.semantic.outputs.new_release_published == 'true'
run: |
echo "## Release Published 🎉" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** \`${{ steps.semantic.outputs.new_release_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
# ===========================================
# STEP 3: Build & Push Docker Images (reuse cache)
# ===========================================
docker:
name: Docker ${{ matrix.image }}
needs: release
if: needs.release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- image: backend
context: ./apps/api
- image: frontend
context: ./apps/web
steps:
- name: Checkout
uses: actions/checkout@v4
# Download pre-built frontend for faster Docker build
- name: Download frontend build
if: matrix.image == 'frontend'
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: apps/web/dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine tags
id: tags
run: |
VERSION="${{ needs.release.outputs.new_release_version }}"
IMAGE="${{ env.IMAGE_PREFIX }}/${{ matrix.image }}"
# Always tag with version
TAGS="${IMAGE}:${VERSION}"
# Check if prerelease (contains -dev.)
if [[ "$VERSION" == *"-dev."* ]]; then
TAGS="${TAGS},${IMAGE}:dev"
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
TAGS="${TAGS},${IMAGE}:latest"
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "Tags: $TAGS"
- name: Determine platforms
id: platforms
run: |
if [[ "${{ github.event.inputs.build_arm64 }}" == "true" ]]; then
echo "platforms=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT
else
echo "platforms=linux/amd64" >> $GITHUB_OUTPUT
fi
- name: Build and push ${{ matrix.image }}
uses: docker/build-push-action@v6
timeout-minutes: 30
with:
context: ${{ matrix.context }}
platforms: ${{ steps.platforms.outputs.platforms }}
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha,scope=${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ matrix.image }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ needs.release.outputs.new_release_version }}
# ===========================================
# Summary
# ===========================================
summary:
name: Summary
needs: [release, docker]
if: needs.release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
steps:
- name: Create summary
run: |
VERSION="${{ needs.release.outputs.new_release_version }}"
if [[ "$VERSION" == *"-dev."* ]]; then
RELEASE_TYPE="🧪 Development"
EXTRA_TAG="dev"
else
RELEASE_TYPE="🚀 Production"
EXTRA_TAG="latest"
fi
echo "## Docker Images Published 🐳" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Release Type:** $RELEASE_TYPE" >> $GITHUB_STEP_SUMMARY
echo "**Version:** \`$VERSION\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Images" >> $GITHUB_STEP_SUMMARY
echo "| Image | Tags |" >> $GITHUB_STEP_SUMMARY
echo "|-------|------|" >> $GITHUB_STEP_SUMMARY
echo "| \`${{ env.IMAGE_PREFIX }}/backend\` | \`$VERSION\`, \`$EXTRA_TAG\` |" >> $GITHUB_STEP_SUMMARY
echo "| \`${{ env.IMAGE_PREFIX }}/frontend\` | \`$VERSION\`, \`$EXTRA_TAG\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Pull Commands" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.IMAGE_PREFIX }}/backend:$VERSION" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.IMAGE_PREFIX }}/frontend:$VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY