dcr 0.7.0

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
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_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_snap:
        description: "Publish to Snap Store (dcrup)"
        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 }}
      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}"
          [[ "$TAG" == *"-"* ]] && PRERELEASE="true" || PRERELEASE="false"
          echo "value=${TAG}"             >> "$GITHUB_OUTPUT"
          echo "version=${VERSION}"       >> "$GITHUB_OUTPUT"
          echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"

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

      - name: Prepare Release Notes
        shell: bash
        run: |
          set -euo pipefail
          tag="${{ needs.setup.outputs.version }}"
          notes_file=".github/release-notes.md"
          if grep -q "^## \\[${tag}\\]" CHANGELOG.md; then
            awk -v ver="$tag" '
              $0 ~ "^## \\[" ver "\\]" {found=1; next}
              found && $0 ~ "^## \\[" {exit}
              found {print}
            ' CHANGELOG.md | sed -e '${/^$/d;}' > "$notes_file"
          else
            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 }}
          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
    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 --target ${{ matrix.target }}
          else
            cargo build --release --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:
        include:
          - package_type: deb
            artifact_name: debian-package
          - package_type: rpm
            artifact_name: rpm-package
          - package_type: arch
            artifact_name: arch-package
          - package_type: snap
            artifact_name: snap-package
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.setup.outputs.tag }}

      - name: Setup Rust (For non-container builds)
        if: matrix.package_type != 'arch'
        uses: dtolnay/rust-toolchain@stable

      # ── DEB Build ──
      - name: Build Debian Package
        if: matrix.package_type == 'deb'
        run: |
          cargo install cargo-deb
          cargo build --release
          cargo deb --no-build
          mkdir -p dist-packages && cp target/debian/*.deb dist-packages/

      # ── RPM Build ──
      - name: Build RPM Package
        if: matrix.package_type == 'rpm'
        run: |
          cargo install cargo-generate-rpm
          cargo build --release
          cargo generate-rpm
          mkdir -p dist-packages && cp target/generate-rpm/*.rpm dist-packages/

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

      - 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}"
            cargo build --release --locked
          }
          package() {
            cd "\$srcdir/\$pkgname-${PKGVER_ORIG}"
            install -Dm755 "target/release/dcr" "\$pkgdir/usr/bin/dcr"
            install -Dm644 LICENSE "\$pkgdir/usr/share/licenses/\$pkgname/LICENSE"
          }
          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.artifact_name }}
          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/debian-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 --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

      - 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

      - 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

      - 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: 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 --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}"
            export CARGO_PROFILE_RELEASE_LTO=false
            export RUSTFLAGS="\${RUSTFLAGS:-}"
            export RUSTFLAGS="\${RUSTFLAGS/-C link-arg=-fuse-ld=lld/}"
            cargo build --release --locked
          }

          package() {
            cd "\$srcdir/\$pkgname-${PKGVER_ORIG}"
            install -Dm755 "target/release/dcr" "\$pkgdir/usr/bin/dcr"
            install -Dm644 LICENSE "\$pkgdir/usr/share/licenses/\$pkgname/LICENSE"
          }
          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'
          git clone "ssh://aur@aur.archlinux.org/${AUR_PACKAGE}.git" aur-repo
          cp packages/aur/dcr/PKGBUILD aur-repo/PKGBUILD
          cp packages/aur/dcr/.SRCINFO aur-repo/.SRCINFO

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

          if git diff --quiet; then
            echo "No AUR changes"
            exit 0
          fi

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

  # ── 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
          BIN_URL="https://github.com/dexoron/dcr/releases/download/${{ needs.setup.outputs.tag }}/dcr-x86_64-unknown-linux-musl-${{ needs.setup.outputs.version }}"
          SHA256="$(curl -fsSL "$BIN_URL" | sha256sum | awk '{print $1}')"
          echo "bin_url=$BIN_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//-/.}"
          BIN_URL='${{ steps.meta.outputs.bin_url }}'
          SHA256='${{ steps.meta.outputs.sha256 }}'

          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')
          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::${BIN_URL}")
          sha256sums_x86_64=('${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
            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}::${BIN_URL}
            sha256sums_x86_64 = ${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'
          git clone "ssh://aur@aur.archlinux.org/${AUR_PACKAGE}.git" aur-repo
          cp packages/aur/dcr-bin/PKGBUILD aur-repo/PKGBUILD
          cp packages/aur/dcr-bin/.SRCINFO aur-repo/.SRCINFO

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

          if git diff --quiet; then
            echo "No AUR changes"
            exit 0
          fi

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

  # ── 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
        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"

      - 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

            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) ─────────────────────────────────────────────────────
  publish-snap:
    if: |
      (github.event_name == 'push' && needs.setup.outputs.prerelease == 'false') ||
      (github.event_name == 'workflow_dispatch' && github.event.inputs.run_snap == 'true')
    needs: [setup, build-linux-packages]
    runs-on: ubuntu-latest
    steps:
      - name: Download Built Packages
        uses: actions/download-artifact@v4
        with:
          name: snap-package
          path: dist-packages

      - name: Publish to Snap Store
        uses: snapcore/action-publish@v1
        env:
          SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_STORE_LOGIN }}
        with:
          snap: dist-packages/*.snap
          release: stable