yek 0.21.0

A tool to serialize a repository into chunks of text files
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
name: CI

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

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: short
  OPENSSL_STATIC: true
  PKG_CONFIG_ALLOW_CROSS: true

permissions:
  contents: write

jobs:
  determine-changes:
    name: Determine Changes
    runs-on: ubuntu-latest
    outputs:
      only_docs: ${{ steps.check.outputs.only_docs }}
      only_tests: ${{ steps.check.outputs.only_tests }}
      only_src: ${{ steps.check.outputs.only_src }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - id: check
        run: |
          changed_files="$(git diff --name-only HEAD^ HEAD || true)"

          doc_pattern='^(docs/|README\.md|\.txt$|\.md$)'
          test_pattern='^(tests/|test/)'
          src_pattern='^(src/|Cargo\.toml|Cargo\.lock)'

          only_docs=true
          only_tests=true
          only_src=true

          if [ -z "$changed_files" ]; then
            only_docs=false
            only_tests=false
            only_src=false
          else
            while IFS= read -r file; do
              [[ "$file" =~ $doc_pattern ]] || only_docs=false
              [[ "$file" =~ $test_pattern ]] || only_tests=false
              [[ "$file" =~ $src_pattern ]] || only_src=false
            done < <(echo "$changed_files")
          fi

          echo "only_docs=$only_docs" >> $GITHUB_OUTPUT
          echo "only_tests=$only_tests" >> $GITHUB_OUTPUT
          echo "only_src=$only_src" >> $GITHUB_OUTPUT

  lint:
    name: Lint
    needs: determine-changes
    runs-on: ubuntu-latest
    if: >
      needs.determine-changes.outputs.only_docs != 'true' &&
      needs.determine-changes.outputs.only_tests != 'true' &&
      needs.determine-changes.outputs.only_src != 'true'
    steps:
      - uses: actions/checkout@v4
      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
      - name: Clippy
        run: cargo clippy -- -D warnings
      - name: Format check
        run: cargo fmt --check

  test:
    name: Test
    needs: determine-changes
    runs-on: ubuntu-latest
    if: needs.determine-changes.outputs.only_docs != 'true'
    steps:
      - uses: actions/checkout@v4
      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install OpenSSL (Ubuntu)
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y pkg-config libssl-dev

      - name: Install OpenSSL (macOS)
        if: runner.os == 'macOS'
        run: |
          brew install openssl@3
          echo "OPENSSL_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV
          echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV

      - name: Install OpenSSL (Windows)
        if: runner.os == 'Windows'
        run: |
          choco install openssl --params='/InstallationPath:C:\OpenSSL\'
          echo "OPENSSL_DIR=C:\OpenSSL" >> $env:GITHUB_ENV
          echo "PKG_CONFIG_PATH=C:\OpenSSL\lib\pkgconfig" >> $env:GITHUB_ENV

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

  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    needs: determine-changes
    if: >
      needs.determine-changes.outputs.only_docs != 'true' &&
      needs.determine-changes.outputs.only_tests != 'true'
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux builds
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            asset_name: yek-x86_64-unknown-linux-gnu.tar.gz
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            asset_name: yek-aarch64-unknown-linux-gnu.tar.gz
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            asset_name: yek-x86_64-unknown-linux-musl.tar.gz
          # macOS
          - os: macos-latest
            target: x86_64-apple-darwin
            asset_name: yek-x86_64-apple-darwin.tar.gz
          - os: macos-latest
            target: aarch64-apple-darwin
            asset_name: yek-aarch64-apple-darwin.tar.gz
          # Windows
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            asset_name: yek-x86_64-pc-windows-msvc.zip
          - os: windows-latest
            target: aarch64-pc-windows-msvc
            asset_name: yek-aarch64-pc-windows-msvc.zip

    steps:
      - uses: actions/checkout@v4

      - name: Cache Cargo dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

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

      - name: Install system dependencies
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y pkg-config libssl-dev lcov

      - name: Build
        uses: ./.github/actions/build
        id: build
        with:
          target: ${{ matrix.target }}

      - name: Package binary (Unix)
        if: runner.os != 'Windows'
        shell: bash
        run: |
          mkdir -p release-artifacts
          staging="yek-${{ matrix.target }}"
          mkdir -p "$staging"
          cp "${{ steps.build.outputs.binary_path }}" "$staging/"
          tar czf "release-artifacts/${{ matrix.asset_name }}" "$staging"
          [ -f "release-artifacts/${{ matrix.asset_name }}" ] || { echo "::error::No artifact"; exit 1; }
          [ -s "release-artifacts/${{ matrix.asset_name }}" ] || { echo "::error::Artifact is empty"; exit 1; }

      - name: Package binary (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          New-Item -ItemType Directory -Force -Path release-artifacts
          $staging = "yek-${{ matrix.target }}"
          New-Item -ItemType Directory -Force -Path $staging
          Copy-Item "${{ steps.build.outputs.binary_path }}" $staging
          7z a "release-artifacts\${{ matrix.asset_name }}" "$staging"
          if (-not (Test-Path "release-artifacts\${{ matrix.asset_name }}")) {
            Write-Error "No artifact"
            exit 1
          }
          if ((Get-Item "release-artifacts\${{ matrix.asset_name }}").Length -eq 0) {
            Write-Error "Artifact is empty"
            exit 1
          }

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: build-${{ matrix.target }}
          path: release-artifacts/${{ matrix.asset_name }}

  stress:
    name: Stress ${{ matrix.target }}
    needs: build
    if: >
      github.event_name == 'pull_request' &&
      needs.determine-changes.outputs.only_docs != 'true' &&
      needs.determine-changes.outputs.only_tests != 'true'
    runs-on: ${{ matrix.os }}
    concurrency:
      group: ${{ github.workflow }}-stress-${{ matrix.target }}-${{ github.ref }}
      cancel-in-progress: true
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: macos-latest
            target: x86_64-apple-darwin
          - os: windows-latest
            target: x86_64-pc-windows-msvc

    steps:
      - uses: actions/checkout@v4

      - uses: actions/download-artifact@v4
        with:
          name: build-${{ matrix.target }}
          path: dist

      - name: Extract and install binary
        shell: bash
        run: |
          mkdir -p bin
          if [[ "${{ runner.os }}" == "Windows" ]]; then
            7z x "dist/yek-${{ matrix.target }}.zip" -obin
            cp bin/yek-${{ matrix.target }}/yek.exe /c/Windows/System32/
          else
            tar xzf dist/yek-${{ matrix.target }}.tar.gz -C bin
            chmod +x bin/yek-${{ matrix.target }}/yek
            sudo cp bin/yek-${{ matrix.target }}/yek /usr/local/bin/
          fi

      - name: Checkout VSCode for stress example
        uses: actions/checkout@v4
        with:
          repository: microsoft/vscode
          path: vscode
          fetch-depth: 1 # needed to make sure story is deep enough

      - name: Run stress test
        shell: bash
        timeout-minutes: 1 # only 1 minute to serialize VSCode
        working-directory: vscode
        run: yek

  benchmark:
    name: Benchmark / ${{ matrix.benchmark_group.name }}
    needs: build
    if: >
      github.event_name == 'pull_request' &&
      needs.determine-changes.outputs.only_docs != 'true' &&
      needs.determine-changes.outputs.only_tests != 'true'
    runs-on: ubuntu-latest
    concurrency:
      group: ${{ github.workflow }}-benchmark-${{ matrix.benchmark_group.group }}-${{ github.ref }}
      cancel-in-progress: true
    strategy:
      fail-fast: false
      matrix:
        benchmark_group:
          - group: SingleFile_ByteMode
            name: Single File Byte Mode
          - group: SingleFile_ByteMode_Large
            name: Single File Byte Mode Large
          - group: SingleFile_TokenMode_Large
            name: Single File Token Mode Large
          - group: MultipleFiles_Small
            name: Multiple Files Small
          - group: MultipleFiles_Medium
            name: Multiple Files Medium
          - group: MultipleFiles_Large
            name: Multiple Files Large
          - group: MultipleFiles_TokenMode
            name: Multiple Files Token Mode
          - group: CustomConfig
            name: Custom Config

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: dtolnay/rust-toolchain@stable

      - name: Run benchmarks
        run: |
          git fetch origin ${{ github.base_ref }}
          git checkout ${{ github.base_ref }}
          cargo bench --bench serialization --no-run
          cargo bench --bench serialization -- --save-baseline ${{ github.base_ref }} '${{ matrix.benchmark_group.group }}/'

          git checkout ${{ github.head_ref }}
          cargo bench --bench serialization --no-run
          cargo bench --bench serialization -- --baseline ${{ github.base_ref }} --noise-threshold 2 '${{ matrix.benchmark_group.group }}/' > benchmark_results.md
          echo "## Benchmark Results for ${{ matrix.benchmark_group.name }}" >> $GITHUB_STEP_SUMMARY
          cat benchmark_results.md >> $GITHUB_STEP_SUMMARY

      - name: Upload benchmark results
        uses: actions/upload-artifact@v4
        with:
          name: criterion-${{ matrix.benchmark_group.group }}-results
          path: benchmark_results.md

  coverage:
    name: Code Coverage
    needs: determine-changes
    runs-on: ubuntu-latest
    if: needs.determine-changes.outputs.only_docs != 'true'
    env:
      CARGO_TERM_COLOR: always
      RUSTFLAGS: "-Cinstrument-coverage"
      LLVM_PROFILE_FILE: "yek-%p-%m.profraw"

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # needed so we can check out base_ref below

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: llvm-tools-preview

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y pkg-config libssl-dev lcov

      - name: Install grcov
        run: cargo install grcov

      # --- Base Branch Coverage ---
      - name: Fetch and check out base branch
        if: github.event_name == 'pull_request'
        run: |
          git fetch origin ${{ github.base_ref }}
          git checkout ${{ github.base_ref }}

      - name: Build + Test coverage on base
        if: github.event_name == 'pull_request'
        run: |
          mkdir -p coverage-base
          LLVM_PROFILE_FILE="coverage-base/yek-%p-%m.profraw" cargo test --profile coverage
          grcov . \
            --binary-path ./target/coverage/deps/ \
            -s . \
            -t lcov \
            --branch \
            --ignore-not-existing \
            --ignore "/*" \
            --ignore "tests/*" \
            -o coverage-base/lcov.info
          grcov . \
            --binary-path ./target/coverage/deps/ \
            -s . \
            -t covdir \
            --branch \
            --ignore-not-existing \
            --ignore "/*" \
            --ignore "tests/*" \
            -o coverage-base/coverage.json

      # --- PR Branch Coverage ---
      - name: Check out head branch (PR)
        if: github.event_name == 'pull_request'
        run: |
          git checkout ${{ github.head_ref }}

      - name: Build + Test coverage on PR
        run: |
          mkdir -p coverage
          LLVM_PROFILE_FILE="coverage/yek-%p-%m.profraw" cargo test --profile coverage
          grcov . \
            --binary-path ./target/coverage/deps/ \
            -s . \
            -t lcov \
            --branch \
            --ignore-not-existing \
            --ignore "/*" \
            --ignore "tests/*" \
            -o coverage/lcov.info
          grcov . \
            --binary-path ./target/coverage/deps/ \
            -s . \
            -t covdir \
            --branch \
            --ignore-not-existing \
            --ignore "/*" \
            --ignore "tests/*" \
            -o coverage/coverage.json

      - name: Compare coverage
        if: github.event_name == 'pull_request'
        run: |
          # Check if base coverage file exists
          if [ ! -f coverage-base/coverage.json ]; then
            echo "No base branch coverage data found - this might be the first coverage run"
            echo "PR branch coverage: $(jq -r '.coveragePercent' coverage/coverage.json)%"
            exit 0
          fi

          # Extract line coverage from JSON files using jq
          BASE_COV=$(jq -r '.coveragePercent' coverage-base/coverage.json)
          PR_COV=$(jq -r '.coveragePercent' coverage/coverage.json)

          echo "Base branch coverage: ${BASE_COV}%"
          echo "PR branch coverage:   ${PR_COV}%"

          # Compare and fail if coverage decreased
          check=$(awk -v base="$BASE_COV" -v pr="$PR_COV" 'BEGIN { if (pr < base) print 1; else print 0; }')
          if [ "$check" -eq 1 ]; then
            echo "Error: Coverage decreased from ${BASE_COV}% to ${PR_COV}%"
            exit 1
          else
            echo "Coverage has not decreased."
          fi

      - name: Upload coverage reports
        uses: actions/upload-artifact@v4
        with:
          name: coverage-reports
          path: |
            coverage/lcov.info
            coverage-base/lcov.info

  should-release:
    name: Should Release
    runs-on: ubuntu-latest
    outputs:
      yes: ${{ steps.check.outputs.yes }}
    steps:
      - uses: actions/checkout@v4
      - run: |
          # get current cargo version from Cargo.toml using cargo CLI tool
          # then use `cargo info` to see if it's already released
          cargo_version=$(cargo pkgid | cut -d# -f2)
          if cargo info "yek@$cargo_version"; then
            echo "yek@$cargo_version is already released"
            echo "::set-output name=yes::false"
          else
            if git tag -l "v$cargo_version" | grep -q "v$cargo_version"; then
              echo "::set-output name=yes::true"
            else
              echo "Error: Git tag v$cargo_version is not pushed"
              exit 1
            fi
          fi
        id: check

  release:
    name: Release
    needs: [test, lint, build, should-release]
    runs-on: ubuntu-latest
    if: ${{ needs.should-release.outputs.yes == 'true' }} && github.ref_name == 'main'
    steps:
      - uses: actions/checkout@v4

      - name: Generate release notes
        uses: orhun/git-cliff-action@v2
        id: git-cliff
        with:
          config: cliff.toml
          args: --current --strip header
        env:
          OUTPUT: CHANGES.md

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: dist/build-*/yek-*
          body_path: CHANGES.md
          tag_name: ${{ github.ref_name }}

  publish:
    name: Publish to crates.io
    needs: [test, lint, build, should-release]
    runs-on: ubuntu-latest
    if: ${{ needs.should-release.outputs.yes == 'true' }} && github.ref_name == 'main'
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: "1.84.0"

      - name: Publish
        run: |
          if cargo search --color=never yek | grep -q ${{ github.ref_name }}; then
            echo "yek@${{ github.ref_name }} already published"
            exit 0
          fi
          cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}