crawlex 1.0.4

Stealth crawler with Chrome-perfect TLS/H2 fingerprint, render pool, hooks, persistent queue
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
name: Release

on:
  push:
    branches:
      - main
    tags:
      - 'v*.*.*'
  workflow_dispatch:
    inputs:
      channel:
        description: Release channel
        required: true
        default: stable
        type: choice
        options:
          - stable
          - next
      version:
        description: "Optional version (e.g. 1.0.1, next: 1.0.1-next.10)"
        required: false

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always

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

jobs:
  plan:
    name: Plan release
    runs-on: ubuntu-latest
    outputs:
      should_skip: ${{ steps.plan.outputs.should_skip }}
      release_channel: ${{ steps.plan.outputs.release_channel }}
      release_tag: ${{ steps.plan.outputs.release_tag }}
      package_version: ${{ steps.plan.outputs.package_version }}
      npm_tag: ${{ steps.plan.outputs.npm_tag }}
      github_prerelease: ${{ steps.plan.outputs.github_prerelease }}
      skip_reason: ${{ steps.plan.outputs.skip_reason }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Decide release target
        id: plan
        env:
          EVENT_NAME: ${{ github.event_name }}
          INPUT_CHANNEL: ${{ github.event.inputs.channel || 'stable' }}
          INPUT_VERSION: ${{ github.event.inputs.version || '' }}
          COMMIT_MSG: ${{ github.event.head_commit.message }}
          RUN_NUMBER: ${{ github.run_number }}
        run: |
          set -euo pipefail

          REF="${GITHUB_REF}"

          SHOULD_SKIP=false
          RELEASE_CHANNEL=""
          RELEASE_TAG=""
          PACKAGE_VERSION=""
          NPM_TAG=""
          IS_PRERELEASE=false
          SKIP_REASON=""

          normalize_version() {
            local value="$1"
            echo "${value#v}"
          }

          next_version() {
            local base_version="$1"
            local run_number="${RUN_NUMBER}"
            echo "${base_version}-next.${run_number}"
          }

          if [[ "$EVENT_NAME" == "push" && "$REF" == refs/tags/v* ]]; then
            RELEASE_CHANNEL="stable"
            RELEASE_TAG="${REF#refs/tags/}"
            PACKAGE_VERSION="$(normalize_version "$RELEASE_TAG")"
            NPM_TAG="latest"
            IS_PRERELEASE=false
          elif [[ "$EVENT_NAME" == "push" && "$REF" == "refs/heads/main" ]]; then
            if [[ "$COMMIT_MSG" =~ ^chore:\ release ]] || [[ "$COMMIT_MSG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
              SHOULD_SKIP=true
              SKIP_REASON="Version bump/release commit; skipping next."
            else
              BASE_VERSION=$(awk -F'"' '/^\[package\]/{p=1} p && /^version = /{print $2; exit}' Cargo.toml)
              PACKAGE_VERSION="$(next_version "$BASE_VERSION")"
              RELEASE_CHANNEL="next"
              RELEASE_TAG="v${PACKAGE_VERSION}"
              NPM_TAG="next"
              IS_PRERELEASE=true
              SKIP_REASON="Main branch auto next release"
            fi
          elif [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
            if [[ "$INPUT_CHANNEL" == "stable" ]]; then
              if [[ -z "$INPUT_VERSION" ]]; then
                echo "Stable channel requires version input on workflow_dispatch."
                exit 1
              fi
              RELEASE_CHANNEL="stable"
              PACKAGE_VERSION="$(normalize_version "$INPUT_VERSION")"
              RELEASE_TAG="v${PACKAGE_VERSION}"
              NPM_TAG="latest"
              IS_PRERELEASE=false
            elif [[ "$INPUT_CHANNEL" == "next" ]]; then
              BASE_VERSION=$(awk -F'"' '/^\[package\]/{p=1} p && /^version = /{print $2; exit}' Cargo.toml)
              if [[ -n "$INPUT_VERSION" ]]; then
                PACKAGE_VERSION="$(normalize_version "$INPUT_VERSION")"
              else
                PACKAGE_VERSION="$(next_version "$BASE_VERSION")"
              fi
              RELEASE_CHANNEL="next"
              RELEASE_TAG="v${PACKAGE_VERSION}"
              NPM_TAG="next"
              IS_PRERELEASE=true
            else
              echo "Unsupported channel: $INPUT_CHANNEL"
              exit 1
            fi
          else
            SHOULD_SKIP=true
            SKIP_REASON="Unhandled event/ref for release workflow."
          fi

          echo "should_skip=${SHOULD_SKIP}" >> "${GITHUB_OUTPUT}"
          echo "release_channel=${RELEASE_CHANNEL}" >> "${GITHUB_OUTPUT}"
          echo "release_tag=${RELEASE_TAG}" >> "${GITHUB_OUTPUT}"
          echo "package_version=${PACKAGE_VERSION}" >> "${GITHUB_OUTPUT}"
          echo "npm_tag=${NPM_TAG}" >> "${GITHUB_OUTPUT}"
          echo "github_prerelease=${IS_PRERELEASE}" >> "${GITHUB_OUTPUT}"
          echo "skip_reason=${SKIP_REASON}" >> "${GITHUB_OUTPUT}"

  build:
    name: Build ${{ matrix.asset_name }}
    needs: [plan]
    if: needs.plan.outputs.should_skip != 'true'
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            binary_name: crawlex
            asset_name: crawlex-linux-x86_64
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            binary_name: crawlex
            asset_name: crawlex-linux-aarch64
            cross: true
          # NOTE: Alpine/musl support deferred. The full crawlex binary
          # links Chromium fetcher + lua-hooks which don't cross-compile
          # cleanly to musl. When we add it back it should build the
          # mini binary instead (`--bin crawlex-mini`, HTTP-only); see
          # docs/getting-started/installation.md for the rationale.
          # NOTE: macOS Intel (x86_64) deferred. macos-13 runners on the
          # free tier sit in queue for 1h+ during peak; legacy Intel
          # Macs are also a shrinking share of the user base. Add back
          # if there's demand — the build itself is straightforward
          # (no cross-compile drama).
          - os: macos-14
            target: aarch64-apple-darwin
            binary_name: crawlex
            asset_name: crawlex-macos-aarch64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            binary_name: crawlex.exe
            asset_name: crawlex-windows-x86_64.exe

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

      - name: Free disk space (Linux)
        if: runner.os == 'Linux'
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: false
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          docker-images: true
          swap-storage: false

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

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: 'stable'

      - name: Install dependencies (Linux)
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y ninja-build clang mold

      - name: Install cross-compilation tools
        if: matrix.cross && matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
          {
            echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc"
            echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc"
            echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++"
            echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar"
          } >> "$GITHUB_ENV"

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

      - name: Build release binary
        if: matrix.target != 'aarch64-unknown-linux-musl'
        shell: bash
        run: cargo build --locked --release --target ${{ matrix.target }}

      - name: Build release binary (musl container)
        if: matrix.target == 'aarch64-unknown-linux-musl'
        shell: bash
        run: |
          mkdir -p "${HOME}/.cargo/registry" "${HOME}/.cargo/git"

          docker run --rm \
            -v "${PWD}:/volume" \
            -v "${HOME}/.cargo/registry:/root/.cargo/registry" \
            -v "${HOME}/.cargo/git:/root/.cargo/git" \
            -w /volume \
            messense/rust-musl-cross:aarch64-musl \
            bash -lc '
              apt-get update >/dev/null &&
              apt-get install -y golang-go ninja-build >/dev/null &&
              export BORING_BSSL_SYSROOT="${TARGET_HOME}" &&
              cargo build --locked --release --target aarch64-unknown-linux-musl
            '

          sudo chown -R "$(id -u):$(id -g)" target/aarch64-unknown-linux-musl

      - name: Stage binary (Unix)
        if: runner.os != 'Windows'
        shell: bash
        run: |
          cp "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "${{ matrix.asset_name }}"
          if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
            aarch64-linux-gnu-strip "${{ matrix.asset_name }}" || true
          elif [[ "${{ matrix.target }}" != "aarch64-unknown-linux-musl" ]]; then
            strip "${{ matrix.asset_name }}" || true
          fi
          shasum -a 256 "${{ matrix.asset_name }}" > "${{ matrix.asset_name }}.sha256"

      - name: Stage binary (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          Copy-Item "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "${{ matrix.asset_name }}"
          $hash = (Get-FileHash "${{ matrix.asset_name }}" -Algorithm SHA256).Hash.ToLower()
          "$hash  ${{ matrix.asset_name }}" | Out-File -FilePath "${{ matrix.asset_name }}.sha256" -Encoding ascii

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.asset_name }}
          path: |
            ${{ matrix.asset_name }}
            ${{ matrix.asset_name }}.sha256

  prepare-release:
    name: Prepare release artifacts
    needs: [plan, build]
    if: needs.plan.outputs.should_skip != 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Collect payload
        run: |
          mkdir -p release
          find artifacts -type f \( -name "crawlex-*" -o -name "*.sha256" \) -exec cp {} release/ \;
          if [ -f sdk/crawlex-sdk.js ]; then
            cp sdk/crawlex-sdk.js release/crawlex-sdk.js
            shasum -a 256 release/crawlex-sdk.js > release/crawlex-sdk.js.sha256
          fi

          cd release
          echo "### SHA256 Checksums" > CHECKSUMS.txt
          for f in *.sha256; do
            cat "$f" >> CHECKSUMS.txt
          done
          cd ..

          ls -la release/

      - name: Upload release artifact bundle
        uses: actions/upload-artifact@v4
        with:
          name: release-bundle
          path: release/
          if-no-files-found: error

  publish-github:
    name: Publish GitHub release
    needs: [plan, prepare-release]
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
    if: needs.plan.outputs.should_skip != 'true'
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Download release payload
        uses: actions/download-artifact@v4
        with:
          name: release-bundle
          path: release
          merge-multiple: true

      - name: Render release body
        id: changelog
        run: |
          VERSION_NUMBER="${{ needs.plan.outputs.package_version }}"
          CHANNEL="${{ needs.plan.outputs.release_channel }}"

          if [[ "$CHANNEL" == "next" ]]; then
            echo "changes<<EOF" >> "$GITHUB_OUTPUT"
            echo "# crawlex Next Release" >> "$GITHUB_OUTPUT"
            echo "" >> "$GITHUB_OUTPUT"
            echo "**Version**: \`${{ needs.plan.outputs.release_tag }}\`" >> "$GITHUB_OUTPUT"
            echo "**Channel**: \`next\`" >> "$GITHUB_OUTPUT"
            echo "" >> "$GITHUB_OUTPUT"
            echo "Generated from commit: \`${GITHUB_SHA}\`" >> "$GITHUB_OUTPUT"
            echo "Build: \`#${{ github.run_number }}\`" >> "$GITHUB_OUTPUT"
            echo "" >> "$GITHUB_OUTPUT"
            echo "## Warning" >> "$GITHUB_OUTPUT"
            echo "This is an automated pre-release and may contain unstable changes." >> "$GITHUB_OUTPUT"
            echo "EOF" >> "$GITHUB_OUTPUT"
            exit 0
          fi

          CHANGELOG_CHUNK=""
          if [ -f CHANGELOG.md ]; then
            CHANGELOG_CHUNK=$(awk '/^## \['"${VERSION_NUMBER}"'\]/,/^## \[/{if(/^## \['"${VERSION_NUMBER}"'\]/){next}if(/^## \[/){exit}print}' CHANGELOG.md)
          fi

          if [ -z "$CHANGELOG_CHUNK" ]; then
            PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
            if [ -n "$PREV_TAG" ]; then
              CHANGELOG_CHUNK=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s" --no-merges)
            else
              CHANGELOG_CHUNK=$(git log --pretty=format:"- %s" --no-merges -10)
            fi
          fi

          if [ -z "$CHANGELOG_CHUNK" ]; then
            CHANGELOG_CHUNK="No changes detected."
          fi

          echo "changes<<EOF" >> "$GITHUB_OUTPUT"
          echo "## Changes" >> "$GITHUB_OUTPUT"
          echo "" >> "$GITHUB_OUTPUT"
          echo "$CHANGELOG_CHUNK" >> "$GITHUB_OUTPUT"
          echo "EOF" >> "$GITHUB_OUTPUT"

      - name: Delete old next releases
        if: needs.plan.outputs.release_channel == 'next'
        uses: dev-drprasad/delete-older-releases@v0.3.4
        with:
          keep_latest: 5
          delete_tag_pattern: ".*-next.*"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.plan.outputs.release_tag }}
          name: crawlex ${{ needs.plan.outputs.release_tag }}
          body: |
            # crawlex ${{ needs.plan.outputs.release_tag }}

            ${{ steps.changelog.outputs.changes }}

            ## Installation

            ### Via npm (recommended)
            ```bash
            pnpm add -g crawlex
            # or: npm install -g crawlex
            crawlex --version
            ```

            ### Direct binary download
            ```bash
            # Linux x86_64
            curl -L https://github.com/${{ github.repository }}/releases/download/${{ needs.plan.outputs.release_tag }}/crawlex-linux-x86_64 -o crawlex
            chmod +x crawlex
            sudo mv crawlex /usr/local/bin/
            ```

            ### Verify installation
            ```bash
            crawlex --version
            crawlex --help
            ```
          prerelease: ${{ needs.plan.outputs.github_prerelease }}
          files: release/*
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Job summary
        run: |
          echo "## Release published" >> "$GITHUB_STEP_SUMMARY"
          echo "" >> "$GITHUB_STEP_SUMMARY"
          echo "| Property | Value |" >> "$GITHUB_STEP_SUMMARY"
          echo "|----------|-------|" >> "$GITHUB_STEP_SUMMARY"
          echo "| **Channel** | \`${{ needs.plan.outputs.release_channel }}\` |" >> "$GITHUB_STEP_SUMMARY"
          echo "| **Tag** | \`${{ needs.plan.outputs.release_tag }}\` |" >> "$GITHUB_STEP_SUMMARY"
          echo "| **NPM Tag** | \`${{ needs.plan.outputs.npm_tag }}\` |" >> "$GITHUB_STEP_SUMMARY"

  publish-npm:
    name: Publish npm package
    needs: [plan, prepare-release, publish-github]
    runs-on: ubuntu-latest
    if: needs.plan.outputs.should_skip != 'true'
    permissions:
      contents: read
      id-token: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          registry-url: 'https://registry.npmjs.org'

      - name: Install pnpm
        run: corepack enable && corepack prepare pnpm@9 --activate

      - name: Set package version
        run: |
          VERSION="${{ needs.plan.outputs.package_version }}"
          VERSION="$VERSION" node - <<'EOF'
          const fs = require('fs');
          const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
          pkg.version = process.env.VERSION;
          fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
          EOF

      - name: Validate package
        run: |
          pnpm install --no-frozen-lockfile --ignore-scripts
          pnpm run build
          pnpm run pack-check
        env:
          CRAWLEX_SKIP_POSTINSTALL: '1'

      - name: Publish package
        run: npm publish --tag "${{ needs.plan.outputs.npm_tag }}" --access public --provenance
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

      - name: Publish signal (no registry wait)
        env:
          EXPECTED_VERSION: ${{ needs.plan.outputs.package_version }}
          NPM_TAG: ${{ needs.plan.outputs.npm_tag }}
        run: |
          EXPECTED_VERSION_CANONICAL="${EXPECTED_VERSION%%+*}"
          echo "NPM publish finished: crawlex@${EXPECTED_VERSION_CANONICAL} (tag: ${NPM_TAG})"

      - name: Job summary
        run: |
          echo "## NPM published" >> "$GITHUB_STEP_SUMMARY"
          echo "" >> "$GITHUB_STEP_SUMMARY"
          echo "| Property | Value |" >> "$GITHUB_STEP_SUMMARY"
          echo "|----------|-------|" >> "$GITHUB_STEP_SUMMARY"
          echo "| **Package** | \`crawlex\` |" >> "$GITHUB_STEP_SUMMARY"
          echo "| **Version** | \`${{ needs.plan.outputs.package_version }}\` |" >> "$GITHUB_STEP_SUMMARY"
          echo "| **Tag** | \`${{ needs.plan.outputs.npm_tag }}\` |" >> "$GITHUB_STEP_SUMMARY"

  publish-crates:
    name: Publish crates.io
    needs: [plan, publish-github]
    runs-on: ubuntu-latest
    # crates.io is stable-channel only (no prerelease semver mismatch with
    # the next channel's `-next.N` suffix; crates.io accepts SemVer pre-
    # release strings, but we keep the surface clean by only shipping
    # tagged stable releases there).
    if: needs.plan.outputs.should_skip != 'true' && needs.plan.outputs.release_channel == 'stable'
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Free disk space
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: false
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          docker-images: true
          swap-storage: false

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: "1.91"

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: 'stable'

      - name: Install build deps
        run: |
          sudo apt-get update
          sudo apt-get install -y ninja-build clang mold

      - name: Dry-run package
        run: cargo publish --dry-run --locked

      - name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --locked

      - name: Job summary
        run: |
          echo "## crates.io published" >> "$GITHUB_STEP_SUMMARY"
          echo "" >> "$GITHUB_STEP_SUMMARY"
          echo "| Property | Value |" >> "$GITHUB_STEP_SUMMARY"
          echo "|----------|-------|" >> "$GITHUB_STEP_SUMMARY"
          echo "| **Crate** | \`crawlex\` |" >> "$GITHUB_STEP_SUMMARY"
          echo "| **Version** | \`${{ needs.plan.outputs.package_version }}\` |" >> "$GITHUB_STEP_SUMMARY"