elio 1.3.0

Snappy, batteries-included terminal file manager with rich previews, inline images, bulk actions, and trash support.
Documentation
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
name: Release

on:
  push:
    tags:
      - "v*.*.*"

permissions:
  contents: read

concurrency:
  group: release-${{ github.ref }}
  cancel-in-progress: false

env:
  CARGO_TERM_COLOR: always

jobs:
  validate:
    name: Validate release metadata
    runs-on: ubuntu-latest
    outputs:
      crate_name: ${{ steps.meta.outputs.crate_name }}
      tag: ${{ steps.meta.outputs.tag }}
      version: ${{ steps.meta.outputs.version }}

    steps:
      - name: Checkout
        uses: actions/checkout@v5
        with:
          fetch-depth: 0

      - name: Read crate metadata and validate tag
        id: meta
        shell: bash
        run: |
          set -euo pipefail
          tag="${GITHUB_REF_NAME}"
          version="${tag#v}"
          crate_name="$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
          cargo_version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
          lock_version="$(
            awk -v crate_name="${crate_name}" '
              $0 == "[[package]]" { in_pkg = 0; next }
              $0 == "name = \"" crate_name "\"" { in_pkg = 1; next }
              in_pkg && $1 == "version" {
                gsub(/"/, "", $3)
                print $3
                exit
              }
            ' Cargo.lock
          )"

          if [[ -z "${crate_name}" || -z "${cargo_version}" || -z "${lock_version}" ]]; then
            echo "Could not read crate metadata from Cargo.toml" >&2
            exit 1
          fi

          if [[ "${cargo_version}" != "${lock_version}" ]]; then
            echo "Cargo.toml version ${cargo_version} does not match Cargo.lock version ${lock_version}" >&2
            exit 1
          fi

          if [[ "${version}" != "${cargo_version}" ]]; then
            echo "Tag ${tag} does not match Cargo.toml version ${cargo_version}" >&2
            exit 1
          fi

          {
            echo "crate_name=${crate_name}"
            echo "tag=${tag}"
            echo "version=${version}"
          } >> "$GITHUB_OUTPUT"

      - name: Verify tag points to mainline history
        shell: bash
        run: |
          set -euo pipefail
          git fetch --no-tags origin main

          if ! git merge-base --is-ancestor "${GITHUB_SHA}" "origin/main"; then
            echo "Tagged commit ${GITHUB_SHA} is not reachable from origin/main" >&2
            exit 1
          fi

      - name: Extract release notes from changelog
        shell: bash
        run: |
          set -euo pipefail
          version="${{ steps.meta.outputs.version }}"
          awk -v version="${version}" '
            $0 ~ "^## \\[" version "\\]" { in_section = 1; next }
            in_section && $0 ~ "^## \\[" { exit }
            in_section && $0 ~ "^\\[[^]]+\\]: " { exit }
            in_section { print }
          ' CHANGELOG.md > RELEASE_NOTES.md

          sed -i '/./,$!d' RELEASE_NOTES.md

          if ! grep -q '[^[:space:]]' RELEASE_NOTES.md; then
            echo "Failed to extract release notes for ${version} from CHANGELOG.md" >&2
            exit 1
          fi

      - name: Upload release notes
        uses: actions/upload-artifact@v6
        with:
          name: release-notes
          path: RELEASE_NOTES.md

      - name: Install preview test tooling
        run: |
          set -euxo pipefail
          sudo apt-get update
          sudo apt-get install -y \
            ffmpeg \
            genisoimage \
            imagemagick \
            libarchive-tools \
            poppler-utils \
            xz-utils

          if ! command -v 7z >/dev/null 2>&1; then
            if sudo apt-get install -y p7zip-full; then
              :
            else
              sudo apt-get install -y 7zip
              if command -v 7zz >/dev/null 2>&1 && ! command -v 7z >/dev/null 2>&1; then
                sudo ln -s "$(command -v 7zz)" /usr/local/bin/7z
              fi
            fi
          fi

      - name: Install Rust 1.93.0
        uses: dtolnay/rust-toolchain@1.93.0

      - name: Cache Rust build artifacts
        uses: Swatinem/rust-cache@v2

      - name: Run release gate tests
        run: cargo test --locked

  build-linux:
    name: Build release artifact (Linux)
    needs: validate
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Install Rust 1.93.0
        uses: dtolnay/rust-toolchain@1.93.0

      - name: Cache Rust build artifacts
        uses: Swatinem/rust-cache@v2

      - name: Build release binary
        run: cargo build --locked --release

      - name: Package Linux artifact
        shell: bash
        run: |
          set -euo pipefail
          version="${{ needs.validate.outputs.version }}"
          host_target="$(rustc -vV | sed -n 's/^host: //p')"
          bundle_dir="dist/elio-${version}-${host_target}"

          mkdir -p "${bundle_dir}"
          cp target/release/elio "${bundle_dir}/"
          cp README.md LICENSE-MIT "${bundle_dir}/"
          tar -C dist -czf "dist/elio-${version}-${host_target}.tar.gz" "$(basename "${bundle_dir}")"

      - name: Upload Linux artifact
        uses: actions/upload-artifact@v6
        with:
          name: release-asset-linux
          path: dist/*.tar.gz

  build-macos:
    name: Build release artifact (macOS)
    needs: validate
    runs-on: macos-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Install Rust 1.93.0
        uses: dtolnay/rust-toolchain@1.93.0

      - name: Cache Rust build artifacts
        uses: Swatinem/rust-cache@v2

      - name: Build release binary
        run: cargo build --locked --release

      - name: Package macOS artifact
        shell: bash
        run: |
          set -euo pipefail
          version="${{ needs.validate.outputs.version }}"
          host_target="$(rustc -vV | sed -n 's/^host: //p')"
          bundle_dir="dist/elio-${version}-${host_target}"

          mkdir -p "${bundle_dir}"
          cp target/release/elio "${bundle_dir}/"
          cp README.md LICENSE-MIT "${bundle_dir}/"
          tar -C dist -czf "dist/elio-${version}-${host_target}.tar.gz" "$(basename "${bundle_dir}")"

      - name: Upload macOS artifact
        uses: actions/upload-artifact@v6
        with:
          name: release-asset-macos
          path: dist/*.tar.gz

  build-windows:
    name: Build release artifact (Windows)
    needs: validate
    runs-on: windows-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Install Rust 1.93.0
        uses: dtolnay/rust-toolchain@1.93.0

      - name: Cache Rust build artifacts
        uses: Swatinem/rust-cache@v2

      - name: Build release binary
        run: cargo build --locked --release

      - name: Package Windows artifact
        shell: pwsh
        env:
          RELEASE_VERSION: ${{ needs.validate.outputs.version }}
        run: |
          $hostTarget = ((rustc -vV | Select-String '^host: ').ToString().Split(':')[1]).Trim()
          $bundleDir = "dist/elio-$env:RELEASE_VERSION-$hostTarget"

          New-Item -ItemType Directory -Path $bundleDir -Force | Out-Null
          Copy-Item "target/release/elio.exe" "$bundleDir/"
          Copy-Item "README.md" "$bundleDir/"
          Copy-Item "LICENSE-MIT" "$bundleDir/"
          Compress-Archive -Path $bundleDir -DestinationPath "dist/elio-$env:RELEASE_VERSION-$hostTarget.zip" -Force

      - name: Upload Windows artifact
        uses: actions/upload-artifact@v6
        with:
          name: release-asset-windows
          path: dist/*.zip

  github-release:
    name: Create GitHub release
    needs:
      - validate
      - build-linux
      - build-macos
      - build-windows
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Download release notes
        uses: actions/download-artifact@v7
        with:
          name: release-notes
          path: release-notes

      - name: Download release artifacts
        uses: actions/download-artifact@v7
        with:
          pattern: release-asset-*
          path: dist
          merge-multiple: true

      - name: Create or update GitHub release
        env:
          GH_TOKEN: ${{ github.token }}
        shell: bash
        run: |
          set -euo pipefail
          tag="${{ needs.validate.outputs.tag }}"

          if gh release view "${tag}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
            gh release edit "${tag}" \
              --repo "${GITHUB_REPOSITORY}" \
              --title "${tag}" \
              --notes-file release-notes/RELEASE_NOTES.md
          else
            gh release create "${tag}" \
              --repo "${GITHUB_REPOSITORY}" \
              --title "${tag}" \
              --notes-file release-notes/RELEASE_NOTES.md
          fi

          gh release upload "${tag}" dist/* --clobber --repo "${GITHUB_REPOSITORY}"

  publish-crates:
    name: Publish crate
    needs:
      - validate
      - github-release
    runs-on: ubuntu-latest
    environment: release
    permissions:
      contents: read
      id-token: write

    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Install Rust 1.93.0
        uses: dtolnay/rust-toolchain@1.93.0

      - name: Cache Rust build artifacts
        uses: Swatinem/rust-cache@v2

      - name: Check whether version exists on crates.io
        id: crates
        env:
          CRATE_NAME: ${{ needs.validate.outputs.crate_name }}
          VERSION: ${{ needs.validate.outputs.version }}
        shell: bash
        run: |
          set -euo pipefail
          python3 - <<'PY' >> "$GITHUB_OUTPUT"
          import json
          import os
          import sys
          import urllib.error
          import urllib.request

          crate_name = os.environ["CRATE_NAME"]
          version = os.environ["VERSION"]
          url = f"https://crates.io/api/v1/crates/{crate_name}"

          try:
              with urllib.request.urlopen(url) as response:
                  payload = json.load(response)
          except urllib.error.HTTPError as error:
              if error.code == 404:
                  print("published=false")
                  sys.exit(0)
              raise

          versions = {entry["num"] for entry in payload.get("versions", [])}
          if version in versions:
              print("published=true")
          else:
              print("published=false")
          PY

      - name: Authenticate with crates.io
        id: auth
        if: steps.crates.outputs.published != 'true'
        uses: rust-lang/crates-io-auth-action@v1.0.4

      - name: Publish to crates.io
        if: steps.crates.outputs.published != 'true'
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
        run: cargo publish --locked

      - name: Skip crates.io publish
        if: steps.crates.outputs.published == 'true'
        env:
          CRATE_NAME: ${{ needs.validate.outputs.crate_name }}
          RELEASE_VERSION: ${{ needs.validate.outputs.version }}
        shell: bash
        run: echo "${CRATE_NAME} ${RELEASE_VERSION} is already published on crates.io"

  update-aur:
    name: Publish AUR package (${{ matrix.package.name }})
    needs:
      - validate
      - publish-crates
    runs-on: ubuntu-latest
    environment: release
    permissions: {}
    container:
      image: archlinux:base-devel
    strategy:
      fail-fast: false
      matrix:
        package:
          - name: elio
            repo: ssh://aur@aur.archlinux.org/elio.git
            dir: aur-elio
          - name: elio-bin
            repo: ssh://aur@aur.archlinux.org/elio-bin.git
            dir: aur-elio-bin

    steps:
      - name: Install packaging tools
        shell: bash
        run: |
          set -euxo pipefail
          pacman -Syu --noconfirm --needed \
            git \
            openssh \
            pacman-contrib
          useradd -m builder

      - name: Configure AUR SSH key
        env:
          AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
        shell: bash
        run: |
          set -euo pipefail

          if [[ -z "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
            echo "AUR_SSH_PRIVATE_KEY is not configured" >&2
            exit 1
          fi

          mkdir -p ~/.ssh
          chmod 700 ~/.ssh
          printf '%s\n' "${AUR_SSH_PRIVATE_KEY}" > ~/.ssh/aur
          chmod 600 ~/.ssh/aur
          known_hosts="$(mktemp)"
          ssh-keyscan -H aur.archlinux.org > "${known_hosts}"
          if [[ ! -s "${known_hosts}" ]]; then
            echo "Failed to fetch AUR SSH host keys" >&2
            exit 1
          fi
          mv "${known_hosts}" ~/.ssh/known_hosts
          chmod 644 ~/.ssh/known_hosts

          {
            echo "Host aur.archlinux.org"
            echo "    HostName aur.archlinux.org"
            echo "    User aur"
            echo "    IdentityFile ${HOME}/.ssh/aur"
            echo "    IdentitiesOnly yes"
            echo "    UserKnownHostsFile ${HOME}/.ssh/known_hosts"
            echo "    StrictHostKeyChecking yes"
          } > ~/.ssh/config
          chmod 600 ~/.ssh/config

      - name: Clone AUR package repository
        env:
          AUR_REPO: ${{ matrix.package.repo }}
          AUR_DIR: ${{ matrix.package.dir }}
        shell: bash
        run: |
          set -euo pipefail
          export GIT_SSH_COMMAND="ssh -F ${HOME}/.ssh/config"
          git clone "${AUR_REPO}" "${AUR_DIR}"
          chown -R builder:builder "${AUR_DIR}"

      - name: Update PKGBUILD and .SRCINFO
        env:
          AUR_DIR: ${{ matrix.package.dir }}
          RELEASE_VERSION: ${{ needs.validate.outputs.version }}
        shell: bash
        run: |
          set -euo pipefail

          runuser -u builder -- env \
            AUR_DIR="${AUR_DIR}" \
            RELEASE_VERSION="${RELEASE_VERSION}" \
            bash <<'BASH'
            set -euo pipefail
            cd "${AUR_DIR}"

            current_pkgver="$(sed -n 's/^pkgver=//p' PKGBUILD | head -n1)"
            current_pkgrel="$(sed -n 's/^pkgrel=//p' PKGBUILD | head -n1)"

            if [[ -z "${current_pkgver}" || -z "${current_pkgrel}" ]]; then
              echo "Failed to read pkgver/pkgrel from ${AUR_DIR}/PKGBUILD" >&2
              exit 1
            fi

            if [[ ! "${current_pkgrel}" =~ ^[0-9]+$ ]]; then
              echo "Unsupported non-numeric pkgrel '${current_pkgrel}' in ${AUR_DIR}/PKGBUILD" >&2
              exit 1
            fi

            same_version=false
            target_pkgrel=1
            if [[ "${current_pkgver}" == "${RELEASE_VERSION}" ]]; then
              same_version=true
              target_pkgrel="${current_pkgrel}"
            fi

            update_pkgbuild() {
              local pkgrel="$1"

              sed -i "s/^pkgver=.*/pkgver=${RELEASE_VERSION}/" PKGBUILD
              sed -i "s/^pkgrel=.*/pkgrel=${pkgrel}/" PKGBUILD
              sed -i "s/^sha256sums=.*/sha256sums=('SKIP')/" PKGBUILD

              for attempt in {1..12}; do
                if updpkgsums; then
                  break
                fi

                if [[ "${attempt}" -eq 12 ]]; then
                  echo "Failed to generate AUR checksum after 12 attempts" >&2
                  exit 1
                fi

                sleep 10
              done

              makepkg --printsrcinfo > .SRCINFO
            }

            update_pkgbuild "${target_pkgrel}"

            if [[ "${same_version}" == "true" ]] && ! git diff --quiet -- PKGBUILD .SRCINFO; then
              update_pkgbuild "$((current_pkgrel + 1))"
            fi
          BASH

      - name: Commit and push AUR update
        working-directory: ${{ matrix.package.dir }}
        env:
          AUR_PACKAGE: ${{ matrix.package.name }}
          RELEASE_VERSION: ${{ needs.validate.outputs.version }}
        shell: bash
        run: |
          set -euo pipefail

          git config --global --add safe.directory "${PWD}"
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

          git add PKGBUILD .SRCINFO

          if git diff --cached --quiet; then
            echo "AUR package is already up to date"
            exit 0
          fi

          git commit -m "Update ${AUR_PACKAGE} to ${RELEASE_VERSION}"
          export GIT_SSH_COMMAND="ssh -F ${HOME}/.ssh/config"
          git push

  update-copr:
    name: Publish COPR package
    needs:
      - publish-crates
    runs-on: ubuntu-latest
    environment: release
    permissions:
      contents: read
    container:
      image: fedora:43
    env:
      COPR_PROJECT: elio

    steps:
      - name: Install COPR build tooling
        shell: bash
        run: |
          set -euxo pipefail
          dnf -y install \
            cargo \
            copr-cli \
            git \
            make \
            rpm-build \
            zstd

      - name: Checkout
        uses: actions/checkout@v5

      - name: Trust checked-out repository
        shell: bash
        run: |
          set -euo pipefail
          git config --global --add safe.directory "${GITHUB_WORKSPACE}"

      - name: Configure COPR credentials
        env:
          COPR_CONFIG: ${{ secrets.COPR_CONFIG }}
        shell: bash
        run: |
          set -euo pipefail

          if [[ -z "${COPR_CONFIG:-}" ]]; then
            echo "COPR_CONFIG is not configured" >&2
            exit 1
          fi

          mkdir -p ~/.config
          printf '%s\n' "${COPR_CONFIG}" > ~/.config/copr
          chmod 600 ~/.config/copr

      - name: Build and submit COPR SRPM
        shell: bash
        run: |
          set -euo pipefail

          srpm_dir="$(mktemp -d)"
          trap 'rm -rf "${srpm_dir}"' EXIT

          make -f .copr/Makefile srpm \
            outdir="${srpm_dir}" \
            spec=packaging/fedora/elio.spec \
            release=1

          srpm_path="$(find "${srpm_dir}" -maxdepth 1 -name '*.src.rpm' -print -quit)"
          if [[ -z "${srpm_path}" ]]; then
            echo "No source RPM was created in ${srpm_dir}" >&2
            exit 1
          fi

          copr-cli build "${COPR_PROJECT}" "${srpm_path}"

  update-homebrew:
    name: Publish Homebrew tap
    needs:
      - validate
      - github-release
      - publish-crates
    runs-on: ubuntu-latest
    environment: release
    permissions: {}
    env:
      HOMEBREW_TAP_REPO: elio-fm/homebrew-elio

    steps:
      - name: Install tooling
        shell: bash
        run: |
          set -euxo pipefail
          sudo apt-get update
          sudo apt-get install -y curl git
          gh --version

      - name: Clone Homebrew tap
        env:
          HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
        shell: bash
        run: |
          set -euo pipefail

          if [[ -z "${HOMEBREW_TAP_TOKEN:-}" ]]; then
            echo "HOMEBREW_TAP_TOKEN is not configured" >&2
            exit 1
          fi

          auth_header="$(printf 'x-access-token:%s' "${HOMEBREW_TAP_TOKEN}" | base64 | tr -d '\n')"
          echo "::add-mask::${auth_header}"
          git -c "http.https://github.com/.extraheader=AUTHORIZATION: Basic ${auth_header}" \
            clone "https://github.com/${HOMEBREW_TAP_REPO}.git" homebrew-elio

      - name: Prepare Homebrew update branch
        working-directory: homebrew-elio
        env:
          RELEASE_VERSION: ${{ needs.validate.outputs.version }}
        shell: bash
        run: |
          set -euo pipefail

          git switch -c "automation/elio-${RELEASE_VERSION}"

      - name: Update formula
        working-directory: homebrew-elio
        env:
          RELEASE_TAG: ${{ needs.validate.outputs.tag }}
          RELEASE_VERSION: ${{ needs.validate.outputs.version }}
        shell: bash
        run: |
          set -euo pipefail

          formula="Formula/elio.rb"
          source_url="https://github.com/elio-fm/elio/archive/refs/tags/${RELEASE_TAG}.tar.gz"
          sha256="$(curl -fsSL "${source_url}" | sha256sum | awk '{print $1}')"

          SOURCE_URL="${source_url}" SOURCE_SHA256="${sha256}" python3 - <<'PY'
          import os
          import re
          from pathlib import Path

          formula = Path("Formula/elio.rb")
          text = formula.read_text()
          original = text
          source_url = os.environ["SOURCE_URL"]
          sha256 = os.environ["SOURCE_SHA256"]
          release_version = os.environ["RELEASE_VERSION"]

          url_match = re.search(r'^  url "https://github\.com/elio-fm/elio/archive/refs/tags/v([^"]+)\.tar\.gz"$', text, re.MULTILINE)
          current_version = url_match.group(1) if url_match else None
          new_version = current_version != release_version
          revision_match = re.search(r'^  revision ([0-9]+)$', text, re.MULTILINE)
          current_revision = int(revision_match.group(1)) if revision_match else 0

          def strip_bottle_block(value):
              return re.sub(r'\n+  bottle do\n(?:    .*\n)*  end\n+', '\n\n', value, count=1)

          text = strip_bottle_block(text)
          original_without_bottle = strip_bottle_block(original)

          text = re.sub(r'^  url ".*"$', f'  url "{source_url}"', text, count=1, flags=re.MULTILINE)
          text = re.sub(r'^  sha256 ".*"$', f'  sha256 "{sha256}"', text, count=1, flags=re.MULTILINE)
          old = '''  test do
            assert_predicate bin/"elio", :executable?
          end
          '''
          new = '''  test do
            assert_match "elio #{version}", shell_output("#{bin}/elio --version")
          end
          '''
          if old in text:
              text = text.replace(old, new)

          text_without_revision = re.sub(r'^  revision [0-9]+\n', '', text, flags=re.MULTILINE)

          if new_version:
              text = text_without_revision
          elif text_without_revision != re.sub(r'^  revision [0-9]+\n', '', original_without_bottle, flags=re.MULTILINE):
              next_revision = current_revision + 1
              if revision_match:
                  text = re.sub(r'^  revision [0-9]+$', f'  revision {next_revision}', text, count=1, flags=re.MULTILINE)
              else:
                  text = re.sub(r'^(  sha256 "[^"]+"\n)', rf'\1  revision {next_revision}\n', text, count=1, flags=re.MULTILINE)
          else:
              text = original

          formula.write_text(text)
          PY

      - name: Commit, push, and open Homebrew PR
        working-directory: homebrew-elio
        env:
          RELEASE_VERSION: ${{ needs.validate.outputs.version }}
          HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
          GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
        shell: bash
        run: |
          set -euo pipefail

          branch="automation/elio-${RELEASE_VERSION}"

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

          git add Formula/elio.rb

          if git diff --cached --quiet; then
            echo "Homebrew formula is already up to date"
            exit 0
          fi

          git commit -m "Update elio to ${RELEASE_VERSION}"
          auth_header="$(printf 'x-access-token:%s' "${HOMEBREW_TAP_TOKEN}" | base64 | tr -d '\n')"
          echo "::add-mask::${auth_header}"
          git -c "http.https://github.com/.extraheader=AUTHORIZATION: Basic ${auth_header}" \
            push --force-with-lease origin "${branch}"

          pr_body="$(cat <<EOF
          Automated Homebrew formula update for elio ${RELEASE_VERSION}.

          This is a trusted internal release PR. The tap bottle workflow will build and publish bottles after CI passes.
          EOF
          )"

          pr_number="$(gh pr list \
            --repo "${HOMEBREW_TAP_REPO}" \
            --head "${branch}" \
            --state open \
            --json number \
            --jq '.[0].number // empty')"

          if [[ -n "${pr_number}" ]]; then
            gh pr edit "${pr_number}" \
              --repo "${HOMEBREW_TAP_REPO}" \
              --title "Update elio to ${RELEASE_VERSION}" \
              --body "${pr_body}"
            echo "Updated Homebrew PR #${pr_number}"
          else
            gh pr create \
              --repo "${HOMEBREW_TAP_REPO}" \
              --base main \
              --head "${branch}" \
              --title "Update elio to ${RELEASE_VERSION}" \
              --body "${pr_body}"
          fi