yaak 0.1.4

Translate natural language to bash commands using an OpenAI-compatible LLM
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
name: CI

on:
  push:
    branches: [main]
    tags: ["v*"]
  pull_request:
    branches: [main]

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  # ──────────────────────────────────────────────
  # Lint: formatting + clippy
  # ──────────────────────────────────────────────
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - uses: Swatinem/rust-cache@v2

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Run clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

  # ──────────────────────────────────────────────
  # Test: unit + integration tests
  # ──────────────────────────────────────────────
  test:
    name: Test (${{ matrix.os }})
    needs: lint
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4

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

      - uses: Swatinem/rust-cache@v2

      - name: Run tests
        run: cargo test --all-features --verbose

  # ──────────────────────────────────────────────
  # Publish: push crate to crates.io
  # ──────────────────────────────────────────────
  publish:
    name: Publish to crates.io
    needs: test
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

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

      - name: Verify version matches tag
        shell: bash
        run: |
          CARGO_VERSION="v$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
          TAG_VERSION="${GITHUB_REF#refs/tags/}"
          if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
            echo "::error::Cargo.toml version ($CARGO_VERSION) does not match tag ($TAG_VERSION)"
            exit 1
          fi

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

  # ──────────────────────────────────────────────
  # Build: cross-platform release binaries
  # ──────────────────────────────────────────────
  build:
    name: Build (${{ matrix.target }})
    needs: test
    if: startsWith(github.ref, 'refs/tags/v')
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            archive: tar.gz

          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            archive: tar.gz

          - target: x86_64-apple-darwin
            os: macos-latest
            archive: tar.gz

          - target: aarch64-apple-darwin
            os: macos-latest
            archive: tar.gz

          - target: x86_64-pc-windows-msvc
            os: windows-latest
            archive: zip

    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4

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

      - name: Install cross-compilation deps (aarch64-linux)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu
          echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV

      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

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

      - name: Get version from tag
        id: version
        shell: bash
        run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

      - name: Generate shell completions and build .deb (Linux x86_64)
        if: matrix.target == 'x86_64-unknown-linux-gnu'
        shell: bash
        run: |
          # Generate shell completions from the just-built binary
          YAAK="target/${{ matrix.target }}/release/yaak"
          mkdir -p target/completions
          "$YAAK" --completions bash > target/completions/yaak.bash
          "$YAAK" --completions zsh  > target/completions/_yaak
          "$YAAK" --completions fish > target/completions/yaak.fish

          # Build .deb package
          cargo install cargo-deb
          cargo deb --target ${{ matrix.target }} --no-build
          DEB=$(find target/${{ matrix.target }}/debian -name '*.deb' | head -1)
          cp "$DEB" "yaak_${{ steps.version.outputs.version }}_amd64.deb"

      - name: Package (unix)
        if: matrix.archive == 'tar.gz'
        shell: bash
        run: |
          STAGING="yaak-${{ steps.version.outputs.version }}-${{ matrix.target }}"
          mkdir "$STAGING"
          cp target/${{ matrix.target }}/release/yaak "$STAGING/"
          cp README.md LICENSE* "$STAGING/" 2>/dev/null || true
          tar czf "$STAGING.tar.gz" "$STAGING"
          echo "ASSET=$STAGING.tar.gz" >> $GITHUB_ENV

      - name: Package (windows)
        if: matrix.archive == 'zip'
        shell: bash
        run: |
          STAGING="yaak-${{ steps.version.outputs.version }}-${{ matrix.target }}"
          mkdir "$STAGING"
          cp target/${{ matrix.target }}/release/yaak.exe "$STAGING/"
          cp README.md LICENSE* "$STAGING/" 2>/dev/null || true
          7z a "$STAGING.zip" "$STAGING"
          echo "ASSET=$STAGING.zip" >> $GITHUB_ENV

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.target }}
          path: ${{ env.ASSET }}

      - name: Upload .deb artifact
        if: matrix.target == 'x86_64-unknown-linux-gnu'
        uses: actions/upload-artifact@v4
        with:
          name: debian-package
          path: "yaak_${{ steps.version.outputs.version }}_amd64.deb"

  # ──────────────────────────────────────────────
  # Release: create GitHub release with all binaries
  # ──────────────────────────────────────────────
  release:
    name: Release
    needs: build
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: List artifacts
        run: find artifacts -type f | sort

      - name: Generate checksums
        shell: bash
        run: |
          cd artifacts
          find . -type f \( -name '*.tar.gz' -o -name '*.zip' -o -name '*.deb' \) \
            -exec sh -c 'sha256sum "$1" >> ../SHA256SUMS.txt' _ {} \;
          cd ..
          cat SHA256SUMS.txt

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true
          files: |
            artifacts/**/*.tar.gz
            artifacts/**/*.zip
            artifacts/**/*.deb
            SHA256SUMS.txt

  # ──────────────────────────────────────────────
  # Homebrew: update tap formula after release
  # ──────────────────────────────────────────────
  homebrew:
    name: Update Homebrew tap
    needs: release
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Get version from tag
        id: version
        shell: bash
        run: |
          TAG="${GITHUB_REF#refs/tags/}"
          echo "tag=$TAG" >> $GITHUB_OUTPUT
          echo "version=${TAG#v}" >> $GITHUB_OUTPUT

      - name: Download macOS release tarballs and compute SHA256
        id: sha
        shell: bash
        run: |
          VERSION="${{ steps.version.outputs.tag }}"
          BASE_URL="https://github.com/hanneshapke/yaak/releases/download/${VERSION}"

          curl -fSL -o x86_64.tar.gz  "${BASE_URL}/yaak-${VERSION}-x86_64-apple-darwin.tar.gz"
          curl -fSL -o aarch64.tar.gz "${BASE_URL}/yaak-${VERSION}-aarch64-apple-darwin.tar.gz"
          curl -fSL -o linux_x86_64.tar.gz "${BASE_URL}/yaak-${VERSION}-x86_64-unknown-linux-gnu.tar.gz"
          curl -fSL -o linux_aarch64.tar.gz "${BASE_URL}/yaak-${VERSION}-aarch64-unknown-linux-gnu.tar.gz"

          echo "sha_mac_x86=$(sha256sum x86_64.tar.gz | awk '{print $1}')" >> $GITHUB_OUTPUT
          echo "sha_mac_arm=$(sha256sum aarch64.tar.gz | awk '{print $1}')" >> $GITHUB_OUTPUT
          echo "sha_linux_x86=$(sha256sum linux_x86_64.tar.gz | awk '{print $1}')" >> $GITHUB_OUTPUT
          echo "sha_linux_arm=$(sha256sum linux_aarch64.tar.gz | awk '{print $1}')" >> $GITHUB_OUTPUT

      - name: Generate Homebrew formula
        shell: bash
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          TAG="${{ steps.version.outputs.tag }}"
          cat > yaak.rb <<FORMULA
          class Yaak < Formula
            desc "Translate natural language to bash commands using an OpenAI-compatible LLM"
            homepage "https://www.hanneshapke.com/yaak/"
            version "${VERSION}"
            license "Apache-2.0"

            on_macos do
              if Hardware::CPU.arm?
                url "https://github.com/hanneshapke/yaak/releases/download/${TAG}/yaak-${TAG}-aarch64-apple-darwin.tar.gz"
                sha256 "${{ steps.sha.outputs.sha_mac_arm }}"
              else
                url "https://github.com/hanneshapke/yaak/releases/download/${TAG}/yaak-${TAG}-x86_64-apple-darwin.tar.gz"
                sha256 "${{ steps.sha.outputs.sha_mac_x86 }}"
              end
            end

            on_linux do
              if Hardware::CPU.arm?
                url "https://github.com/hanneshapke/yaak/releases/download/${TAG}/yaak-${TAG}-aarch64-unknown-linux-gnu.tar.gz"
                sha256 "${{ steps.sha.outputs.sha_linux_arm }}"
              else
                url "https://github.com/hanneshapke/yaak/releases/download/${TAG}/yaak-${TAG}-x86_64-unknown-linux-gnu.tar.gz"
                sha256 "${{ steps.sha.outputs.sha_linux_x86 }}"
              end
            end

            def install
              bin.install "yaak"
            end

            test do
              assert_match "yaak", shell_output("#{bin}/yaak --version")
            end
          end
          FORMULA
          # Remove leading whitespace from heredoc
          sed -i 's/^          //' yaak.rb
          cat yaak.rb

      - name: Push formula to Homebrew tap
        uses: dmnemec/copy_file_to_another_repo_action@main
        env:
          API_TOKEN_GITHUB: ${{ secrets.HOMEBREW_TAP_TOKEN }}
        with:
          source_file: yaak.rb
          destination_repo: hanneshapke/homebrew-yaak
          destination_folder: Formula
          destination_branch: main
          user_email: github-actions[bot]@users.noreply.github.com
          user_name: github-actions[bot]
          commit_message: "Update yaak formula to ${{ steps.version.outputs.tag }}"

  # ──────────────────────────────────────────────
  # AUR: update yaak and yaak-bin on the Arch User Repository
  # ──────────────────────────────────────────────
  aur:
    name: Update AUR packages
    needs: release
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - pkgname: yaak
            # Source package — hash the source tarball from GitHub archive
            asset_suffix: ""
          - pkgname: yaak-bin
            # Binary package — hash the prebuilt Linux x86_64 tarball
            asset_suffix: "-x86_64-unknown-linux-gnu.tar.gz"
    steps:
      - uses: actions/checkout@v4

      - name: Get version from tag
        id: version
        shell: bash
        run: |
          TAG="${GITHUB_REF#refs/tags/}"
          echo "tag=$TAG" >> $GITHUB_OUTPUT
          echo "version=${TAG#v}" >> $GITHUB_OUTPUT

      - name: Compute source hash (yaak)
        if: matrix.pkgname == 'yaak'
        id: hash_source
        shell: bash
        run: |
          TAG="${{ steps.version.outputs.tag }}"
          URL="https://github.com/hanneshapke/yaak/archive/refs/tags/${TAG}.tar.gz"
          SHA=$(curl -fSL "$URL" | sha256sum | awk '{print $1}')
          echo "sha256=$SHA" >> $GITHUB_OUTPUT

      - name: Compute binary hash (yaak-bin)
        if: matrix.pkgname == 'yaak-bin'
        id: hash_bin
        shell: bash
        run: |
          TAG="${{ steps.version.outputs.tag }}"
          URL="https://github.com/hanneshapke/yaak/releases/download/${TAG}/yaak-${TAG}-x86_64-unknown-linux-gnu.tar.gz"
          SHA=$(curl -fSL "$URL" | sha256sum | awk '{print $1}')
          echo "sha256=$SHA" >> $GITHUB_OUTPUT

      - name: Update PKGBUILD
        shell: bash
        run: |
          PKGBUILD="packaging/aur/${{ matrix.pkgname }}/PKGBUILD"
          VERSION="${{ steps.version.outputs.version }}"

          # Update pkgver
          sed -i "s/^pkgver=.*/pkgver=${VERSION}/" "$PKGBUILD"
          # Reset pkgrel to 1 on version bump
          sed -i "s/^pkgrel=.*/pkgrel=1/" "$PKGBUILD"

          # Update sha256sums
          if [ "${{ matrix.pkgname }}" = "yaak" ]; then
            SHA="${{ steps.hash_source.outputs.sha256 }}"
          else
            SHA="${{ steps.hash_bin.outputs.sha256 }}"
          fi
          sed -i "s/^sha256sums=.*/sha256sums=('${SHA}')/" "$PKGBUILD"

          echo "--- Updated PKGBUILD ---"
          cat "$PKGBUILD"

      - name: Generate .SRCINFO
        uses: addnab/docker-run-action@v3
        with:
          image: archlinux:latest
          options: -v ${{ github.workspace }}:/work
          run: |
            pacman -Syu --noconfirm --needed base-devel
            useradd -m builder
            echo "builder ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/builder
            chown -R builder:builder /work
            su builder -c "cd /work/packaging/aur/${{ matrix.pkgname }} && makepkg --printsrcinfo > .SRCINFO"

      - name: Publish to AUR
        uses: KSXGitHub/github-actions-deploy-aur@v3.0.1
        with:
          pkgname: ${{ matrix.pkgname }}
          pkgbuild: packaging/aur/${{ matrix.pkgname }}/PKGBUILD
          commit_username: yaak-bot
          commit_email: yaak-bot@users.noreply.github.com
          ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
          commit_message: "Update to ${{ steps.version.outputs.tag }}"

  # ──────────────────────────────────────────────
  # Scoop: update manifest in the scoop-yaak bucket
  # ──────────────────────────────────────────────
  scoop:
    name: Update Scoop bucket
    needs: release
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Get version from tag
        id: version
        shell: bash
        run: |
          TAG="${GITHUB_REF#refs/tags/}"
          echo "tag=$TAG" >> $GITHUB_OUTPUT
          echo "version=${TAG#v}" >> $GITHUB_OUTPUT

      - name: Compute Windows binary hash
        id: hash
        shell: bash
        run: |
          TAG="${{ steps.version.outputs.tag }}"
          URL="https://github.com/hanneshapke/yaak/releases/download/${TAG}/yaak-${TAG}-x86_64-pc-windows-msvc.zip"
          SHA=$(curl -fSL "$URL" | sha256sum | awk '{print $1}')
          echo "sha256=$SHA" >> $GITHUB_OUTPUT

      - name: Generate Scoop manifest
        shell: bash
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          TAG="${{ steps.version.outputs.tag }}"
          SHA="${{ steps.hash.outputs.sha256 }}"

          cat > yaak.json <<MANIFEST
          {
              "version": "${VERSION}",
              "description": "Translate natural language to bash commands using any OpenAI-compatible LLM",
              "homepage": "https://github.com/hanneshapke/yaak",
              "license": "Apache-2.0",
              "architecture": {
                  "64bit": {
                      "url": "https://github.com/hanneshapke/yaak/releases/download/${TAG}/yaak-${TAG}-x86_64-pc-windows-msvc.zip",
                      "hash": "${SHA}",
                      "extract_dir": "yaak-${TAG}-x86_64-pc-windows-msvc"
                  }
              },
              "bin": "yaak.exe",
              "checkver": {
                  "github": "https://github.com/hanneshapke/yaak"
              },
              "autoupdate": {
                  "architecture": {
                      "64bit": {
                          "url": "https://github.com/hanneshapke/yaak/releases/download/v\$version/yaak-v\$version-x86_64-pc-windows-msvc.zip",
                          "extract_dir": "yaak-v\$version-x86_64-pc-windows-msvc"
                      }
                  },
                  "hash": {
                      "url": "https://github.com/hanneshapke/yaak/releases/download/v\$version/SHA256SUMS.txt"
                  }
              }
          }
          MANIFEST
          # Remove leading whitespace from heredoc
          sed -i 's/^          //' yaak.json
          echo "--- Generated manifest ---"
          cat yaak.json

      - name: Push manifest to Scoop bucket
        uses: dmnemec/copy_file_to_another_repo_action@main
        env:
          API_TOKEN_GITHUB: ${{ secrets.SCOOP_BUCKET_TOKEN }}
        with:
          source_file: yaak.json
          destination_repo: hanneshapke/scoop-yaak
          destination_folder: .
          destination_branch: main
          user_email: github-actions[bot]@users.noreply.github.com
          user_name: github-actions[bot]
          commit_message: "Update yaak to ${{ steps.version.outputs.tag }}"

  # ──────────────────────────────────────────────
  # Nix: verify the flake builds on each tagged release
  # ──────────────────────────────────────────────
  nix:
    name: Verify Nix flake
    needs: release
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Nix
        uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable

      - name: Build with Nix
        working-directory: packaging/nix
        run: |
          nix build .#yaak --print-build-logs
          ./result/bin/yaak --version