forked from f1xpl/openauto
-
Notifications
You must be signed in to change notification settings - Fork 73
437 lines (387 loc) · 15 KB
/
Copy pathbuild_native.yml
File metadata and controls
437 lines (387 loc) · 15 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
name: OpenAuto Build and Test
on:
push:
branches:
- main
- develop
- "feature/*"
- "bugfix/*"
paths-ignore:
- "**.md"
- "docs/**"
- ".gitignore"
- ".github/**"
pull_request:
branches:
- main
- develop
paths-ignore:
- "**.md"
- "docs/**"
- ".gitignore"
- ".github/**"
workflow_dispatch:
inputs:
version:
description: "Build version (leave empty for auto-generated)"
required: false
default: ""
type: string
architecture:
description: "Architecture to build (all, amd64, arm64, armhf)"
required: false
default: "all"
type: choice
options:
- all
- amd64
- arm64
- armhf
distribution:
description: "Debian distribution to build (trixie, bookworm, all)"
required: false
default: "all"
type: choice
options:
- all
- trixie
- bookworm
trigger_release:
description: "Trigger release workflow after build"
required: false
default: false
type: boolean
trigger_apt_publish:
description: "Trigger APT publish workflow after build"
required: false
default: false
type: boolean
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/openauto
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
distribution: ${{ steps.matrix.outputs.distribution }}
steps:
- name: Generate build matrix
id: matrix
run: |
# Determine distributions
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
DISTRO_INPUT="${{ github.event.inputs.distribution }}"
else
DISTRO_INPUT="all"
fi
# Determine architectures
ARCH_INPUT="${{ github.event.inputs.architecture }}"
if [ -z "$ARCH_INPUT" ] || [ "$ARCH_INPUT" = "all" ]; then
ARCHES="amd64 arm64 armhf"
else
ARCHES="$ARCH_INPUT"
fi
# On develop branch, limit to amd64 for faster feedback
if [ "${{ github.ref }}" = "refs/heads/develop" ]; then
ARCHES="amd64"
echo "Building only amd64 for develop branch"
fi
# Expand distributions list
if [ "$DISTRO_INPUT" = "all" ]; then
DISTROS="bookworm trixie"
echo "distribution=all" >> $GITHUB_OUTPUT
else
DISTROS="$DISTRO_INPUT"
echo "distribution=$DISTRO_INPUT" >> $GITHUB_OUTPUT
fi
# Helper to map arch to platform
platform_for_arch() {
case "$1" in
amd64) echo "linux/amd64";;
arm64) echo "linux/arm64";;
armhf) echo "linux/arm/v7";;
*) echo "linux/amd64";;
esac
}
# Build matrix JSON (ensure valid JSON without over-escaping)
MATRIX='{"include":['
first=true
for d in $DISTROS; do
for a in $ARCHES; do
plat=$(platform_for_arch "$a")
entry=$(printf '{"arch":"%s","platform":"%s","distro":"%s"}' "$a" "$plat" "$d")
if [ "$first" = true ]; then
MATRIX+="$entry"
first=false
else
MATRIX+=",$entry"
fi
done
done
MATRIX+=']}'
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
build:
name: Build OpenAuto for ${{ matrix.arch }} on ${{ matrix.distro }}
needs: prepare
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU for cross-platform builds
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Generate build info
id: build_info
run: |
# Use manual version if provided, otherwise generate using same scheme as CMake
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
else
# Match CMakeLists.txt date-based versioning: YYYY.MM.DD
BUILD_YEAR=$(date -u +"%Y")
BUILD_MONTH=$(date -u +"%m")
BUILD_DAY=$(date -u +"%d")
VERSION="${BUILD_YEAR}.${BUILD_MONTH}.${BUILD_DAY}"
# Add git commit info if available (match CMake logic)
COMMIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
if [ "$COMMIT_SHA" != "unknown" ]; then
VERSION="${VERSION}+git.${COMMIT_SHA}"
# Check if repository is dirty (has uncommitted changes)
# In CI, we'll skip dirty check as the workspace should be clean
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && ! git diff --quiet 2>/dev/null; then
VERSION="${VERSION}.dirty"
fi
fi
fi
COMMIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE=$(date -u +"%Y%m%d_%H%M%S")
# For releases, ensure we have a clean version without build date suffix
RELEASE_VERSION="${VERSION}"
if [ "${{ github.event.inputs.create_release }}" = "true" ] || [[ "${GITHUB_REF}" == refs/tags/* ]]; then
# For releases, use a cleaner version format
if [ -z "${{ github.event.inputs.version }}" ]; then
RELEASE_VERSION="${BUILD_YEAR}.${BUILD_MONTH}.${BUILD_DAY}"
if [ "$COMMIT_SHA" != "unknown" ]; then
RELEASE_VERSION="${RELEASE_VERSION}+git.${COMMIT_SHA}"
fi
fi
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "release_version=${RELEASE_VERSION}" >> $GITHUB_OUTPUT
echo "commit_sha=${COMMIT_SHA}" >> $GITHUB_OUTPUT
echo "build_date=${BUILD_DATE}" >> $GITHUB_OUTPUT
echo "package_name=openauto-${{ matrix.arch }}-${VERSION}" >> $GITHUB_OUTPUT
echo "Generated version: ${VERSION}"
echo "Release version: ${RELEASE_VERSION}"
- name: Build for ${{ matrix.arch }} on ${{ matrix.distro }}
run: |
echo "Building OpenAuto for ${{ matrix.arch }} architecture"
# Create output directory
mkdir -p ./build-output
# Build using Docker with platform emulation
docker buildx build \
--platform ${{ matrix.platform }} \
--build-arg TARGET_ARCH=${{ matrix.arch }} \
--build-arg DEBIAN_VERSION=${{ matrix.distro }} \
--tag openauto-build:${{ matrix.arch }} \
--load \
.
# Extract built packages from container
container_id=$(docker create openauto-build:${{ matrix.arch }})
docker cp ${container_id}:/output/. ./build-output/
docker rm ${container_id}
echo "Build completed for ${{ matrix.arch }}"
ls -la ./build-output/
- name: Validate packages
run: |
echo "Validating packages for ${{ matrix.arch }}..."
if [ ! "$(ls -A ./build-output/*.deb 2>/dev/null)" ]; then
echo "Error: No .deb packages found for ${{ matrix.arch }}"
exit 1
fi
# Display package information
for package in ./build-output/*.deb; do
if [ -f "$package" ]; then
echo "Package: $(basename $package)"
dpkg-deb --info "$package" | head -20
echo "---"
fi
done
- name: Assert distro suffix in package version
run: |
echo "Asserting Debian revision suffix for distro: ${{ matrix.distro }}"
case "${{ matrix.distro }}" in
bookworm)
expected_regex='\+deb12u[0-9]+'
;;
trixie)
expected_regex='\+deb13u[0-9]+'
;;
jammy)
expected_regex='0ubuntu[0-9]+~22\.04'
;;
noble)
expected_regex='0ubuntu[0-9]+~24\.04'
;;
*)
expected_regex='(deb|ubuntu|rpi)'
;;
esac
failed=0
for package in ./build-output/*.deb; do
[ -f "$package" ] || continue
ver=$(dpkg-deb --field "$package" Version)
echo "$(basename "$package"): Version=$ver"
if echo "$ver" | grep -Eq "$expected_regex"; then
echo "✅ Suffix OK: matches $expected_regex"
else
echo "::error::Version suffix does not match expected regex '$expected_regex' for ${{ matrix.distro }}"
failed=1
fi
done
if [ "$failed" -ne 0 ]; then
echo "Package version suffix assertion failed."
exit 1
fi
- name: Generate version report
run: |
out="deb-versions-${{ matrix.distro }}-${{ matrix.arch }}.md"
echo "# OpenAuto DEB Versions for ${{ matrix.distro }} / ${{ matrix.arch }}" > "$out"
echo "" >> "$out"
for package in ./build-output/*.deb; do
[ -f "$package" ] || continue
pkg=$(dpkg-deb --field "$package" Package)
ver=$(dpkg-deb --field "$package" Version)
arch=$(dpkg-deb --field "$package" Architecture)
echo "- $(basename "$package"): $pkg $ver ($arch)" >> "$out"
done
echo "Wrote $out"
- name: Upload version report
uses: actions/upload-artifact@v4
with:
name: openauto-deb-versions-${{ matrix.distro }}-${{ matrix.arch }}
path: deb-versions-${{ matrix.distro }}-${{ matrix.arch }}.md
retention-days: 60
- name: Debug - Show files before upload
run: |
echo "=== Build completed for ${{ matrix.arch }} ==="
echo "Files in build-output directory:"
ls -la ./build-output/ || echo "No build-output directory found"
echo "DEB files found:"
find ./build-output -name "*.deb" 2>/dev/null || echo "No .deb files found"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: openauto-packages-${{ matrix.distro }}-${{ matrix.arch }}
path: |
./build-output/*.deb
./build-output/*.tar.*
retention-days: 30
test:
needs: build
runs-on: ubuntu-latest
if: success()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
pattern: openauto-packages-*
merge-multiple: true
path: ./test-packages
- name: Test package installation
run: |
echo "Testing package installation..."
# Test AMD64 packages on native Ubuntu
for package in ./test-packages/*amd64*.deb; do
if [ -f "$package" ]; then
echo "Testing installation of $(basename $package)"
# Check package structure
dpkg-deb --contents "$package" | head -20
# Verify package dependencies
dpkg-deb --field "$package" Depends
echo "Package $(basename $package) structure looks good"
fi
done
- name: Generate test report
run: |
echo "# OpenAuto Build Test Report" > test-report.md
echo "" >> test-report.md
echo "## Build Summary" >> test-report.md
echo "- Build Date: $(date -u)" >> test-report.md
echo "- Commit: ${{ github.sha }}" >> test-report.md
echo "- Branch: ${{ github.ref_name }}" >> test-report.md
echo "" >> test-report.md
echo "## Package Information" >> test-report.md
for package in ./test-packages/*.deb; do
if [ -f "$package" ]; then
echo "### $(basename $package)" >> test-report.md
echo '```' >> test-report.md
dpkg-deb --field "$package" Package Architecture Version Depends >> test-report.md
echo '```' >> test-report.md
echo "" >> test-report.md
fi
done
- name: Upload test report
uses: actions/upload-artifact@v4
with:
name: openauto-test-report-${{ github.run_number }}
path: test-report.md
retention-days: 90
release:
needs: [prepare, build, test]
runs-on: ubuntu-latest
if: github.event.inputs.trigger_release == 'true' || github.event.inputs.trigger_apt_publish == 'true' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Trigger Release Workflow
if: github.event.inputs.trigger_release == 'true' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
run: |
echo "Triggering release workflow with build run ID: ${{ github.run_id }}"
gh workflow run release.yml --repo ${{ github.repository }} \
-f build_run_id="${{ github.run_id }}" \
-f version="${{ github.event.inputs.version }}" \
-f create_draft="false"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
- name: Trigger APT Publish Workflow
if: github.event.inputs.trigger_apt_publish == 'true' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
run: |
echo "Dispatching to packages repo Aptly workflow with build run ID: ${{ github.run_id }} (distribution: ${{ needs.prepare.outputs.distribution }})"
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.PACKAGES_REPO_TOKEN }}" \
https://api.github.com/repos/opencardev/packages/dispatches \
-d '{
"event_type": "publish-apt-packages",
"client_payload": {
"source_repo": "${{ github.repository }}",
"build_run_id": "${{ github.run_id }}",
"apt_import": true,
"distribution": "${{ needs.prepare.outputs.distribution }}"
}
}'
echo "✅ APT repository update triggered successfully!"
echo "Check: https://github.com/opencardev/packages/actions"
env:
PACKAGES_REPO_TOKEN: ${{ secrets.PACKAGES_REPO_TOKEN }}
- name: Build Summary
run: |
echo "## Build Complete! 🎉"
echo "Build Run ID: \`${{ github.run_id }}\`"
echo ""
echo "### Next Steps:"
echo "You can now manually trigger workflows using this build:"
echo ""
echo "- Trigger release: release.yml with build_run_id=${{ github.run_id }}"
echo "- Trigger APT publish: apt-publish-aptly.yml or packages repo dispatch"