dcr 0.8.4

DCR is a utility for managing C/C++ projects in a Cargo-like style.
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
name: Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:
    inputs:
      tag:
        description: "Tag to build (e.g. v0.6.7)"
        required: true
      run_linux:
        description: "Build Linux"
        type: boolean
        default: true
      run_linux_packages:
        description: "Build Linux Packages (.deb, .rpm, .snap, .pkg.tar.zst)"
        type: boolean
        default: true
      run_aur:
        description: "Update AUR packages (dcr & dcr-bin)"
        type: boolean
        default: false 
      run_aur_dev:
        description: "Update Dev AUR packages (dcr-dev, dcr-dev-bin)"
        type: boolean
        default: false
      run_bsd:
        description: "Build BSD"
        type: boolean
        default: true
      run_macos:
        description: "Build macOS"
        type: boolean
        default: true
      run_windows:
        description: "Build Windows"
        type: boolean
        default: true
      run_publish:
        description: "Publish to crates.io"
        type: boolean
        default: false
      run_brew:
        description: "Update Homebrew tap"
        type: boolean
        default: false

permissions:
  contents: write

jobs:
  # ── Resolve Tag ────────────────────────────────────────────────────────────
  setup:
    runs-on: ubuntu-latest
    outputs:
      tag: ${{ steps.tag.outputs.value }}
      version: ${{ steps.tag.outputs.version }}
      clean_version: ${{ steps.tag.outputs.clean_version }}
      prerelease: ${{ steps.tag.outputs.prerelease }}
    steps:
      - name: Resolve tag
        id: tag
        run: |
          if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
            TAG="${{ github.event.inputs.tag }}"
          else
            TAG="${GITHUB_REF_NAME}"
          fi
          VERSION="${TAG#v}"
          CLEAN_VERSION="${VERSION%-dev}"
          [[ "$TAG" == *"-"* ]] && PRERELEASE="true" || PRERELEASE="false"
          echo "value=${TAG}"             >> "$GITHUB_OUTPUT"
          echo "version=${VERSION}"       >> "$GITHUB_OUTPUT"
          echo "clean_version=${CLEAN_VERSION}" >> "$GITHUB_OUTPUT"
          echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"

  # ── Release Notes ──────────────────────────────────────────────────────────
  notes:
    needs: setup
    runs-on: ubuntu-latest
    outputs:
      release_name: ${{ steps.extract.outputs.release_name }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - name: Prepare Release Notes
        id: extract
        shell: bash
        run: |
          set -euo pipefail
          tag="${{ needs.setup.outputs.version }}"
          notes_file=".github/release-notes.md"
          # Strip -dev suffix to match base version in CHANGELOG
          changelog_tag="${tag%-dev}"
          if grep -q "^## \\[${changelog_tag}\\]" CHANGELOG.md; then
            # Extract release name from header: ## [0.7.1] - 2026-06-02 "Title"
            release_name=$(awk -v search_ver="$changelog_tag" -v display_ver="$tag" '
              $0 ~ "^## \\[" search_ver "\\]" {
                match($0, /"([^"]+)"/, arr)
                if (arr[1] != "") {
                  print "v" display_ver " - " arr[1]
                } else {
                  print "v" display_ver
                }
              }
            ' CHANGELOG.md)
            echo "release_name=${release_name}" >> "$GITHUB_OUTPUT"
            awk -v ver="$changelog_tag" '
              $0 ~ "^## \\[" ver "\\]" {found=1; next}
              found && $0 ~ "^## \\[" {exit}
              found {print}
            ' CHANGELOG.md | sed -e '${/^$/d;}' > "$notes_file"
          else
            echo "release_name=v${tag}" >> "$GITHUB_OUTPUT"
            echo "No CHANGELOG section for $tag." > "$notes_file"
            git log -1 --pretty=format:"%s%n%n%b" >> "$notes_file"
          fi

      - name: Upload Notes Artifact
        uses: actions/upload-artifact@v4
        with:
          name: release-notes
          path: .github/release-notes.md

  # ── Create Release (prevent race conditions) ───────────────────────────────
  create-release:
    needs: [setup, notes]
    runs-on: ubuntu-latest
    steps:
      - name: Download Release Notes
        uses: actions/download-artifact@v4
        with:
          name: release-notes
          path: .github

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.setup.outputs.tag }}
          name: ${{ needs.notes.outputs.release_name }}
          body_path: .github/release-notes.md
          prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}

  # ── Man Pages Archive ──────────────────────────────────────────────────────
  man-pages:
    if: ${{ github.event_name == 'push' || github.event.inputs.run_linux == 'true' }}
    needs: [setup, notes, create-release]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - name: Download Release Notes
        uses: actions/download-artifact@v4
        with:
          name: release-notes
          path: .github

      - name: Create Man Pages Archive
        run: |
          tar czf "dcr-man-pages-${{ needs.setup.outputs.version }}.tar.gz" \
            --transform 's/^man\/man1\//usr\/share\/man\/man1\//' \
            man/man1/*.1

      - name: Upload Man Pages to Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.setup.outputs.tag }}
          files: dcr-man-pages-${{ needs.setup.outputs.version }}.tar.gz
          body_path: .github/release-notes.md
          prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}

  # ── Linux Binaries Matrix ──────────────────────────────────────────────────
  build-linux:
    if: ${{ github.event_name == 'push' || github.event.inputs.run_linux == 'true' }}
    needs: [setup, notes, create-release]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
          - target: aarch64-unknown-linux-gnu
          - target: x86_64-unknown-linux-musl
          - target: aarch64-unknown-linux-musl
          - target: i686-unknown-linux-gnu
          - target: i686-unknown-linux-musl
          - target: armv7-unknown-linux-gnueabihf
          - target: armv7-unknown-linux-musleabihf
          - target: riscv64gc-unknown-linux-gnu
          - target: riscv64gc-unknown-linux-musl
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - name: Download Release Notes
        uses: actions/download-artifact@v4
        with:
          name: release-notes
          path: .github

      - name: Install cargo-zigbuild
        run: |
          pip install cargo-zigbuild
          echo "$HOME/.local/bin" >> $GITHUB_PATH

      - name: Setup Zig
        if: matrix.target != 'x86_64-unknown-linux-gnu'
        uses: mlugg/setup-zig@v1
        with:
          version: 0.13.0

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build
        run: |
          if [ "${{ matrix.target }}" != "x86_64-unknown-linux-gnu" ]; then
            cargo zigbuild --release --features archive --target ${{ matrix.target }}
          else
            cargo build --release --features archive --target ${{ matrix.target }}
          fi

      - name: Prepare Artifact
        run: |
          ASSET="dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}"
          cp target/${{ matrix.target }}/release/dcr "$ASSET"
          echo "ASSET_NAME=${ASSET}" >> "$GITHUB_ENV"

      - name: Upload Release Asset
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.setup.outputs.tag }}
          files: ${{ env.ASSET_NAME }}
          body_path: .github/release-notes.md
          prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}

  # ── Linux Packages Matrix (.deb, .rpm, .pkg.tar.zst, .snap) ────────────────
  build-linux-packages:
    if: ${{ github.event_name == 'push' || github.event.inputs.run_linux_packages == 'true' }}
    needs: [setup, notes]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        package_type: [deb, rpm, arch, snap]
        target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, i686-unknown-linux-gnu, armv7-unknown-linux-gnueabihf, riscv64gc-unknown-linux-gnu]
        exclude:
          - package_type: arch
            target: aarch64-unknown-linux-gnu
          - package_type: arch
            target: i686-unknown-linux-gnu
          - package_type: arch
            target: armv7-unknown-linux-gnueabihf
          - package_type: arch
            target: riscv64gc-unknown-linux-gnu
          - package_type: snap
            target: aarch64-unknown-linux-gnu
          - package_type: snap
            target: i686-unknown-linux-gnu
          - package_type: snap
            target: armv7-unknown-linux-gnueabihf
          - package_type: snap
            target: riscv64gc-unknown-linux-gnu
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - name: Install cargo-zigbuild
        if: matrix.package_type == 'deb' || matrix.package_type == 'rpm'
        run: |
          pip install cargo-zigbuild
          echo "$HOME/.local/bin" >> $GITHUB_PATH

      - name: Setup Zig
        if: (matrix.package_type == 'deb' || matrix.package_type == 'rpm') && matrix.target != 'x86_64-unknown-linux-gnu'
        uses: mlugg/setup-zig@v1
        with:
          version: 0.13.0

      - name: Setup Rust
        if: matrix.package_type != 'arch'
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      # ── DEB Build ──
      - name: Build Debian Package
        if: matrix.package_type == 'deb'
        run: |
          cargo install cargo-deb
          if [ "${{ matrix.target }}" != "x86_64-unknown-linux-gnu" ]; then
            cargo zigbuild --release --features archive --target ${{ matrix.target }}
          else
            cargo build --release --features archive --target ${{ matrix.target }}
          fi
          cargo deb --no-build --target ${{ matrix.target }}
          mkdir -p dist-packages && cp target/${{ matrix.target }}/debian/*.deb dist-packages/

      # ── RPM Build ──
      - name: Build RPM Package
        if: matrix.package_type == 'rpm'
        run: |
          cargo install cargo-generate-rpm
          if [ "${{ matrix.target }}" != "x86_64-unknown-linux-gnu" ]; then
            cargo zigbuild --release --features archive --target ${{ matrix.target }}
          else
            cargo build --release --features archive --target ${{ matrix.target }}
          fi
          cargo generate-rpm --target ${{ matrix.target }}
          mkdir -p dist-packages && cp target/${{ matrix.target }}/generate-rpm/*.rpm dist-packages/

      # ── Snap Build ──
      - name: Build Snap Package
        if: matrix.package_type == 'snap'
        run: |
          cargo build --release --features archive
          mkdir -p packaging/snap/dist/bin
          cp target/release/dcr packaging/snap/dist/bin/
          cp -r man packaging/snap/dist/man

      - name: Snapcraft Build Action
        if: matrix.package_type == 'snap'
        uses: snapcore/action-build@v1
        with:
          path: packaging/snap

      - name: Prepare Snap Output
        if: matrix.package_type == 'snap'
        run: mkdir -p dist-packages && cp packaging/snap/*.snap dist-packages/

      # ── Arch Linux Native Build ──
      - name: Build Arch Package inside Container
        if: matrix.package_type == 'arch'
        run: |
          PKGVER_ORIG='${{ needs.setup.outputs.version }}'
          PKGVER_CLEAN="${PKGVER_ORIG//-/.}"
          TAG='${{ needs.setup.outputs.tag }}'
          SRC_URL="https://github.com/dexoron/dcr/archive/refs/tags/${TAG}.tar.gz"
          SHA256="$(curl -fsSL "$SRC_URL" | sha256sum | awk '{print $1}')"
          mkdir -p arch-build
          cat > arch-build/PKGBUILD <<PKG
          pkgname=dcr
          pkgver=${PKGVER_CLEAN}
          pkgrel=1
          pkgdesc="Cargo-like utility to manage C/C++ projects"
          arch=('x86_64')
          url="https://github.com/dexoron/dcr"
          license=('GPL-3.0-or-later')
          depends=('gcc-libs')
          makedepends=('cargo')
          options=('!lto')
          source=("\$pkgname-\$pkgver.tar.gz::\$url/archive/refs/tags/${TAG}.tar.gz")
          sha256sums=('${SHA256}')
          build() {
            cd "\$srcdir/\$pkgname-${PKGVER_ORIG}"
            unset CFLAGS CXXFLAGS LDFLAGS
            export RUSTFLAGS="-C linker=cc"
            cargo build --release --locked --features archive
          }
          package() {
            cd "\$srcdir/dcr-${PKGVER_ORIG}"
            install -Dm755 "target/release/dcr" "\$pkgdir/usr/bin/dcr"
            install -Dm644 LICENSE "\$pkgdir/usr/share/licenses/\$pkgname/LICENSE"
            for manpage in man/man1/*.1; do
              install -Dm644 "\$manpage" "\$pkgdir/usr/share/man/man1/\$(basename "\$manpage")"
            done
          }
          PKG
          docker run --rm \
            -v ${{ github.workspace }}/arch-build:/build \
            archlinux:latest \
            bash -c "
              pacman -Syu --noconfirm base-devel cargo gcc-libs git && \
              useradd -m builduser && \
              echo 'builduser ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \
              chown -R builduser:builduser /build && \
              cd /build && \
              su builduser -c 'makepkg -s --noconfirm'
            "
          mkdir -p dist-packages && cp arch-build/*.pkg.tar.zst dist-packages/

      # ── Upload Artifacts ──
      - name: Upload Package Artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.package_type }}-package-${{ matrix.target }}
          path: dist-packages/*
          if-no-files-found: ignore

  # ── Publish Packages to Release (Out of Matrix) ────────────────────────────
  publish-dexoron-packages:
    needs: [setup, notes, build-linux-packages, create-release]
    runs-on: ubuntu-latest
    steps:
      - name: Download Release Notes
        uses: actions/download-artifact@v4
        with:
          name: release-notes
          path: .github

      - name: Download Built Packages
        uses: actions/download-artifact@v4
        with:
          path: collected-packages

      - name: Upload Everything to GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.setup.outputs.tag }}
          files: |
            collected-packages/deb-package-*/*
            collected-packages/rpm-package-*/*
            collected-packages/arch-package-*/*
            collected-packages/snap-package-*/*
          body_path: .github/release-notes.md
          prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}

  # ── macOS Matrix ───────────────────────────────────────────────────────────
  build-macos:
    if: ${{ github.event_name == 'push' || github.event.inputs.run_macos == 'true' }}
    needs: [setup, notes, create-release]
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: macos-15-intel
            target: x86_64-apple-darwin
          - os: macos-latest
            target: aarch64-apple-darwin
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - name: Download Release Notes
        uses: actions/download-artifact@v4
        with:
          name: release-notes
          path: .github

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build
        run: cargo build --release --features archive --target ${{ matrix.target }}

      - name: Prepare Artifact
        run: |
          ASSET="dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}"
          cp target/${{ matrix.target }}/release/dcr "$ASSET"
          echo "ASSET_NAME=${ASSET}" >> "$GITHUB_ENV"

      - name: Upload Release Asset
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.setup.outputs.tag }}
          files: ${{ env.ASSET_NAME }}
          body_path: .github/release-notes.md
          prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}

  # ── BSD Systems Matrix ─────────────────────────────────────────────────────
  build-bsd:
    if: ${{ github.event_name == 'push' || github.event.inputs.run_bsd == 'true' }}
    needs: [setup, notes, create-release]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        system: [freebsd, openbsd, netbsd]
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - name: Download Release Notes
        uses: actions/download-artifact@v4
        with:
          name: release-notes
          path: .github

      # --- FREEBSD ---
      - name: Build in FreeBSD VM
        if: matrix.system == 'freebsd'
        uses: vmactions/freebsd-vm@v1
        with:
          usesh: true
          run: |
            export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
            pkg install -y rust perl5 gmake
            cargo build --release --features archive

      - name: Prepare FreeBSD Artifact
        if: matrix.system == 'freebsd'
        run: |
          ASSET="dcr-x86_64-unknown-freebsd-${{ needs.setup.outputs.version }}"
          cp target/release/dcr "$ASSET"
          echo "BSD_ASSET=${ASSET}" >> "$GITHUB_ENV"

      # --- OPENBSD ---
      - name: Build in OpenBSD VM
        if: matrix.system == 'openbsd'
        uses: vmactions/openbsd-vm@v1
        with:
          usesh: true
          run: |
            export PATH="/usr/local/bin:$PATH"
            pkg_add rust perl gmake
            cargo build --release --features archive

      - name: Prepare OpenBSD Artifact
        if: matrix.system == 'openbsd'
        run: |
          ASSET="dcr-x86_64-unknown-openbsd-${{ needs.setup.outputs.version }}"
          cp target/release/dcr "$ASSET"
          echo "BSD_ASSET=${ASSET}" >> "$GITHUB_ENV"

      # --- NETBSD ---
      - name: Build in NetBSD VM
        if: matrix.system == 'netbsd'
        uses: vmactions/netbsd-vm@v1
        with:
          usesh: true
          run: |
            pkg_add rust perl gmake
            mkdir -p /tmp/bin
            ln -sf /usr/pkg/bin/gmake /tmp/bin/make
            export PATH="/tmp/bin:/usr/pkg/bin:/usr/pkg/sbin:$PATH"
            cargo build --release --features archive

      - name: Prepare NetBSD Artifact
        if: matrix.system == 'netbsd'
        run: |
          ASSET="dcr-x86_64-unknown-netbsd-${{ needs.setup.outputs.version }}"
          cp target/release/dcr "$ASSET"
          echo "BSD_ASSET=${ASSET}" >> "$GITHUB_ENV"

      # --- UPLOAD TARGET ---
      - name: Upload BSD Asset to Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.setup.outputs.tag }}
          files: ${{ env.BSD_ASSET }}
          body_path: .github/release-notes.md
          prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}

  # ── Windows Matrix ─────────────────────────────────────────────────────────
  build-windows:
    if: ${{ github.event_name == 'push' || github.event.inputs.run_windows == 'true' }}
    needs: [setup, notes, create-release]
    runs-on: windows-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-pc-windows-msvc
          - target: aarch64-pc-windows-msvc
          - target: i686-pc-windows-msvc
          - target: x86_64-pc-windows-gnu
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - name: Download Release Notes
        uses: actions/download-artifact@v4
        with:
          name: release-notes
          path: .github

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build
        run: cargo build --release --features archive --target ${{ matrix.target }}

      - name: Prepare Artifact
        shell: pwsh
        run: |
          $asset = "dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}.exe"
          Copy-Item "target/${{ matrix.target }}/release/dcr.exe" "$asset"
          "ASSET_NAME=$asset" >> $env:GITHUB_ENV

      - name: Upload Release Asset
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.setup.outputs.tag }}
          files: ${{ env.ASSET_NAME }}
          body_path: .github/release-notes.md
          prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}
 
  # ── Arch User Repository (dcr) ───────────────────────────────────
  publish-aur:
    if: ${{ (github.event_name == 'push' && needs.setup.outputs.prerelease == 'false') || github.event.inputs.run_aur == 'true' }}
    needs: [setup]
    runs-on: ubuntu-latest
    environment: aur
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Derive checksum
        id: meta
        shell: bash
        run: |
          set -euo pipefail
          SRC_URL="https://github.com/dexoron/dcr/archive/refs/tags/${{ needs.setup.outputs.tag }}.tar.gz"
          SHA256="$(curl -fsSL "$SRC_URL" | sha256sum | awk '{print $1}')"
          echo "source_url=$SRC_URL" >> "$GITHUB_OUTPUT"
          echo "sha256=$SHA256" >> "$GITHUB_OUTPUT"

      - name: Render AUR metadata
        shell: bash
        run: |
          set -euo pipefail
          PKGVER_ORIG='${{ needs.setup.outputs.version }}'
          PKGVER_CLEAN="${PKGVER_ORIG//-/.}"
          SRC_URL='${{ steps.meta.outputs.source_url }}'
          SHA256='${{ steps.meta.outputs.sha256 }}'

          mkdir -p packages/aur/dcr
          cat > packages/aur/dcr/PKGBUILD <<PKG
          pkgname=dcr
          pkgver=${PKGVER_CLEAN}
          pkgrel=1
          pkgdesc="Cargo-like utility to manage C/C++ projects"
          arch=('x86_64' 'aarch64')
          url="https://github.com/dexoron/dcr"
          license=('GPL-3.0-or-later')
          depends=('gcc-libs')
          makedepends=('cargo')
          options=('!lto')
          optdepends=(
            'gcc: build C/C++ projects with GCC'
            'clang: build C/C++ projects with Clang'
          )
          source=("\$pkgname-\$pkgver.tar.gz::${SRC_URL}")
          sha256sums=('${SHA256}')

          build() {
            cd "\$srcdir/\$pkgname-${PKGVER_ORIG}"
            unset CFLAGS CXXFLAGS LDFLAGS
            export RUSTFLAGS="-C linker=cc"
            cargo build --release --locked --features archive
          }

          package() {
            cd "\$srcdir/\$pkgname-${PKGVER_ORIG}"
            install -Dm755 "target/release/dcr" "\$pkgdir/usr/bin/dcr"
            install -Dm644 LICENSE "\$pkgdir/usr/share/licenses/\$pkgname/LICENSE"
            for manpage in man/man1/*.1; do
              install -Dm644 "\$manpage" "\$pkgdir/usr/share/man/man1/\$(basename "\$manpage")"
            done
          }
          PKG

          cat > packages/aur/dcr/.SRCINFO <<SRC
          pkgbase = dcr
            pkgdesc = Cargo-like utility to manage C/C++ projects
            pkgver = ${PKGVER_CLEAN}
            pkgrel = 1
            url = https://github.com/dexoron/dcr
            arch = x86_64
            arch = aarch64
            license = GPL-3.0-or-later
            makedepends = cargo
            depends = gcc-libs
            optdepends = gcc: build C/C++ projects with GCC
            optdepends = clang: build C/C++ projects with Clang
            options = !lto
            source = dcr-${PKGVER_CLEAN}.tar.gz::${SRC_URL}
            sha256sums = ${SHA256}

          pkgname = dcr
          SRC

      - name: Push to AUR
        env:
          AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
          AUR_PACKAGE: dcr
        shell: bash
        run: |
          set -euo pipefail
          install -d -m 700 ~/.ssh
          printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > ~/.ssh/aur
          chmod 600 ~/.ssh/aur
          ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts

          export GIT_SSH_COMMAND='ssh -i ~/.ssh/aur -o IdentitiesOnly=yes'
          
          mkdir -p aur-repo
          cd aur-repo
          git init
          git remote add origin "ssh://aur@aur.archlinux.org/${AUR_PACKAGE}.git"
          
          git fetch origin master || true
          git checkout master || git checkout -b master
          
          cp ../packages/aur/dcr/PKGBUILD .
          cp ../packages/aur/dcr/.SRCINFO .

          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

          if git rev-parse --verify HEAD >/dev/null 2>&1; then
            if git diff --quiet; then
              echo "No AUR changes"
              exit 0
            fi
          fi

          git add PKGBUILD .SRCINFO
          git commit -m "dcr ${{ needs.setup.outputs.version }}"
          git push -u origin master

  # ── Arch User Repository (dcr-bin) ────────────────────────────────
  publish-aur-bin:
    if: ${{ (github.event_name == 'push' && needs.setup.outputs.prerelease == 'false') || github.event.inputs.run_aur == 'true' }}
    needs: [setup, build-linux]
    runs-on: ubuntu-latest
    environment: aur
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Derive checksum
        id: meta
        shell: bash
        run: |
          set -euo pipefail
          TAG="${{ needs.setup.outputs.tag }}"
          VER="${{ needs.setup.outputs.version }}"
          BASE_URL="https://github.com/dexoron/dcr/releases/download/${TAG}"
          for arch in x86_64 aarch64 i686 armv7h riscv64; do
            case "$arch" in
              x86_64)  triple="x86_64-unknown-linux-musl" ;;
              aarch64) triple="aarch64-unknown-linux-musl" ;;
              i686)    triple="i686-unknown-linux-musl" ;;
              armv7h)  triple="armv7-unknown-linux-musleabihf" ;;
              riscv64) triple="riscv64gc-unknown-linux-musl" ;;
            esac
            url="${BASE_URL}/dcr-${triple}-${VER}"
            sha256="$(curl -fsSL "$url" | sha256sum | awk '{print $1}')"
            echo "${arch}_url=${url}" >> "$GITHUB_OUTPUT"
            echo "${arch}_sha256=${sha256}" >> "$GITHUB_OUTPUT"
          done

      - name: Render AUR Metadata
        shell: bash
        run: |
          set -euo pipefail
          PKGVER_ORIG='${{ needs.setup.outputs.version }}'
          PKGVER_CLEAN="${PKGVER_ORIG//-/.}"
          mkdir -p packages/aur/dcr-bin
          cat > packages/aur/dcr-bin/PKGBUILD <<PKG
          pkgname=dcr-bin
          pkgver=${PKGVER_CLEAN}
          pkgrel=1
          pkgdesc="Cargo-like utility to manage C/C++ projects (pre-compiled musl binary)"
          arch=('x86_64' 'aarch64' 'i686' 'armv7h' 'riscv64')
          url="https://github.com/dexoron/dcr"
          license=('GPL-3.0-or-later')
          provides=('dcr')
          conflicts=('dcr')
          optdepends=(
            'gcc: build C/C++ projects with GCC'
            'clang: build C/C++ projects with Clang'
          )
          source_x86_64=("dcr-\$pkgver::${{ steps.meta.outputs.x86_64_url }}")
          sha256sums_x86_64=('${{ steps.meta.outputs.x86_64_sha256 }}')
          source_aarch64=("dcr-\$pkgver::${{ steps.meta.outputs.aarch64_url }}")
          sha256sums_aarch64=('${{ steps.meta.outputs.aarch64_sha256 }}')
          source_i686=("dcr-\$pkgver::${{ steps.meta.outputs.i686_url }}")
          sha256sums_i686=('${{ steps.meta.outputs.i686_sha256 }}')
          source_armv7h=("dcr-\$pkgver::${{ steps.meta.outputs.armv7h_url }}")
          sha256sums_armv7h=('${{ steps.meta.outputs.armv7h_sha256 }}')
          source_riscv64=("dcr-\$pkgver::${{ steps.meta.outputs.riscv64_url }}")
          sha256sums_riscv64=('${{ steps.meta.outputs.riscv64_sha256 }}')

          package() {
            install -Dm755 "\$srcdir/dcr-\$pkgver" "\$pkgdir/usr/bin/dcr"
          }
          PKG

          cat > packages/aur/dcr-bin/.SRCINFO <<SRC
          pkgbase = dcr-bin
            pkgdesc = Cargo-like utility to manage C/C++ projects (pre-compiled musl binary)
            pkgver = ${PKGVER_CLEAN}
            pkgrel = 1
            url = https://github.com/dexoron/dcr
            arch = x86_64
            arch = aarch64
            arch = i686
            arch = armv7h
            arch = riscv64
            license = GPL-3.0-or-later
            provides = dcr
            conflicts = dcr
            optdepends = gcc: build C/C++ projects with GCC
            optdepends = clang: build C/C++ projects with Clang
            source_x86_64 = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.x86_64_url }}
            sha256sums_x86_64 = ${{ steps.meta.outputs.x86_64_sha256 }}
            source_aarch64 = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.aarch64_url }}
            sha256sums_aarch64 = ${{ steps.meta.outputs.aarch64_sha256 }}
            source_i686 = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.i686_url }}
            sha256sums_i686 = ${{ steps.meta.outputs.i686_sha256 }}
            source_armv7h = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.armv7h_url }}
            sha256sums_armv7h = ${{ steps.meta.outputs.armv7h_sha256 }}
            source_riscv64 = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.riscv64_url }}
            sha256sums_riscv64 = ${{ steps.meta.outputs.riscv64_sha256 }}

          pkgname = dcr-bin
          SRC

      - name: Push to AUR
        env:
          AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
          AUR_PACKAGE: dcr-bin
        shell: bash
        run: |
          set -euo pipefail
          install -d -m 700 ~/.ssh
          printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > ~/.ssh/aur
          chmod 600 ~/.ssh/aur
          ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts

          export GIT_SSH_COMMAND='ssh -i ~/.ssh/aur -o IdentitiesOnly=yes'
          
          mkdir -p aur-repo
          cd aur-repo
          git init
          git remote add origin "ssh://aur@aur.archlinux.org/${AUR_PACKAGE}.git"
          
          git fetch origin master || true
          git checkout master || git checkout -b master
          
          cp ../packages/aur/dcr-bin/PKGBUILD .
          cp ../packages/aur/dcr-bin/.SRCINFO .

          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

          if git rev-parse --verify HEAD >/dev/null 2>&1; then
            if git diff --quiet; then
              echo "No AUR changes"
              exit 0
            fi
          fi

          git add PKGBUILD .SRCINFO
          git commit -m "dcr-bin ${{ needs.setup.outputs.version }}"
          git push -u origin master


  # ── Arch User Repository (dcr-dev) ────────────────────────────────
  publish-aur-dev:
    if: ${{ (github.event_name == 'push' && needs.setup.outputs.prerelease == 'true') || github.event.inputs.run_aur_dev == 'true' }}
    needs: [setup]
    runs-on: ubuntu-latest
    environment: aur
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Derive checksum
        id: meta
        shell: bash
        run: |
          set -euo pipefail
          SRC_URL="https://github.com/dexoron/dcr/archive/refs/tags/${{ needs.setup.outputs.tag }}.tar.gz"
          SHA256="$(curl -fsSL "$SRC_URL" | sha256sum | awk '{print $1}')"
          echo "source_url=$SRC_URL" >> "$GITHUB_OUTPUT"
          echo "sha256=$SHA256" >> "$GITHUB_OUTPUT"

      - name: Render AUR metadata
        shell: bash
        run: |
          set -euo pipefail
          PKGVER_ORIG='${{ needs.setup.outputs.version }}'
          PKGVER_CLEAN='${{ needs.setup.outputs.clean_version }}'
          SRC_URL='${{ steps.meta.outputs.source_url }}'
          SHA256='${{ steps.meta.outputs.sha256 }}'

          mkdir -p packages/aur/dcr-dev
          cat > packages/aur/dcr-dev/PKGBUILD <<PKG
          pkgname=dcr-dev
          pkgver=${PKGVER_CLEAN}
          pkgrel=1
          pkgdesc="Cargo-like utility to manage C/C++ projects (development release)"
          arch=('x86_64' 'aarch64')
          url="https://github.com/dexoron/dcr"
          license=('GPL-3.0-or-later')
          depends=('gcc-libs')
          makedepends=('cargo')
          options=('!lto')
          provides=('dcr')
          conflicts=('dcr')
          optdepends=(
            'gcc: build C/C++ projects with GCC'
            'clang: build C/C++ projects with Clang'
          )
          source=("\$pkgname-\$pkgver.tar.gz::${SRC_URL}")
          sha256sums=('${SHA256}')

          build() {
            cd "\$srcdir/dcr-${PKGVER_ORIG}"
            unset CFLAGS CXXFLAGS LDFLAGS
            export RUSTFLAGS="-C linker=cc"
            cargo build --release --locked --features archive
          }

          package() {
            cd "\$srcdir/\$pkgname-${PKGVER_ORIG}"
            install -Dm755 "target/release/dcr" "\$pkgdir/usr/bin/dcr"
            install -Dm644 LICENSE "\$pkgdir/usr/share/licenses/\$pkgname/LICENSE"
            for manpage in man/man1/*.1; do
              install -Dm644 "\$manpage" "\$pkgdir/usr/share/man/man1/\$(basename "\$manpage")"
            done
          }
          PKG

          cat > packages/aur/dcr-dev/.SRCINFO <<SRC
          pkgbase = dcr-dev
            pkgdesc = Cargo-like utility to manage C/C++ projects (development release)
            pkgver = ${PKGVER_CLEAN}
            pkgrel = 1
            url = https://github.com/dexoron/dcr
            arch = x86_64
            arch = aarch64
            license = GPL-3.0-or-later
            makedepends = cargo
            depends = gcc-libs
            provides = dcr
            conflicts = dcr
            optdepends = gcc: build C/C++ projects with GCC
            optdepends = clang: build C/C++ projects with Clang
            options = !lto
            source = dcr-${PKGVER_CLEAN}.tar.gz::${SRC_URL}
            sha256sums = ${SHA256}

          pkgname = dcr-dev
          SRC

      - name: Push to AUR
        env:
          AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
          AUR_PACKAGE: dcr-dev
        shell: bash
        run: |
          set -euo pipefail
          install -d -m 700 ~/.ssh
          printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > ~/.ssh/aur
          chmod 600 ~/.ssh/aur
          ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts

          export GIT_SSH_COMMAND='ssh -i ~/.ssh/aur -o IdentitiesOnly=yes'
          
          mkdir -p aur-repo
          cd aur-repo
          git init
          git remote add origin "ssh://aur@aur.archlinux.org/${AUR_PACKAGE}.git"
          
          git fetch origin master || true
          git checkout master || git checkout -b master
          
          cp ../packages/aur/dcr-dev/PKGBUILD .
          cp ../packages/aur/dcr-dev/.SRCINFO .

          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

          if git rev-parse --verify HEAD >/dev/null 2>&1; then
            if git diff --quiet; then
              echo "No AUR changes"
              exit 0
            fi
          fi

          git add PKGBUILD .SRCINFO
          git commit -m "dcr-dev ${{ needs.setup.outputs.version }}"
          git push -u origin master

  # ── Arch User Repository (dcr-dev-bin) ────────────────────────────
  publish-aur-dev-bin:
    if: ${{ (github.event_name == 'push' && needs.setup.outputs.prerelease == 'true') || github.event.inputs.run_aur_dev == 'true' }}
    needs: [setup, build-linux]
    runs-on: ubuntu-latest
    environment: aur
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Derive checksum
        id: meta
        shell: bash
        run: |
          set -euo pipefail
          TAG="${{ needs.setup.outputs.tag }}"
          VER="${{ needs.setup.outputs.version }}"
          BASE_URL="https://github.com/dexoron/dcr/releases/download/${TAG}"
          for arch in x86_64 aarch64 i686 armv7h riscv64; do
            case "$arch" in
              x86_64)  triple="x86_64-unknown-linux-musl" ;;
              aarch64) triple="aarch64-unknown-linux-musl" ;;
              i686)    triple="i686-unknown-linux-musl" ;;
              armv7h)  triple="armv7-unknown-linux-musleabihf" ;;
              riscv64) triple="riscv64gc-unknown-linux-musl" ;;
            esac
            url="${BASE_URL}/dcr-${triple}-${VER}"
            sha256="$(curl -fsSL "$url" | sha256sum | awk '{print $1}')"
            echo "${arch}_url=${url}" >> "$GITHUB_OUTPUT"
            echo "${arch}_sha256=${sha256}" >> "$GITHUB_OUTPUT"
          done

      - name: Render AUR Metadata
        shell: bash
        run: |
          set -euo pipefail
          PKGVER_ORIG='${{ needs.setup.outputs.version }}'
          PKGVER_CLEAN='${{ needs.setup.outputs.clean_version }}'
          mkdir -p packages/aur/dcr-dev-bin
          cat > packages/aur/dcr-dev-bin/PKGBUILD <<PKG
          pkgname=dcr-dev-bin
          pkgver=${PKGVER_CLEAN}
          pkgrel=1
          pkgdesc="Cargo-like utility to manage C/C++ projects (pre-compiled musl binary dev release)"
          arch=('x86_64' 'aarch64' 'i686' 'armv7h' 'riscv64')
          url="https://github.com/dexoron/dcr"
          license=('GPL-3.0-or-later')
          provides=('dcr')
          conflicts=('dcr')
          optdepends=(
            'gcc: build C/C++ projects with GCC'
            'clang: build C/C++ projects with Clang'
          )
          source_x86_64=("dcr-\$pkgver::${{ steps.meta.outputs.x86_64_url }}")
          sha256sums_x86_64=('${{ steps.meta.outputs.x86_64_sha256 }}')
          source_aarch64=("dcr-\$pkgver::${{ steps.meta.outputs.aarch64_url }}")
          sha256sums_aarch64=('${{ steps.meta.outputs.aarch64_sha256 }}')
          source_i686=("dcr-\$pkgver::${{ steps.meta.outputs.i686_url }}")
          sha256sums_i686=('${{ steps.meta.outputs.i686_sha256 }}')
          source_armv7h=("dcr-\$pkgver::${{ steps.meta.outputs.armv7h_url }}")
          sha256sums_armv7h=('${{ steps.meta.outputs.armv7h_sha256 }}')
          source_riscv64=("dcr-\$pkgver::${{ steps.meta.outputs.riscv64_url }}")
          sha256sums_riscv64=('${{ steps.meta.outputs.riscv64_sha256 }}')

          package() {
            install -Dm755 "\$srcdir/dcr-\$pkgver" "\$pkgdir/usr/bin/dcr"
          }
          PKG

          cat > packages/aur/dcr-dev-bin/.SRCINFO <<SRC
          pkgbase = dcr-dev-bin
            pkgdesc = Cargo-like utility to manage C/C++ projects (pre-compiled musl binary dev release)
            pkgver = ${PKGVER_CLEAN}
            pkgrel = 1
            url = https://github.com/dexoron/dcr
            arch = x86_64
            arch = aarch64
            arch = i686
            arch = armv7h
            arch = riscv64
            license = GPL-3.0-or-later
            provides = dcr
            conflicts = dcr
            optdepends = gcc: build C/C++ projects with GCC
            optdepends = clang: build C/C++ projects with Clang
            source_x86_64 = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.x86_64_url }}
            sha256sums_x86_64 = ${{ steps.meta.outputs.x86_64_sha256 }}
            source_aarch64 = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.aarch64_url }}
            sha256sums_aarch64 = ${{ steps.meta.outputs.aarch64_sha256 }}
            source_i686 = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.i686_url }}
            sha256sums_i686 = ${{ steps.meta.outputs.i686_sha256 }}
            source_armv7h = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.armv7h_url }}
            sha256sums_armv7h = ${{ steps.meta.outputs.armv7h_sha256 }}
            source_riscv64 = dcr-${PKGVER_CLEAN}::${{ steps.meta.outputs.riscv64_url }}
            sha256sums_riscv64 = ${{ steps.meta.outputs.riscv64_sha256 }}

          pkgname = dcr-dev-bin
          SRC

      - name: Push to AUR
        env:
          AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
          AUR_PACKAGE: dcr-dev-bin
        shell: bash
        run: |
          set -euo pipefail
          install -d -m 700 ~/.ssh
          printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > ~/.ssh/aur
          chmod 600 ~/.ssh/aur
          ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts

          export GIT_SSH_COMMAND='ssh -i ~/.ssh/aur -o IdentitiesOnly=yes'
          
          mkdir -p aur-repo
          cd aur-repo
          git init
          git remote add origin "ssh://aur@aur.archlinux.org/${AUR_PACKAGE}.git"
          
          git fetch origin master || true
          git checkout master || git checkout -b master
          
          cp ../packages/aur/dcr-dev-bin/PKGBUILD .
          cp ../packages/aur/dcr-dev-bin/.SRCINFO .

          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

          if git rev-parse --verify HEAD >/dev/null 2>&1; then
            if git diff --quiet; then
              echo "No AUR changes"
              exit 0
            fi
          fi

          git add PKGBUILD .SRCINFO
          git commit -m "dcr-dev-bin ${{ needs.setup.outputs.version }}"
          git push -u origin master


  # ── crates.io ──────────────────────────────────────────────────────────────
  publish-crates:
    if: |
      (github.event_name == 'push' && needs.setup.outputs.prerelease == 'false') ||
      (github.event_name == 'workflow_dispatch' && github.event.inputs.run_publish == 'true')
    needs: [setup, build-linux, build-macos, build-windows, build-bsd]
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - uses: dtolnay/rust-toolchain@stable

      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish

  # ── Homebrew tap ───────────────────────────────────────────────────────────
  publish-brew:
    if: |
      (github.event_name == 'push' && needs.setup.outputs.prerelease == 'false') ||
      (github.event_name == 'workflow_dispatch' && github.event.inputs.run_brew == 'true')
    needs: [setup, build-linux, build-macos]
    runs-on: ubuntu-latest
    steps:
      - name: Download release assets and compute sha256
        id: sha
        run: |
          VERSION="${{ needs.setup.outputs.version }}"
          BASE="https://github.com/dexoron/dcr/releases/download/v${VERSION}"

          download_sha() {
            curl -fsSL "${BASE}/$1" | sha256sum | awk '{print $1}'
          }

          echo "linux_x86=$(download_sha "dcr-x86_64-unknown-linux-gnu-${VERSION}")"     >> "$GITHUB_OUTPUT"
          echo "linux_arm=$(download_sha "dcr-aarch64-unknown-linux-gnu-${VERSION}")"    >> "$GITHUB_OUTPUT"
          echo "macos_x86=$(download_sha "dcr-x86_64-apple-darwin-${VERSION}")"          >> "$GITHUB_OUTPUT"
          echo "macos_arm=$(download_sha "dcr-aarch64-apple-darwin-${VERSION}")"         >> "$GITHUB_OUTPUT"
          echo "man_pages=$(download_sha "dcr-man-pages-${VERSION}.tar.gz")"             >> "$GITHUB_OUTPUT"

      - name: Checkout homebrew-dexoron
        uses: actions/checkout@v4
        with:
          repository: dexoron/homebrew-dexoron
          token: ${{ secrets.HOMEBREW_TAP_TOKEN }}

      - name: Update Formula/dcr.rb
        run: |
          VERSION="${{ needs.setup.outputs.version }}"
          cat > Formula/dcr.rb <<FORMULA
          class Dcr < Formula
            desc "Cargo-like utility to manage C/C++ projects"
            homepage "https://dcr.dexoron.su"
            version "${VERSION}"

            on_macos do
              on_intel do
                url "https://github.com/dexoron/dcr/releases/download/v#{version}/dcr-x86_64-apple-darwin-#{version}"
                sha256 "${{ steps.sha.outputs.macos_x86 }}"
              end
              on_arm do
                url "https://github.com/dexoron/dcr/releases/download/v#{version}/dcr-aarch64-apple-darwin-#{version}"
                sha256 "${{ steps.sha.outputs.macos_arm }}"
              end
            end

            on_linux do
              on_intel do
                url "https://github.com/dexoron/dcr/releases/download/v#{version}/dcr-x86_64-unknown-linux-gnu-#{version}"
                sha256 "${{ steps.sha.outputs.linux_x86 }}"
              end
              on_arm do
                url "https://github.com/dexoron/dcr/releases/download/v#{version}/dcr-aarch64-unknown-linux-gnu-#{version}"
                sha256 "${{ steps.sha.outputs.linux_arm }}"
              end
            end

            def install
              bin.install Dir["dcr*"].first => "dcr"
            end

            resource "man-pages" do
              url "https://github.com/dexoron/dcr/releases/download/v#{version}/dcr-man-pages-#{version}.tar.gz"
              sha256 "${{ steps.sha.outputs.man_pages }}"
            end

            def install
              bin.install Dir["dcr*"].first => "dcr"
              resource("man-pages").stage do
                man1.install Dir["usr/share/man/man1/*.1"]
              end
            end

            test do
              system "#{bin}/dcr", "--version"
            end
          end
          FORMULA

      - name: Commit and push
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Formula/dcr.rb
          git diff --staged --quiet && echo "No changes" && exit 0
          git commit -m "dcr ${{ needs.setup.outputs.version }}"
          git push
  
  # ── Snap Store (dcrup) — temporarily disabled ────────────────────────────
  # Classic confinement was denied for this project (too new).
  # Snap artifact is still built and attached to the release via
  # publish-dexoron-packages. Users can install manually:
  #   sudo snap install --classic --dangerous dcrup_*.snap
  #
  # publish-snap:
  #   if: ...