File: build.yml

package info (click to toggle)
rfone-host 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 604 kB
  • sloc: ansic: 6,116; xml: 23; makefile: 3
file content (1344 lines) | stat: -rw-r--r-- 56,214 bytes parent folder | download
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
# Copyright (c) 2025, Benjamin Vernoux <bvernoux@hydrasdr.com>
# 
# This workflow is licensed exclusively for HydraSDR products and related development.
# Unauthorized use, modification, or distribution for non-HydraSDR products is prohibited.
# All rights reserved.
#
# HydraSDR RFOne Host Tools Build and Release Workflow
# For more information about HydraSDR products: https://hydrasdr.com

name: Build and Release HydraSDR RFOne Host Tools + Shared Lib / DLL (Windows, GNU/Linux, MacOS)

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

env:
  # Global environment variables
  PACKAGE_NAME: "hydrasdr-host-tools"
  MAINTAINER: "Benjamin Vernoux <bvernoux@hydrasdr.com>"
  HOMEPAGE: "https://hydrasdr.com"

jobs:
  # Extract version once and share across all jobs
  extract-version:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.version.outputs.version }}
    steps:
    - uses: actions/checkout@v4
    - name: Extract version
      id: version
      run: |
        VERSION=$(grep '#define HYDRASDR_VERSION' libhydrasdr/src/hydrasdr.h | sed 's/.*"\([^"]*\)".*/\1/')
        echo "version=$VERSION" >> $GITHUB_OUTPUT
        echo "Extracted version: $VERSION"

  build:
    needs: extract-version
    runs-on: ${{ matrix.os }}
    
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: windows-2022
            name: "Windows-x64"
            platform: "windows"
          - os: ubuntu-24.04
            name: "Ubuntu-24.04-LTS-Noble-Numbat"
            platform: "linux"
            create_deb: true
          - os: macos-14
            name: "macOS-ARM64"
            platform: "macos"
            arch: "arm64"
          - os: macos-13
            name: "macOS-x86_64"
            platform: "macos"
            arch: "x86_64"

    name: ${{ matrix.name }}

    steps:
    - uses: actions/checkout@v4

    # === Platform Dependencies ===
    - name: Install Linux dependencies
      if: matrix.platform == 'linux'
      run: |
        sudo apt-get update
        sudo apt-get install -y build-essential cmake pkg-config libusb-1.0-0-dev

    - name: Install macOS dependencies
      if: matrix.platform == 'macos'
      env:
        HOMEBREW_NO_AUTO_UPDATE: 1
      run: |
        brew uninstall --ignore-dependencies cmake || true
        brew install --quiet cmake libusb pkg-config

    # === Windows Dependencies ===
    - name: Setup Windows build tools
      if: matrix.platform == 'windows'
      uses: microsoft/setup-msbuild@v2

    - name: Download Windows dependencies
      if: matrix.platform == 'windows'
      shell: powershell
      run: |
        # Download dependencies
        Invoke-WebRequest "https://github.com/libusb/libusb/releases/download/v1.0.23/libusb-1.0.23.7z" -OutFile "libusb.7z"
        Invoke-WebRequest "https://gcc.gnu.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip" -OutFile "pthreads.zip"
        
        # Extract libusb
        New-Item -ItemType Directory -Path "deps\libusb" -Force
        7z x libusb.7z -o"deps\libusb"
        
        # Extract pthreads
        Expand-Archive pthreads.zip -DestinationPath "temp" -Force
        $prebuilt = Get-ChildItem "temp" -Recurse -Directory | Where-Object { $_.Name -eq "Pre-built.2" }
        New-Item -ItemType Directory -Path "deps\pthreads" -Force
        Copy-Item "$($prebuilt.FullName)\*" -Destination "deps\pthreads" -Recurse -Force
        Remove-Item "temp" -Recurse -Force

    # === Build Configuration ===
    - name: Configure build (Linux)
      if: matrix.platform == 'linux'
      run: |
        cmake -B build -DCMAKE_BUILD_TYPE=Release -DINSTALL_UDEV_RULES=OFF

    - name: Configure build (macOS)
      if: matrix.platform == 'macos'
      run: |
        if [ "${{ matrix.arch }}" = "arm64" ]; then
          cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm64
        else
          cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64
        fi

    - name: Configure build (Windows)
      if: matrix.platform == 'windows'
      run: |
        cmake -B build -G "Visual Studio 17 2022" -A x64 `
          -DLIBUSB_INCLUDE_DIR="$PWD\deps\libusb\include\libusb-1.0" `
          -DLIBUSB_LIBRARIES="$PWD\deps\libusb\MS64\dll\libusb-1.0.lib" `
          -DTHREADS_PTHREADS_INCLUDE_DIR="$PWD\deps\pthreads\include" `
          -DTHREADS_PTHREADS_WIN32_LIBRARY="$PWD\deps\pthreads\lib\x64\pthreadVC2.lib"

    # === Build ===
    - name: Build (Linux/macOS)
      if: matrix.platform != 'windows'
      shell: bash
      run: |
        if [ "${{ matrix.platform }}" = "macos" ]; then
          cmake --build build --config Release --parallel $(sysctl -n hw.ncpu)
        else
          cmake --build build --config Release --parallel
        fi

    - name: Build (Windows)
      if: matrix.platform == 'windows'
      run: |
        cmake --build build --config Release --parallel

    # === Package Artifacts ===
    - name: Package artifacts (Linux)
      if: matrix.platform == 'linux'
      run: |
        ARTIFACT_DIR="${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}"
        mkdir -p "$ARTIFACT_DIR"
        cp build/libhydrasdr/src/libhydrasdr.so* "$ARTIFACT_DIR/" 2>/dev/null || true
        cp build/hydrasdr-tools/src/hydrasdr_* "$ARTIFACT_DIR/"

    - name: Package artifacts (macOS)
      if: matrix.platform == 'macos'
      run: |
        ARTIFACT_DIR="${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}"
        mkdir -p "$ARTIFACT_DIR"
        cp build/libhydrasdr/src/libhydrasdr.dylib* "$ARTIFACT_DIR/" 2>/dev/null || true
        cp build/hydrasdr-tools/src/hydrasdr_* "$ARTIFACT_DIR/" 2>/dev/null || true

    - name: Package artifacts (Windows)
      if: matrix.platform == 'windows'
      shell: powershell
      run: |
        $dir = "${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}"
        New-Item -ItemType Directory -Path $dir -Force
        Copy-Item "build\libhydrasdr\src\Release\*.lib" $dir -ErrorAction SilentlyContinue
        Copy-Item "build\hydrasdr-tools\src\hydrasdr.dll" $dir -ErrorAction SilentlyContinue
        Copy-Item "deps\libusb\MS64\dll\libusb-1.0.dll" $dir -ErrorAction SilentlyContinue
        Copy-Item "deps\pthreads\dll\x64\pthreadVC2.dll" $dir -ErrorAction SilentlyContinue
        Copy-Item "build\hydrasdr-tools\src\Release\*.exe" $dir

    # === Create .deb package (shared function) ===
    - name: Create .deb package
      if: matrix.create_deb == true
      shell: bash
      run: |
        PACKAGE_VERSION="${{ needs.extract-version.outputs.version }}"
        ARCH="amd64"
        
        # Use the standard package name for internal package creation
        PACKAGE_NAME_FULL="${{ env.PACKAGE_NAME }}"
        PACKAGE_DIR="${PACKAGE_NAME_FULL}_${PACKAGE_VERSION}_${ARCH}"
        
        # Create package directory structure
        mkdir -p "${PACKAGE_DIR}/DEBIAN"
        mkdir -p "${PACKAGE_DIR}/usr/lib"
        mkdir -p "${PACKAGE_DIR}/usr/bin"
        mkdir -p "${PACKAGE_DIR}/usr/share/doc/${PACKAGE_NAME_FULL}"
        mkdir -p "${PACKAGE_DIR}/etc/udev/rules.d"
        
        # Copy binaries and libraries
        cp build/libhydrasdr/src/libhydrasdr.so* "${PACKAGE_DIR}/usr/lib/" 2>/dev/null || true
        cp build/hydrasdr-tools/src/hydrasdr_* "${PACKAGE_DIR}/usr/bin/"
        
        # Copy udev rules file from repository
        cp hydrasdr-tools/51-hydrasdr.rules "${PACKAGE_DIR}/etc/udev/rules.d/51-hydrasdr.rules"
        
        # Create control file
        cat > "${PACKAGE_DIR}/DEBIAN/control" << EOF
        Package: ${PACKAGE_NAME_FULL}
        Version: ${PACKAGE_VERSION}
        Section: electronics
        Priority: optional
        Architecture: ${ARCH}
        Depends: libusb-1.0-0 (>= 1.0.20)
        Maintainer: ${{ env.MAINTAINER }}
        Description: HydraSDR RFOne Host Tools and Libraries
         Host tools and shared libraries for HydraSDR RFOne software-defined radio.
         Provides command-line utilities and development libraries for interfacing
         with HydraSDR RFOne hardware.
         .
         This package includes:
          - libhydrasdr shared library
          - Command-line tools (hydrasdr_info, hydrasdr_lib_version, etc.)
          - Development headers and pkg-config files
         .
         Built for: ${{ matrix.name }}
        Homepage: ${{ env.HOMEPAGE }}
        EOF
        
        # Create maintenance scripts
        cat > "${PACKAGE_DIR}/DEBIAN/postinst" << 'EOF'
        #!/bin/bash
        set -e
        if [ "$1" = "configure" ]; then
          command -v udevadm >/dev/null 2>&1 && { udevadm control --reload-rules || true; udevadm trigger || true; }
          command -v ldconfig >/dev/null 2>&1 && ldconfig || true
        fi
        exit 0
        EOF
        
        cat > "${PACKAGE_DIR}/DEBIAN/postrm" << 'EOF'
        #!/bin/bash
        set -e
        if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
          command -v ldconfig >/dev/null 2>&1 && ldconfig || true
        fi
        exit 0
        EOF
        
        chmod 755 "${PACKAGE_DIR}/DEBIAN/postinst" "${PACKAGE_DIR}/DEBIAN/postrm"
        
        # Create documentation
        cat > "${PACKAGE_DIR}/usr/share/doc/${PACKAGE_NAME_FULL}/copyright" << EOF
        Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
        Upstream-Name: HydraSDR RFOne Host Tools
        Upstream-Contact: ${{ env.MAINTAINER }}
        Source: https://github.com/hydrasdr/rfone_host
        
        Files: *
        Copyright: 2025 ${{ env.MAINTAINER }}
        License: Custom-HydraSDR
         This software is licensed exclusively for HydraSDR products and related development.
         Unauthorized use, modification, or distribution for non-HydraSDR products is prohibited.
         All rights reserved.
        EOF
        
        cat > "${PACKAGE_DIR}/usr/share/doc/${PACKAGE_NAME_FULL}/changelog.Debian" << EOF
        ${PACKAGE_NAME_FULL} (${PACKAGE_VERSION}) unstable; urgency=medium
        
          * Automated build from CI for ${{ matrix.name }}
          * Built from commit ${{ github.sha }}
        
         -- ${{ env.MAINTAINER }}  $(date -R)
        EOF
        
        gzip -9 "${PACKAGE_DIR}/usr/share/doc/${PACKAGE_NAME_FULL}/changelog.Debian"
        
        # Set permissions
        find "${PACKAGE_DIR}" -type d -exec chmod 755 {} \;
        find "${PACKAGE_DIR}/usr/bin" -type f -exec chmod 755 {} \;
        find "${PACKAGE_DIR}/usr/lib" -name "*.so*" -exec chmod 644 {} \;
        chmod 644 "${PACKAGE_DIR}/etc/udev/rules.d/51-hydrasdr.rules"
        
        # Build package
        dpkg-deb --build "${PACKAGE_DIR}"
        
        # Rename to distribution-specific name
        DIST_SPECIFIC_NAME="${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${PACKAGE_VERSION}.deb"
        mv "${PACKAGE_DIR}.deb" "${DIST_SPECIFIC_NAME}"
        
        # Verify the package
        dpkg-deb --info "${DIST_SPECIFIC_NAME}"
        dpkg-deb --contents "${DIST_SPECIFIC_NAME}"
        echo "Created distribution-specific .deb package: ${DIST_SPECIFIC_NAME}"
        
        # Debug: Show what files exist
        echo "=== Files in current directory after .deb creation ==="
        ls -la *.deb 2>/dev/null || echo "No .deb files found"
        ls -la ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.deb 2>/dev/null || echo "No distribution-specific .deb files found"

    # === Testing ===
    - name: Test (Linux)
      if: matrix.platform == 'linux'
      run: |
        export LD_LIBRARY_PATH=build/libhydrasdr/src:$LD_LIBRARY_PATH
        build/hydrasdr-tools/src/hydrasdr_lib_version
        timeout 10s build/hydrasdr-tools/src/hydrasdr_info || echo "No HydraSDR hardware detected (normal in CI environment)"

    - name: Test (macOS)
      if: matrix.platform == 'macos'
      run: |
        export DYLD_LIBRARY_PATH=build/libhydrasdr/src:$DYLD_LIBRARY_PATH
        build/hydrasdr-tools/src/hydrasdr_lib_version
        timeout 10s build/hydrasdr-tools/src/hydrasdr_info || echo "No HydraSDR hardware detected (normal in CI environment)"

    - name: Test (Windows)
      if: matrix.platform == 'windows'
      shell: cmd
      run: |
        copy deps\libusb\MS64\dll\libusb-1.0.dll build\hydrasdr-tools\src\Release\ >nul 2>&1
        copy deps\pthreads\dll\x64\pthreadVC2.dll build\hydrasdr-tools\src\Release\ >nul 2>&1
        copy build\hydrasdr-tools\src\hydrasdr.dll build\hydrasdr-tools\src\Release\ >nul 2>&1
        build\hydrasdr-tools\src\Release\hydrasdr_lib_version.exe
        timeout 10 build\hydrasdr-tools\src\Release\hydrasdr_info.exe >nul 2>&1 || echo No HydraSDR hardware detected (normal in CI environment)
        exit /b 0

    # === Upload ===
    - name: Upload artifacts
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}
        path: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}/*
        retention-days: 30

    - name: Debug .deb files before upload
      if: matrix.create_deb == true
      run: |
        echo "=== Debug: Looking for .deb files to upload ==="
        echo "Current directory: $(pwd)"
        echo "Looking for pattern: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.deb"
        find . -name "*.deb" -type f | head -10
        find . -name "${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.deb" -type f | head -10
        ls -la ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.deb 2>/dev/null || echo "No files match the pattern"

    - name: Upload .deb package
      if: matrix.create_deb == true
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}-deb
        path: "${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.deb"
        retention-days: 30

    - name: Upload .rpm package
      if: matrix.create_rpm == true
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}-rpm
        path: "${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.rpm"
        retention-days: 30

    - name: Upload .pkg.tar package
      if: matrix.create_pkg == true
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}-pkg
        path: "${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.pkg.tar.*"
        retention-days: 30

  build_linux_distros:
    needs: extract-version
    runs-on: ubuntu-latest
    container: ${{ matrix.container }}
    
    strategy:
      fail-fast: false
      matrix:
        include:
          # Ubuntu LTS Versions
          - container: "ubuntu:22.04"
            name: "Ubuntu-22.04-LTS-Jammy-Jellyfish"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
          - container: "ubuntu:20.04"
            name: "Ubuntu-20.04-LTS-Focal-Fossa"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
          
          # Debian Stable/Testing
          - container: "debian:trixie"
            name: "Debian-13-Trixie"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
          - container: "debian:bookworm"
            name: "Debian-12-Bookworm"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
          - container: "debian:bullseye"
            name: "Debian-11-Bullseye"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
          
          # Linux Mint (Ubuntu-based, use Ubuntu containers)
          - container: "ubuntu:24.04"
            name: "Linux-Mint-22.1-Xia"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
            mint_version: "22.1"
          - container: "ubuntu:24.04"
            name: "Linux-Mint-22-Wilma"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
            mint_version: "22"
          - container: "ubuntu:22.04"
            name: "Linux-Mint-21.3-Virginia"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
            mint_version: "21.3"
          - container: "ubuntu:22.04"
            name: "Linux-Mint-21.2-Victoria"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
            mint_version: "21.2"
          - container: "ubuntu:22.04"
            name: "Linux-Mint-21.1-Vera"
            pkg_manager: "apt"
            create_deb: true
            deps: "build-essential cmake pkg-config libusb-1.0-0-dev"
            mint_version: "21.1"
          
          # Fedora Latest Versions
            # Fedora Latest Versions
          - container: "fedora:42"
            name: "Fedora-42"
            pkg_manager: "dnf"
            create_rpm: true
            deps: "gcc gcc-c++ cmake pkg-config libusb1-devel make rpm-build rpmdevtools tar gzip"
          - container: "fedora:41"
            name: "Fedora-41"
            pkg_manager: "dnf"
            create_rpm: true
            deps: "gcc gcc-c++ cmake pkg-config libusb1-devel make rpm-build rpmdevtools tar gzip"
          
          # Enterprise Linux
          - container: "almalinux:9"
            name: "AlmaLinux-9"
            pkg_manager: "dnf"
            create_rpm: true
            deps: "gcc gcc-c++ cmake pkg-config libusb1-devel make epel-release rpm-build rpmdevtools"
            enable_repos: true
          
          # Rolling Release Distributions
          - container: "archlinux:latest"
            name: "Arch-Linux"
            pkg_manager: "pacman"
            create_pkg: true
            deps: "base-devel cmake pkg-config libusb sudo"
          - container: "opensuse/tumbleweed:latest"
            name: "openSUSE-Tumbleweed"
            pkg_manager: "zypper"
            create_rpm: true
            deps: "gcc gcc-c++ cmake pkg-config libusb-1_0-devel make rpm-build rpmdevtools tar gzip"

    name: ${{ matrix.name }}

    steps:
    - uses: actions/checkout@v4

    # === Unified dependency installation ===
    - name: Install dependencies
      run: |
        case "${{ matrix.pkg_manager }}" in
          "apt")
            export DEBIAN_FRONTEND=noninteractive
            export TZ=UTC
            apt-get update
            apt-get install -y ${{ matrix.deps }}
            ;;
          "dnf")
            # Special handling for Fedora 41/42 potential issues
            if [[ "${{ matrix.name }}" == *"Fedora-4"* ]]; then
              dnf update -y --best --allowerasing
              dnf install -y ${{ matrix.deps }}
              # Install additional dependencies that might be needed
              dnf install -y which findutils
            else
              dnf update -y
              dnf install -y ${{ matrix.deps }}
            fi
            ${{ matrix.enable_repos == true && 'dnf config-manager --set-enabled crb || dnf config-manager --set-enabled powertools || true' || '' }}
            # Install chrpath with fallback to patchelf (try EPEL for AlmaLinux)
            if [[ "${{ matrix.name }}" == *"AlmaLinux"* ]]; then
              dnf install -y chrpath || dnf install -y patchelf || echo "Warning: Neither chrpath nor patchelf available"
            else
              dnf install -y chrpath || dnf install -y patchelf || echo "Warning: Neither chrpath nor patchelf available"
            fi
            ;;
          "pacman")
            # Special handling for Arch Linux
            pacman -Sy --noconfirm archlinux-keyring
            pacman -Syu --noconfirm
            pacman -S --noconfirm ${{ matrix.deps }}
            # Ensure makepkg is properly configured
            if ! grep -q "^builduser" /etc/passwd; then
              echo "Setting up build environment for Arch Linux"
            fi
            ;;
          "zypper")
            zypper refresh
            zypper install -y ${{ matrix.deps }}
            # Install chrpath with fallback to patchelf
            zypper install -y chrpath || zypper install -y patchelf || echo "Warning: Neither chrpath nor patchelf available"
            ;;
        esac

    # === Build Configuration ===
    - name: Configure build
      run: |
        CMAKE_FLAGS="-DCMAKE_BUILD_TYPE=Release -DINSTALL_UDEV_RULES=OFF"
        
        # Add extra configuration if specified
        if [ -n "${{ matrix.extra_config }}" ]; then
          CMAKE_FLAGS="$CMAKE_FLAGS ${{ matrix.extra_config }}"
        fi
        
        echo "Building with flags: $CMAKE_FLAGS"
        cmake -B build $CMAKE_FLAGS

    # === Build ===
    - name: Build
      run: cmake --build build --config Release --parallel

    # === Debug build output ===
    - name: Debug build output
      if: matrix.create_rpm == true || matrix.create_pkg == true
      run: |
        echo "=== Build directory structure ==="
        find build -type f -name "*.so*" -o -name "hydrasdr_*" | head -20
        echo "=== Library files ==="
        ls -la build/libhydrasdr/src/ || echo "No libhydrasdr build directory"
        echo "=== Tool files ==="
        ls -la build/hydrasdr-tools/src/ || echo "No hydrasdr-tools build directory"
        echo "=== System info ==="
        uname -a
        if command -v gcc >/dev/null 2>&1; then
          gcc --version | head -1
        fi
        if command -v cmake >/dev/null 2>&1; then
          cmake --version | head -1
        fi

    # === Package Artifacts ===
    - name: Package artifacts
      run: |
        ARTIFACT_DIR="${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}"
        mkdir -p "$ARTIFACT_DIR"
        cp build/libhydrasdr/src/libhydrasdr.so* "$ARTIFACT_DIR/" 2>/dev/null || true
        cp build/hydrasdr-tools/src/hydrasdr_* "$ARTIFACT_DIR/"

    # === Create .deb package for Debian/Ubuntu/Linux Mint ===
    - name: Create .deb package
      if: matrix.create_deb == true
      shell: bash
      run: |
        PACKAGE_VERSION="${{ needs.extract-version.outputs.version }}"
        ARCH="amd64"
        
        # Determine package name based on distribution
        if [ -n "${{ matrix.mint_version }}" ]; then
          PACKAGE_NAME_FULL="${{ env.PACKAGE_NAME }}-mint${{ matrix.mint_version }}"
          DIST_DESC="Linux Mint ${{ matrix.mint_version }}"
        else
          PACKAGE_NAME_FULL="${{ env.PACKAGE_NAME }}"
          DIST_DESC="Debian/Ubuntu"
        fi
        
        PACKAGE_DIR="${PACKAGE_NAME_FULL}_${PACKAGE_VERSION}_${ARCH}"
        
        # Create package directory structure
        mkdir -p "${PACKAGE_DIR}/DEBIAN"
        mkdir -p "${PACKAGE_DIR}/usr/lib"
        mkdir -p "${PACKAGE_DIR}/usr/bin"
        mkdir -p "${PACKAGE_DIR}/usr/share/doc/${PACKAGE_NAME_FULL}"
        mkdir -p "${PACKAGE_DIR}/etc/udev/rules.d"
        
        # Copy binaries and libraries
        cp build/libhydrasdr/src/libhydrasdr.so* "${PACKAGE_DIR}/usr/lib/" 2>/dev/null || true
        cp build/hydrasdr-tools/src/hydrasdr_* "${PACKAGE_DIR}/usr/bin/"
        
        # Copy udev rules file from repository
        cp hydrasdr-tools/51-hydrasdr.rules "${PACKAGE_DIR}/etc/udev/rules.d/51-hydrasdr.rules"
        
        # Create control file
        cat > "${PACKAGE_DIR}/DEBIAN/control" << EOF
        Package: ${PACKAGE_NAME_FULL}
        Version: ${PACKAGE_VERSION}
        Section: electronics
        Priority: optional
        Architecture: ${ARCH}
        Depends: libusb-1.0-0 (>= 1.0.20)
        Maintainer: ${{ env.MAINTAINER }}
        Description: HydraSDR RFOne Host Tools and Libraries (${DIST_DESC})
         Host tools and shared libraries for HydraSDR RFOne software-defined radio.
         Provides command-line utilities and development libraries for interfacing
         with HydraSDR RFOne hardware.
         .
         This package includes:
          - libhydrasdr shared library
          - Command-line tools (hydrasdr_info, hydrasdr_lib_version, etc.)
          - Development headers and pkg-config files
         .
         Built for: ${{ matrix.name }}
        Homepage: ${{ env.HOMEPAGE }}
        EOF
        
        # Create maintenance scripts
        cat > "${PACKAGE_DIR}/DEBIAN/postinst" << 'EOF'
        #!/bin/bash
        set -e
        if [ "$1" = "configure" ]; then
          command -v udevadm >/dev/null 2>&1 && { udevadm control --reload-rules || true; udevadm trigger || true; }
          command -v ldconfig >/dev/null 2>&1 && ldconfig || true
        fi
        exit 0
        EOF
        
        cat > "${PACKAGE_DIR}/DEBIAN/postrm" << 'EOF'
        #!/bin/bash
        set -e
        if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
          command -v ldconfig >/dev/null 2>&1 && ldconfig || true
        fi
        exit 0
        EOF
        
        chmod 755 "${PACKAGE_DIR}/DEBIAN/postinst" "${PACKAGE_DIR}/DEBIAN/postrm"
        
        # Create documentation
        cat > "${PACKAGE_DIR}/usr/share/doc/${PACKAGE_NAME_FULL}/copyright" << EOF
        Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
        Upstream-Name: HydraSDR RFOne Host Tools
        Upstream-Contact: ${{ env.MAINTAINER }}
        Source: https://github.com/hydrasdr/rfone_host
        
        Files: *
        Copyright: 2025 ${{ env.MAINTAINER }}
        License: Custom-HydraSDR
         This software is licensed exclusively for HydraSDR products and related development.
         Unauthorized use, modification, or distribution for non-HydraSDR products is prohibited.
         All rights reserved.
        EOF
        
        cat > "${PACKAGE_DIR}/usr/share/doc/${PACKAGE_NAME_FULL}/changelog.Debian" << EOF
        ${PACKAGE_NAME_FULL} (${PACKAGE_VERSION}) unstable; urgency=medium
        
          * Automated build from CI for ${{ matrix.name }}
          * Built from commit ${{ github.sha }}
        
         -- ${{ env.MAINTAINER }}  $(date -R)
        EOF
        
        gzip -9 "${PACKAGE_DIR}/usr/share/doc/${PACKAGE_NAME_FULL}/changelog.Debian"
        
        # Set permissions
        find "${PACKAGE_DIR}" -type d -exec chmod 755 {} \;
        find "${PACKAGE_DIR}/usr/bin" -type f -exec chmod 755 {} \;
        find "${PACKAGE_DIR}/usr/lib" -name "*.so*" -exec chmod 644 {} \;
        chmod 644 "${PACKAGE_DIR}/etc/udev/rules.d/51-hydrasdr.rules"
        
        # Build and verify package
        dpkg-deb --build "${PACKAGE_DIR}"
        
        # Rename to distribution-specific name
        DIST_SPECIFIC_NAME="${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${PACKAGE_VERSION}.deb"
        mv "${PACKAGE_DIR}.deb" "${DIST_SPECIFIC_NAME}"
        
        dpkg-deb --info "${DIST_SPECIFIC_NAME}"
        dpkg-deb --contents "${DIST_SPECIFIC_NAME}"
        echo "Created distribution-specific .deb package: ${DIST_SPECIFIC_NAME}"

    # === Create .rpm package for Red Hat family (Fedora/AlmaLinux/openSUSE) ===
    - name: Create .rpm package
      if: matrix.create_rpm == true
      shell: bash
      run: |
        set -e
        PACKAGE_VERSION="${{ needs.extract-version.outputs.version }}"
        
        # Setup RPM build environment
        rpmdev-setuptree
        
        # Generate changelog date
        CHANGELOG_DATE=$(date "+%a %b %d %Y")
        
        # Determine libusb package name based on distribution
        if [[ "${{ matrix.name }}" == *"openSUSE"* ]]; then
          LIBUSB_DEP="libusb-1_0-0"
          LIBUSB_DEVEL_DEP="libusb-1_0-devel"
        else
          LIBUSB_DEP="libusb1"
          LIBUSB_DEVEL_DEP="libusb1-devel"
        fi
        
        # Create RPM spec file
        cat > ~/rpmbuild/SPECS/${{ env.PACKAGE_NAME }}.spec << EOF
        Name:           ${{ env.PACKAGE_NAME }}
        Version:        ${PACKAGE_VERSION}
        Release:        1%{?dist}
        Summary:        HydraSDR RFOne Host Tools and Libraries
        
        License:        Custom-HydraSDR
        URL:            ${{ env.HOMEPAGE }}
        
        BuildRequires:  gcc gcc-c++ cmake pkg-config ${LIBUSB_DEVEL_DEP} make
        Requires:       ${LIBUSB_DEP} >= 1.0.20
        
        %description
        Host tools and shared libraries for HydraSDR RFOne software-defined radio.
        Provides command-line utilities and development libraries for interfacing
        with HydraSDR RFOne hardware.
        
        This package includes:
        - libhydrasdr shared library
        - Command-line tools (hydrasdr_info, hydrasdr_lib_version, etc.)
        - Development headers and pkg-config files
        
        Built for: ${{ matrix.name }}
        
        %prep
        # Copy source files to build directory
        mkdir -p %{_builddir}/%{name}-%{version}
        cp -r %{_sourcedir}/* %{_builddir}/%{name}-%{version}/
        
        %build
        # Files already built, just verify they exist
        ls -la %{_builddir}/%{name}-%{version}/build/libhydrasdr/src/
        ls -la %{_builddir}/%{name}-%{version}/build/hydrasdr-tools/src/
        
        %install
        rm -rf %{buildroot}
        
        # Create directory structure
        mkdir -p %{buildroot}/usr/lib
        mkdir -p %{buildroot}/usr/bin
        mkdir -p %{buildroot}/etc/udev/rules.d
        
        # Copy files from build directory
        cp %{_builddir}/%{name}-%{version}/build/libhydrasdr/src/libhydrasdr.so* %{buildroot}/usr/lib/ || true
        cp %{_builddir}/%{name}-%{version}/build/hydrasdr-tools/src/hydrasdr_* %{buildroot}/usr/bin/
        cp %{_builddir}/%{name}-%{version}/hydrasdr-tools/51-hydrasdr.rules %{buildroot}/etc/udev/rules.d/51-hydrasdr.rules
        
        # Debug: Show RPATH information before fixing
        echo "=== RPATH Information Before Fixing ==="
        for binary in %{buildroot}/usr/bin/hydrasdr_*; do
          if [ -f "\$binary" ]; then
            echo "Binary: \$binary"
            if command -v chrpath >/dev/null 2>&1; then
              chrpath -l "\$binary" || echo "No RPATH found"
            elif command -v readelf >/dev/null 2>&1; then
              readelf -d "\$binary" | grep -E "(RPATH|RUNPATH)" || echo "No RPATH found"
            fi
          fi
        done
        
        # Fix RPATH issues by stripping RPATH from binaries
        echo "=== Fixing RPATH Issues ==="
        for binary in %{buildroot}/usr/bin/hydrasdr_*; do
          if [ -f "\$binary" ]; then
            echo "Processing binary: \$binary"
            # Strip RPATH using chrpath if available, otherwise use patchelf
            if command -v chrpath >/dev/null 2>&1; then
              chrpath -d "\$binary" 2>/dev/null || echo "Could not remove RPATH from \$binary"
            elif command -v patchelf >/dev/null 2>&1; then
              patchelf --remove-rpath "\$binary" 2>/dev/null || echo "Could not remove RPATH from \$binary"
            else
              echo "Warning: Neither chrpath nor patchelf available to fix RPATH"
            fi
          fi
        done
        
        # Set proper RPATH for shared libraries if needed
        for lib in %{buildroot}/usr/lib/libhydrasdr.so*; do
          if [ -f "\$lib" ] && [ ! -L "\$lib" ]; then
            echo "Processing library: \$lib"
            if command -v chrpath >/dev/null 2>&1; then
              chrpath -r /usr/lib "\$lib" 2>/dev/null || echo "Could not set RPATH for \$lib"
            elif command -v patchelf >/dev/null 2>&1; then
              patchelf --set-rpath /usr/lib "\$lib" 2>/dev/null || echo "Could not set RPATH for \$lib"
            fi
          fi
        done
        
        # Debug: Show RPATH information after fixing
        echo "=== RPATH Information After Fixing ==="
        for binary in %{buildroot}/usr/bin/hydrasdr_*; do
          if [ -f "\$binary" ]; then
            echo "Binary: \$binary"
            if command -v chrpath >/dev/null 2>&1; then
              chrpath -l "\$binary" || echo "No RPATH found (expected)"
            elif command -v readelf >/dev/null 2>&1; then
              readelf -d "\$binary" | grep -E "(RPATH|RUNPATH)" || echo "No RPATH found (expected)"
            fi
          fi
        done
        
        %post
        /sbin/ldconfig
        if command -v udevadm >/dev/null 2>&1; then
            udevadm control --reload-rules || true
            udevadm trigger || true
        fi
        
        %postun
        /sbin/ldconfig
        
        %files
        %defattr(-,root,root,-)
        /usr/lib/libhydrasdr.so*
        /usr/bin/hydrasdr_*
        /etc/udev/rules.d/51-hydrasdr.rules
        
        %changelog
        * ${CHANGELOG_DATE} ${{ env.MAINTAINER }} - ${PACKAGE_VERSION}-1
        - Automated build from CI for ${{ matrix.name }}
        - Built from commit ${{ github.sha }}
        EOF
        
        # Copy source files to SOURCES directory
        cp -r . ~/rpmbuild/SOURCES/
        
        # Build the RPM package
        rpmbuild -bb ~/rpmbuild/SPECS/${{ env.PACKAGE_NAME }}.spec \
          --define "_sourcedir $(pwd)" \
          --define "_builddir $HOME/rpmbuild/BUILD" \
          --define "_buildrootdir $HOME/rpmbuild/BUILDROOT"
        
        # Copy the built RPM to current directory and rename to distribution-specific name
        find ~/rpmbuild/RPMS -name "*.rpm" -exec cp {} . \;
        
        # Rename RPM to distribution-specific name
        for rpm_file in *.rpm; do
          if [ -f "$rpm_file" ]; then
            DIST_SPECIFIC_NAME="${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${PACKAGE_VERSION}.rpm"
            mv "$rpm_file" "$DIST_SPECIFIC_NAME"
            echo "Renamed $rpm_file to $DIST_SPECIFIC_NAME"
            break
          fi
        done
        
        # Verify the renamed package
        for rpm_file in ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.rpm; do
          if [ -f "$rpm_file" ]; then
            echo "Created distribution-specific RPM package: $rpm_file"
            rpm -qip "$rpm_file" || echo "Could not query package info"
            rpm -qlp "$rpm_file" || echo "Could not query package files"
          fi
        done

    # === Create .pkg.tar.xz package for Arch Linux ===
    - name: Create .pkg.tar.xz package
      if: matrix.create_pkg == true
      shell: bash
      run: |
        set -e
        PACKAGE_VERSION="${{ needs.extract-version.outputs.version }}"
        
        # Get absolute path to current directory
        ORIGINAL_DIR=$(pwd)
        echo "Original directory: $ORIGINAL_DIR"
        echo "Build directory contents:"
        ls -la "$ORIGINAL_DIR/build/libhydrasdr/src/" || echo "No libhydrasdr build directory"
        ls -la "$ORIGINAL_DIR/build/hydrasdr-tools/src/" || echo "No hydrasdr-tools build directory"
        
        # Create non-root user for makepkg if it doesn't exist
        if ! id -u builduser >/dev/null 2>&1; then
          useradd -m -s /bin/bash builduser
          echo "builduser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
        fi
        
        # Create package directory
        mkdir -p /tmp/pkg/${{ env.PACKAGE_NAME }}
        cd /tmp/pkg/${{ env.PACKAGE_NAME }}
        
        # Create PKGBUILD file
        cat > PKGBUILD << 'EOF'
        # Maintainer: ${{ env.MAINTAINER }}
        pkgname=${{ env.PACKAGE_NAME }}
        pkgver={{ PACKAGE_VERSION }}
        pkgrel=1
        pkgdesc="HydraSDR RFOne Host Tools and Libraries"
        arch=('x86_64')
        url="${{ env.HOMEPAGE }}"
        license=('custom:HydraSDR')
        depends=('libusb>=1.0.20')
        
        package() {
          # Create directory structure
          mkdir -p "${pkgdir}/usr/lib"
          mkdir -p "${pkgdir}/usr/bin" 
          mkdir -p "${pkgdir}/etc/udev/rules.d"
          mkdir -p "${pkgdir}/usr/share/licenses/${pkgname}"
          
          # Copy files from build directory (using absolute path from original location)
          cp {{ ORIGINAL_DIR }}/build/libhydrasdr/src/libhydrasdr.so* "${pkgdir}/usr/lib/" || true
          cp {{ ORIGINAL_DIR }}/build/hydrasdr-tools/src/hydrasdr_* "${pkgdir}/usr/bin/"
          cp {{ ORIGINAL_DIR }}/hydrasdr-tools/51-hydrasdr.rules "${pkgdir}/etc/udev/rules.d/51-hydrasdr.rules"
          
          # Create license file
          cat > "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE" << 'LICENSE_EOF'
        HydraSDR RFOne Host Tools
        
        Copyright (c) 2025, ${{ env.MAINTAINER }}
        
        This software is licensed exclusively for HydraSDR products and related development.
        Unauthorized use, modification, or distribution for non-HydraSDR products is prohibited.
        All rights reserved.
        
        For more information: ${{ env.HOMEPAGE }}
        LICENSE_EOF
        }
        EOF
        
        # Replace placeholders in PKGBUILD with absolute path
        sed -i "s/{{ PACKAGE_VERSION }}/${PACKAGE_VERSION}/g" PKGBUILD
        sed -i "s|{{ ORIGINAL_DIR }}|${ORIGINAL_DIR}|g" PKGBUILD
        
        # Debug: show the final PKGBUILD
        echo "=== Final PKGBUILD ==="
        cat PKGBUILD
        echo "======================="
        
        # Set ownership and permissions
        chown -R builduser:builduser /tmp/pkg
        chmod -R 755 /tmp/pkg
        
        # Build the package as non-root user
        sudo -u builduser makepkg --skipinteg --skippgpcheck --nodeps --noconfirm
        
        # Find and copy the built package (handle both .xz and .zst formats)
        BUILT_PACKAGE=""
        for ext in pkg.tar.zst pkg.tar.xz pkg.tar.gz; do
          if ls *.$ext 1> /dev/null 2>&1; then
            BUILT_PACKAGE=$(ls *.$ext | head -1)
            break
          fi
        done
        
        if [ -z "$BUILT_PACKAGE" ]; then
          echo "ERROR: No package file found. Available files:"
          ls -la
          exit 1
        fi
        
        echo "Found package: $BUILT_PACKAGE"
        
        # Rename to distribution-specific name
        # Extract the extension (e.g., pkg.tar.zst, pkg.tar.xz)
        if [[ "$BUILT_PACKAGE" == *.pkg.tar.zst ]]; then
          EXT="pkg.tar.zst"
        elif [[ "$BUILT_PACKAGE" == *.pkg.tar.xz ]]; then
          EXT="pkg.tar.xz"
        elif [[ "$BUILT_PACKAGE" == *.pkg.tar.gz ]]; then
          EXT="pkg.tar.gz"
        else
          EXT="pkg.tar.zst"  # Default fallback
        fi
        
        DIST_SPECIFIC_NAME="${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${PACKAGE_VERSION}.${EXT}"
        mv "$BUILT_PACKAGE" "$DIST_SPECIFIC_NAME"
        echo "Renamed $BUILT_PACKAGE to $DIST_SPECIFIC_NAME"
        
        cp "$DIST_SPECIFIC_NAME" "$ORIGINAL_DIR/"
        
        cd "$ORIGINAL_DIR"
        
        # Verify the renamed package
        for pkg_file in ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.pkg.tar.*; do
          if [ -f "$pkg_file" ]; then
            echo "Created distribution-specific Arch package: $pkg_file"
            tar -tf "$pkg_file" | head -20 || echo "Could not list package contents"
            echo "Package size: $(du -h "$pkg_file")"
            break
          fi
        done

    - name: Test
      run: |
        export LD_LIBRARY_PATH=build/libhydrasdr/src:$LD_LIBRARY_PATH
        build/hydrasdr-tools/src/hydrasdr_lib_version
        timeout 10s build/hydrasdr-tools/src/hydrasdr_info || echo "No HydraSDR hardware detected (normal in CI environment)"

    # === Upload ===
    - name: Upload artifacts
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}
        path: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}/*
        retention-days: 30

    - name: Upload .deb package
      if: matrix.create_deb == true
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}-deb
        path: "${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.deb"
        retention-days: 30

    - name: Upload .rpm package
      if: matrix.create_rpm == true
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}-rpm
        path: "${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.rpm"
        retention-days: 30

    - name: Upload .pkg.tar package
      if: matrix.create_pkg == true
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v${{ needs.extract-version.outputs.version }}-pkg
        path: "${{ env.PACKAGE_NAME }}-${{ matrix.name }}-v*.pkg.tar.*"
        retention-days: 30

  create_full_archive:
    needs: [extract-version, build, build_linux_distros]
    runs-on: ubuntu-latest
    steps:
    - name: Download All Builds
      uses: actions/download-artifact@v4

    - name: Create platform-specific archives
      run: |
        rm -rf hydrasdr_all
        mkdir hydrasdr_all
        
        # First, copy all native package files (now with distribution-specific names)
        echo "=== Copying native packages ==="
        find . -name "${{ env.PACKAGE_NAME }}-*-v*.deb" -exec cp {} hydrasdr_all/ \;
        find . -name "${{ env.PACKAGE_NAME }}-*-v*.rpm" -exec cp {} hydrasdr_all/ \;
        find . -name "${{ env.PACKAGE_NAME }}-*-v*.pkg.tar.*" -exec cp {} hydrasdr_all/ \;
        
        # Count native packages
        DEB_COUNT=$(find hydrasdr_all -name "*.deb" | wc -l)
        RPM_COUNT=$(find hydrasdr_all -name "*.rpm" | wc -l)
        PKG_COUNT=$(find hydrasdr_all -name "*.pkg.tar.*" | wc -l)
        
        echo "Found $DEB_COUNT .deb packages"
        echo "Found $RPM_COUNT .rpm packages"  
        echo "Found $PKG_COUNT .pkg.tar.* packages"
        
        # Create archives for platforms without native packages + required CI archives
        echo "=== Creating archives ==="
        for dir in ${{ env.PACKAGE_NAME }}-*; do
          if [ -d "$dir" ]; then
            # Skip package artifact directories (they end with -deb, -rpm, -pkg)
            if [[ "$dir" == *"-deb" ]] || [[ "$dir" == *"-rpm" ]] || [[ "$dir" == *"-pkg" ]]; then
              echo "Skipping package artifact directory: $dir"
              continue
            fi
            
            echo "Processing directory: $dir"
            
            # Always create archives for Windows and macOS (no native packages)
            if [[ "$dir" == *"Windows"* ]]; then
              echo "Creating Windows ZIP: ${dir}.zip"
              cd "$dir" && zip -r "../hydrasdr_all/${dir}.zip" . && cd ..
            elif [[ "$dir" == *"macOS"* ]]; then
              echo "Creating macOS archive: ${dir}.tar.gz"
              tar -czf "hydrasdr_all/${dir}.tar.gz" -C "$dir" .
            # Special case: Always create ZIP archives for Ubuntu 22.04 and 24.04 (required for firmware CI)
            elif [[ "$dir" == *"Ubuntu-22.04"* ]] || [[ "$dir" == *"Ubuntu-24.04"* ]]; then
              echo "Creating Ubuntu CI archive: ${dir}.zip (required for firmware workflow)"
              cd "$dir" && zip -r "../hydrasdr_all/${dir}.zip" . && cd ..
            else
              # For other Linux distributions, only create archives if no native packages exist
              HAS_NATIVE_PACKAGE=false
              
              # Check if this distribution has a native package
              if [[ "$dir" == *"Ubuntu"* ]] || [[ "$dir" == *"Debian"* ]] || [[ "$dir" == *"Linux-Mint"* ]]; then
                if [ $DEB_COUNT -gt 0 ]; then
                  HAS_NATIVE_PACKAGE=true
                  echo "Skipping archive for $dir (has .deb packages)"
                fi
              elif [[ "$dir" == *"Fedora"* ]] || [[ "$dir" == *"AlmaLinux"* ]] || [[ "$dir" == *"openSUSE"* ]]; then
                if [ $RPM_COUNT -gt 0 ]; then
                  HAS_NATIVE_PACKAGE=true
                  echo "Skipping archive for $dir (has .rpm packages)"
                fi
              elif [[ "$dir" == *"Arch"* ]]; then
                if [ $PKG_COUNT -gt 0 ]; then
                  HAS_NATIVE_PACKAGE=true
                  echo "Skipping archive for $dir (has .pkg.tar.* packages)"
                fi
              fi
              
              # Create archive only if no native package exists
              if [ "$HAS_NATIVE_PACKAGE" = false ]; then
                echo "Creating Linux archive: ${dir}.tar.gz"
                tar -czf "hydrasdr_all/${dir}.tar.gz" -C "$dir" .
              fi
            fi
          fi
        done
        
        echo "=== Final contents of hydrasdr_all ==="
        ls -la hydrasdr_all/
        
        # Show summary
        echo "=== Package Summary ==="
        echo "Native packages (preferred):"
        echo "  - .deb files: $(find hydrasdr_all -name "*.deb" | wc -l)"
        echo "  - .rpm files: $(find hydrasdr_all -name "*.rpm" | wc -l)"
        echo "  - .pkg.tar.* files: $(find hydrasdr_all -name "*.pkg.tar.*" | wc -l)"
        echo "CI/CD archives (required for firmware builds):"
        echo "  - Ubuntu ZIP files: $(find hydrasdr_all -name "*Ubuntu*.zip" | wc -l)"
        echo "Generic archives (fallback):"
        echo "  - .tar.gz files: $(find hydrasdr_all -name "*.tar.gz" | wc -l)"
        echo "  - .zip files: $(find hydrasdr_all -name "*.zip" | wc -l)"

    - name: Upload Full Archive
      uses: actions/upload-artifact@v4
      with:
        name: hydrasdr_all
        path: hydrasdr_all/*

  update_nightly_release:
    needs: [extract-version, create_full_archive]
    runs-on: ubuntu-latest
    if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
    steps:
    - name: Download All Builds
      uses: actions/download-artifact@v4
      
    - name: List downloaded artifacts
      run: |
        echo "Downloaded artifacts:"
        ls -la
        echo "Contents of hydrasdr_all:"
        ls -la hydrasdr_all/ || echo "hydrasdr_all directory not found"
      
    - name: Create or Update Nightly Release
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        # Delete existing nightly release completely to ensure clean slate
        echo "Deleting existing nightly release..."
        gh release delete nightly -R ${{github.repository}} --yes || echo "Nightly release doesn't exist or already deleted"
        
        # Create fresh nightly release
        echo "Creating fresh nightly release..."
        gh release create nightly -R ${{github.repository}} --title "Nightly Build" --notes "Automated nightly build from CI - Built from commit ${{ github.sha }}" --prerelease
        
        # Upload platform-specific archives from hydrasdr_all
        if [ -d "hydrasdr_all" ] && [ "$(ls -A hydrasdr_all)" ]; then
          echo "Uploading platform-specific archives..."
          gh release upload nightly hydrasdr_all/* -R ${{github.repository}}
        else
          echo "No archive files found in hydrasdr_all directory"
        fi

    - name: Update Release Notes
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        VERSION: ${{ needs.extract-version.outputs.version }}
      run: |
        gh release edit nightly -R ${{github.repository}} --notes "Automated nightly build from CI

        **Built from commit:** ${{ github.sha }}
        **Build Date:** $(date -u)
        **Branch:** ${{ github.ref_name }}

        ## Available Builds:

        ### Desktop Platforms (Generic Archives):
        - **Windows x64** (.zip)
        - **macOS ARM64** (Apple Silicon M1/M2/M3) (.tar.gz)
        - **macOS x86_64** (Intel Macs) (.tar.gz)

        ### GNU/Linux Distributions (Native Packages - Recommended):
        
        #### .deb packages (apt/dpkg):
        - **Ubuntu 24.04 LTS** (Noble Numbat) - \`sudo dpkg -i\` *[.zip also available for CI/CD]*
        - **Ubuntu 22.04 LTS** (Jammy Jellyfish) - \`sudo dpkg -i\` *[.zip also available for CI/CD]*
        - **Ubuntu 20.04 LTS** (Focal Fossa) - \`sudo dpkg -i\`
        - **Linux Mint 22.1** (Xia) - \`sudo dpkg -i\`
        - **Linux Mint 22** (Wilma) - \`sudo dpkg -i\`
        - **Linux Mint 21.3** (Virginia) - \`sudo dpkg -i\`
        - **Linux Mint 21.2** (Victoria) - \`sudo dpkg -i\`
        - **Linux Mint 21.1** (Vera) - \`sudo dpkg -i\`
        - **Debian 13** (Trixie) - \`sudo dpkg -i\`
        - **Debian 12** (Bookworm) - \`sudo dpkg -i\`
        - **Debian 11** (Bullseye) - \`sudo dpkg -i\`

        #### .rpm packages (dnf/yum/zypper):
        - **Fedora 42** (Latest) - \`sudo dnf install\`
        - **Fedora 41** - \`sudo dnf install\`
        - **AlmaLinux 9** - \`sudo dnf install\`
        - **openSUSE Tumbleweed** - \`sudo zypper install\`

        #### .pkg.tar.zst packages (pacman):
        - **Arch Linux** - \`sudo pacman -U\`

        ## Installation Instructions:

        ### Recommended: Native Packages (Automatic dependency management)

        #### Debian/Ubuntu/Linux Mint (.deb packages):
        \`\`\`bash
        # Download the appropriate .deb file for your distribution
        # Examples:
        # wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-Ubuntu-22.04-LTS-Jammy-Jellyfish-v${VERSION}.deb
        # wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-Ubuntu-24.04-LTS-Noble-Numbat-v${VERSION}.deb
        # wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-Debian-12-Bookworm-v${VERSION}.deb
        
        # Install the package
        sudo dpkg -i hydrasdr-host-tools-[DISTRIBUTION]-v[VERSION].deb
        sudo apt-get install -f  # Fix any dependency issues if needed
        
        # Add your user to plugdev group for device access
        sudo usermod -a -G plugdev \$USER
        # Log out and back in for group changes to take effect
        \`\`\`

        #### Fedora/AlmaLinux (.rpm packages):
        \`\`\`bash
        # Download the appropriate .rpm file for your distribution
        # Examples:
        # wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-Fedora-42-v${VERSION}.rpm
        # wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-AlmaLinux-9-v${VERSION}.rpm
        
        # Install with automatic dependency resolution
        sudo dnf install ./hydrasdr-host-tools-[DISTRIBUTION]-v[VERSION].rpm
        
        # Add your user to plugdev group for device access
        sudo usermod -a -G plugdev \$USER
        \`\`\`

        #### openSUSE (.rpm packages):
        \`\`\`bash
        # Download the appropriate .rpm file
        # wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-openSUSE-Tumbleweed-v${VERSION}.rpm
        
        # Install with automatic dependency resolution
        sudo zypper install ./hydrasdr-host-tools-openSUSE-Tumbleweed-v[VERSION].rpm
        
        # Add your user to plugdev group for device access
        sudo usermod -a -G plugdev \$USER
        \`\`\`

        #### Arch Linux (.pkg.tar.zst packages):
        \`\`\`bash
        # Download the .pkg.tar.zst file
        # wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-Arch-Linux-v${VERSION}.pkg.tar.zst
        
        # Install with pacman
        sudo pacman -U hydrasdr-host-tools-Arch-Linux-v[VERSION].pkg.tar.zst
        
        # Add your user to plugdev group for device access
        sudo usermod -a -G plugdev \$USER
        \`\`\`

        ### Alternative: Generic Archives (Manual installation)

        #### Windows:
        \`\`\`powershell
        # Download and extract the .zip file
        # All required DLLs are included in the package
        # Add the extracted directory to your PATH environment variable
        \`\`\`

        #### macOS:
        \`\`\`bash
        # Download and extract the .tar.gz file
        wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/[package-name].tar.gz
        tar -xzf [package-name].tar.gz
        
        # Copy binaries to your PATH
        sudo cp [extracted-dir]/* /usr/local/bin/
        
        # Install dependencies via Homebrew
        brew install libusb
        \`\`\`

        #### Other Linux Distributions (if no native package available):
        \`\`\`bash
        # Download the appropriate .tar.gz archive
        wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/[package-name].tar.gz
        
        # Extract and install manually
        tar -xzf [package-name].tar.gz
        sudo cp [extracted-dir]/* /usr/local/bin/
        sudo cp [extracted-dir]/libhydrasdr.so* /usr/local/lib/
        sudo ldconfig
        
        # Install dependencies via package manager
        # Ubuntu/Debian: sudo apt-get install libusb-1.0-0
        # Fedora: sudo dnf install libusb1
        # Arch: sudo pacman -S libusb
        \`\`\`

        ### For CI/CD Workflows:
        Ubuntu 24.04 and 22.04 also provide .zip archives for automated workflows:
        \`\`\`bash
        # Download Ubuntu 24.04: .zip archive (for CI/CD)
        wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-Ubuntu-24.04-LTS-Noble-Numbat-v${VERSION}.zip
        unzip hydrasdr-host-tools-Ubuntu-24.04-LTS-Noble-Numbat-v${VERSION}.zip
        
        # Or for Ubuntu 22.04:
        wget https://github.com/hydrasdr/rfone_host/releases/download/nightly/hydrasdr-host-tools-Ubuntu-22.04-LTS-Jammy-Jellyfish-v${VERSION}.zip
        unzip hydrasdr-host-tools-Ubuntu-22.04-LTS-Jammy-Jellyfish-v${VERSION}.zip
        \`\`\`

        ## System Requirements:
        - **libusb 1.0.23** (avoid 1.0.24 due to known issues)
        - **USB 2.0 or 3.0 port** for HydraSDR RFOne device
        - **64-bit architecture** (amd64/x86_64)

        ## Package Features:
        - **Automatic dependency management** - Required libraries installed automatically  
        - **System integration** - Proper udev rules for non-root device access  
        - **Easy removal** - Standard package manager commands for clean uninstall  
        - **Automatic updates** - Library cache and udev rules updated automatically  
        - **Digital signatures** - All packages built in secure CI environment  

        ## Comprehensive Distribution Coverage:
        This release provides native packages for **major GNU/Linux distributions** including all current LTS versions of Ubuntu, stable Debian releases, latest Fedora versions, and rolling-release distributions. 
        
        **Distribution-specific naming**: All packages use clear, descriptive names that identify their target distribution (e.g., \`hydrasdr-host-tools-Ubuntu-22.04-LTS-Jammy-Jellyfish-v${VERSION}.deb\`, \`hydrasdr-host-tools-Fedora-42-v${VERSION}.rpm\`).
        
        **Special provision**: Ubuntu 24.04 and 22.04 provide both native .deb packages (recommended for users) and .zip archives (required for automated firmware build workflows).

        ## Notes:
        - **Native packages strongly recommended** for easiest installation experience
        - **Distribution-specific naming** - All packages clearly identify their target distribution
        - **Generic archives** provided for Windows, macOS, and unsupported Linux distributions
        - **Ubuntu ZIP archives** provided for CI/CD workflows (firmware builds)
        - **Native packages** handle dependencies, system integration, and updates automatically
        - **Nightly build** - This is an automated nightly build with latest features  
        - **Stable releases** - For stable releases, use tagged releases instead
        - **Issue reporting** - Report issues at https://github.com/${{github.repository}}/issues
        - **Documentation** - Full documentation at ${{ env.HOMEPAGE }}"