OXYGENHUB
# 91334b7fa574 oxygen / vendor / crc-fast / .github / workflows / release.yml
27.2 KiB · YAML · last changed Strata: the cloud stores send through ureq, so every release target links 1 month ago source blame history raw
1
name: Release
2
3
on:
4
  workflow_run:
5
    workflows: [Tests]
6
    types:
7
      - completed
8
  workflow_dispatch:
9
10
permissions:
11
  contents: write
12
13
jobs:
14
  check-trigger:
15
    name: Check if triggered by tag
16
    runs-on: ubuntu-latest
17
    if: github.event.workflow_run.conclusion == 'success'
18
    outputs:
19
      is_tag: ${{ steps.check.outputs.is_tag }}
20
      tag_name: ${{ steps.check.outputs.tag_name }}
21
    steps:
22
      - name: Check if workflow was triggered by a version tag
23
        id: check
24
        env:
25
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26
        run: |
27
          echo "Workflow run event: ${{ github.event.workflow_run.event }}"
28
          echo "Head branch: ${{ github.event.workflow_run.head_branch }}"
29
          echo "Head SHA: ${{ github.event.workflow_run.head_sha }}"
30
          
31
          # Get tags for this commit
32
          TAGS=$(gh api repos/${{ github.repository }}/git/refs/tags --jq '.[] | select(.object.sha == "${{ github.event.workflow_run.head_sha }}") | .ref' | sed 's|refs/tags/||')
33
          
34
          if [ -z "$TAGS" ]; then
35
            echo "No tags found for this commit"
36
            echo "is_tag=false" >> $GITHUB_OUTPUT
37
          else
38
            # Check if any tag matches version pattern
39
            VERSION_TAG=$(echo "$TAGS" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
40
            if [ -n "$VERSION_TAG" ]; then
41
              echo "Found version tag: $VERSION_TAG"
42
              echo "is_tag=true" >> $GITHUB_OUTPUT
43
              echo "tag_name=$VERSION_TAG" >> $GITHUB_OUTPUT
44
            else
45
              echo "Tags found but none match version pattern"
46
              echo "is_tag=false" >> $GITHUB_OUTPUT
47
            fi
48
          fi
49
50
  validate:
51
    name: Validate
52
    needs: check-trigger
53
    if: needs.check-trigger.outputs.is_tag == 'true'
54
    runs-on: ubuntu-latest
55
    timeout-minutes: 60
56
    outputs:
57
      tag_name: ${{ needs.check-trigger.outputs.tag_name }}
58
    steps:
59
      - name: Checkout code
60
        uses: actions/checkout@v4 # not pinning to commit hash since this is a GitHub action, which we trust
61
        with:
62
          ref: ${{ github.event.workflow_run.head_sha }}
63
64
      - name: Setup Rust toolchain
65
        uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # pinned commit for 1.15.2
66
        with:
67
          toolchain: stable
68
          components: rustfmt, clippy
69
70
      - name: Check code formatting
71
        run: cargo fmt --check
72
73
      - name: Run clippy
74
        run: cargo clippy -- -D warnings
75
76
      - name: Run tests
77
        run: cargo test
78
79
  build:
80
    name: Build ${{ matrix.platform }}-${{ matrix.arch }}
81
    needs: validate
82
    runs-on: ${{ matrix.os }}
83
    env:
84
      TAG_NAME: ${{ needs.validate.outputs.tag_name }}
85
    strategy:
86
      fail-fast: false
87
      matrix:
88
        include:
89
          - target: x86_64-unknown-linux-gnu
90
            os: ubuntu-22.04
91
            platform: linux
92
            arch: x86_64
93
            ext: tar.gz
94
95
          - target: i686-unknown-linux-gnu
96
            os: ubuntu-22.04
97
            platform: linux
98
            arch: x86
99
            ext: tar.gz
100
101
          - target: aarch64-unknown-linux-gnu
102
            os: ubuntu-22.04-arm
103
            platform: linux
104
            arch: aarch64
105
            ext: tar.gz
106
107
          - target: aarch64-apple-darwin
108
            os: macos-14
109
            platform: macos
110
            arch: aarch64
111
            ext: tar.gz
112
113
          - target: x86_64-pc-windows-msvc
114
            os: windows-2022
115
            platform: windows
116
            arch: x86_64
117
            ext: zip
118
119
          - target: i686-pc-windows-msvc
120
            os: windows-2022
121
            platform: windows
122
            arch: x86
123
            ext: zip
124
125
          - target: aarch64-pc-windows-msvc
126
            os: windows-11-arm
127
            platform: windows
128
            arch: aarch64
129
            ext: zip
130
    steps:
131
      - name: Checkout code
132
        uses: actions/checkout@v4 # not pinning to commit hash since this is a GitHub action, which we trust
133
134
      - name: Setup Rust toolchain
135
        uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # pinned commit for 1.15.2
136
        with:
137
          toolchain: stable
138
139
      - name: Install cross
140
        if: matrix.target == 'i686-unknown-linux-gnu'
141
        run: cargo install cross --git https://github.com/cross-rs/cross
142
143
      - name: Build release binaries (native)
144
        if: matrix.target != 'i686-unknown-linux-gnu'
145
        run: cargo build --all-features --release --target ${{ matrix.target }}
146
147
      - name: Build release binaries (cross)
148
        if: matrix.target == 'i686-unknown-linux-gnu'
149
        run: cross build --all-features --release --target ${{ matrix.target }}
150
151
      - name: Verify library files (Unix)
152
        if: runner.os != 'Windows'
153
        shell: bash
154
        run: |
155
          echo "Verifying library files..."
156
          if [ "${{ matrix.platform }}" = "linux" ]; then
157
            test -f target/${{ matrix.target }}/release/libcrc_fast.so || { echo "Missing libcrc_fast.so"; exit 1; }
158
            test -f target/${{ matrix.target }}/release/libcrc_fast.a || { echo "Missing libcrc_fast.a"; exit 1; }
159
            echo "✓ Found libcrc_fast.so and libcrc_fast.a"
160
          elif [ "${{ matrix.platform }}" = "macos" ]; then
161
            test -f target/${{ matrix.target }}/release/libcrc_fast.dylib || { echo "Missing libcrc_fast.dylib"; exit 1; }
162
            test -f target/${{ matrix.target }}/release/libcrc_fast.a || { echo "Missing libcrc_fast.a"; exit 1; }
163
            echo "✓ Found libcrc_fast.dylib and libcrc_fast.a"
164
          fi
165
166
      - name: Verify library files (Windows)
167
        if: runner.os == 'Windows'
168
        shell: pwsh
169
        run: |
170
          Write-Host "Verifying library files..."
171
          if (-not (Test-Path "target/${{ matrix.target }}/release/crc_fast.dll")) {
172
            Write-Error "Missing crc_fast.dll"
173
            exit 1
174
          }
175
          if (-not (Test-Path "target/${{ matrix.target }}/release/crc_fast.dll.lib")) {
176
            Write-Error "Missing crc_fast.dll.lib"
177
            exit 1
178
          }
179
          if (-not (Test-Path "target/${{ matrix.target }}/release/crc_fast.lib")) {
180
            Write-Error "Missing crc_fast.lib"
181
            exit 1
182
          }
183
          Write-Host "✓ Found crc_fast.dll, crc_fast.dll.lib, and crc_fast.lib"
184
185
      - name: Verify CLI binaries (Unix)
186
        if: runner.os != 'Windows'
187
        shell: bash
188
        run: |
189
          echo "Verifying CLI binaries..."
190
          test -f target/${{ matrix.target }}/release/checksum || { echo "Missing checksum"; exit 1; }
191
          test -f target/${{ matrix.target }}/release/arch-check || { echo "Missing arch-check"; exit 1; }
192
          test -f target/${{ matrix.target }}/release/get-custom-params || { echo "Missing get-custom-params"; exit 1; }
193
          echo "✓ Found checksum, arch-check, and get-custom-params"
194
195
      - name: Verify CLI binaries (Windows)
196
        if: runner.os == 'Windows'
197
        shell: pwsh
198
        run: |
199
          Write-Host "Verifying CLI binaries..."
200
          if (-not (Test-Path "target/${{ matrix.target }}/release/checksum.exe")) {
201
            Write-Error "Missing checksum.exe"
202
            exit 1
203
          }
204
          if (-not (Test-Path "target/${{ matrix.target }}/release/arch-check.exe")) {
205
            Write-Error "Missing arch-check.exe"
206
            exit 1
207
          }
208
          if (-not (Test-Path "target/${{ matrix.target }}/release/get-custom-params.exe")) {
209
            Write-Error "Missing get-custom-params.exe"
210
            exit 1
211
          }
212
          Write-Host "✓ Found checksum.exe, arch-check.exe, and get-custom-params.exe"
213
214
      - name: Stage Linux package
215
        if: matrix.platform == 'linux'
216
        shell: bash
217
        run: |
218
          PKG_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
219
          echo "Creating package directory structure for $PKG_NAME..."
220
          
221
          mkdir -p "$PKG_NAME/lib"
222
          mkdir -p "$PKG_NAME/include"
223
          mkdir -p "$PKG_NAME/bin"
224
          
225
          echo "Copying library files..."
226
          cp target/${{ matrix.target }}/release/libcrc_fast.so "$PKG_NAME/lib/"
227
          cp target/${{ matrix.target }}/release/libcrc_fast.a "$PKG_NAME/lib/"
228
          
229
          echo "Copying header file..."
230
          cp libcrc_fast.h "$PKG_NAME/include/"
231
          
232
          echo "Copying CLI binaries..."
233
          cp target/${{ matrix.target }}/release/checksum "$PKG_NAME/bin/"
234
          cp target/${{ matrix.target }}/release/arch-check "$PKG_NAME/bin/"
235
          cp target/${{ matrix.target }}/release/get-custom-params "$PKG_NAME/bin/"
236
          
237
          echo "Setting executable permissions on binaries..."
238
          chmod +x "$PKG_NAME/bin/checksum"
239
          chmod +x "$PKG_NAME/bin/arch-check"
240
          chmod +x "$PKG_NAME/bin/get-custom-params"
241
          
242
          echo "Creating VERSION file..."
243
          echo "$TAG_NAME" > "$PKG_NAME/VERSION"
244
          
245
          echo "Creating README.txt..."
246
          cat > "$PKG_NAME/README.txt" <<EOF
247
          crc-fast Binary Distribution
248
          Version: $TAG_NAME
249
          Platform: Linux ${{ matrix.arch }}
250
          
251
          CONTENTS
252
          ========
253
          This package contains:
254
          - Dynamic library (libcrc_fast.so) and static library (libcrc_fast.a)
255
          - C/C++ header file (libcrc_fast.h)
256
          - Command-line utilities (checksum, arch-check, get-custom-params)
257
          
258
          INSTALLATION
259
          ============
260
          1. Extract this archive to your desired location
261
          2. Add the lib/ directory to your library path:
262
             export LD_LIBRARY_PATH=/path/to/crc-fast/lib:$LD_LIBRARY_PATH
263
          3. Add the bin/ directory to your PATH:
264
             export PATH=/path/to/crc-fast/bin:$PATH
265
          
266
          For system-wide installation (requires root):
267
            sudo cp lib/* /usr/local/lib/
268
            sudo cp include/* /usr/local/include/
269
            sudo cp bin/* /usr/local/bin/
270
            sudo ldconfig
271
          
272
          LINKING
273
          =======
274
          Dynamic linking:
275
            gcc your_program.c -lcrc_fast -L/path/to/crc-fast/lib -I/path/to/crc-fast/include
276
          
277
          Static linking:
278
            gcc your_program.c /path/to/crc-fast/lib/libcrc_fast.a -I/path/to/crc-fast/include
279
          
280
          USAGE
281
          =====
282
          Command-line tools:
283
            checksum --help           # Calculate CRC checksums
284
            arch-check                # Display CPU architecture features
285
            get-custom-params --help  # Generate CRC parameters
286
          
287
          DOCUMENTATION
288
          =============
289
          Full documentation: https://github.com/awesomized/crc-fast-rust
290
          
291
          LICENSE
292
          =======
293
          This software is dual-licensed under MIT OR Apache-2.0.
294
          See LICENSE-MIT and LICENSE-Apache files for details.
295
          EOF
296
          
297
          echo "Copying license files..."
298
          cp LICENSE-MIT "$PKG_NAME/"
299
          cp LICENSE-Apache "$PKG_NAME/"
300
          
301
          echo "✓ Linux package staged successfully"
302
          ls -lR "$PKG_NAME"
303
304
      - name: Create tar.gz package (Linux)
305
        if: matrix.platform == 'linux'
306
        shell: bash
307
        run: |
308
          PKG_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
309
          ARCHIVE_NAME="${PKG_NAME}.tar.gz"
310
          
311
          echo "Creating compressed archive: $ARCHIVE_NAME"
312
          tar -czf "$ARCHIVE_NAME" "$PKG_NAME"
313
          
314
          echo "Verifying archive was created..."
315
          test -f "$ARCHIVE_NAME" || { echo "Failed to create $ARCHIVE_NAME"; exit 1; }
316
          
317
          echo "Archive details:"
318
          ls -lh "$ARCHIVE_NAME"
319
          
320
          echo "✓ tar.gz package created successfully"
321
322
      - name: Generate SHA256 checksum (Linux)
323
        if: matrix.platform == 'linux'
324
        shell: bash
325
        run: |
326
          ARCHIVE_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
327
          CHECKSUM_FILE="${ARCHIVE_NAME}.sha256"
328
          
329
          echo "Generating SHA256 checksum for $ARCHIVE_NAME..."
330
          sha256sum "$ARCHIVE_NAME" > "$CHECKSUM_FILE"
331
          
332
          echo "Verifying checksum file was created..."
333
          test -f "$CHECKSUM_FILE" || { echo "Failed to create $CHECKSUM_FILE"; exit 1; }
334
          
335
          echo "Checksum file contents:"
336
          cat "$CHECKSUM_FILE"
337
          
338
          echo "✓ SHA256 checksum generated successfully"
339
340
      - name: Stage macOS package
341
        if: matrix.platform == 'macos'
342
        shell: bash
343
        run: |
344
          PKG_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
345
          echo "Creating package directory structure for $PKG_NAME..."
346
          
347
          mkdir -p "$PKG_NAME/lib"
348
          mkdir -p "$PKG_NAME/include"
349
          mkdir -p "$PKG_NAME/bin"
350
          
351
          echo "Copying library files..."
352
          cp target/${{ matrix.target }}/release/libcrc_fast.dylib "$PKG_NAME/lib/"
353
          cp target/${{ matrix.target }}/release/libcrc_fast.a "$PKG_NAME/lib/"
354
          
355
          echo "Copying header file..."
356
          cp libcrc_fast.h "$PKG_NAME/include/"
357
          
358
          echo "Copying CLI binaries..."
359
          cp target/${{ matrix.target }}/release/checksum "$PKG_NAME/bin/"
360
          cp target/${{ matrix.target }}/release/arch-check "$PKG_NAME/bin/"
361
          cp target/${{ matrix.target }}/release/get-custom-params "$PKG_NAME/bin/"
362
          
363
          echo "Setting executable permissions on binaries..."
364
          chmod +x "$PKG_NAME/bin/checksum"
365
          chmod +x "$PKG_NAME/bin/arch-check"
366
          chmod +x "$PKG_NAME/bin/get-custom-params"
367
          
368
          echo "Creating VERSION file..."
369
          echo "$TAG_NAME" > "$PKG_NAME/VERSION"
370
          
371
          echo "Creating README.txt..."
372
          cat > "$PKG_NAME/README.txt" <<EOF
373
          crc-fast Binary Distribution
374
          Version: $TAG_NAME
375
          Platform: macOS ${{ matrix.arch }}
376
          
377
          CONTENTS
378
          ========
379
          This package contains:
380
          - Dynamic library (libcrc_fast.dylib) and static library (libcrc_fast.a)
381
          - C/C++ header file (libcrc_fast.h)
382
          - Command-line utilities (checksum, arch-check, get-custom-params)
383
          
384
          INSTALLATION
385
          ============
386
          1. Extract this archive to your desired location
387
          2. Add the lib/ directory to your library path:
388
             export DYLD_LIBRARY_PATH=/path/to/crc-fast/lib:$DYLD_LIBRARY_PATH
389
          3. Add the bin/ directory to your PATH:
390
             export PATH=/path/to/crc-fast/bin:$PATH
391
          
392
          For system-wide installation:
393
            sudo cp lib/* /usr/local/lib/
394
            sudo cp include/* /usr/local/include/
395
            sudo cp bin/* /usr/local/bin/
396
          
397
          LINKING
398
          =======
399
          Dynamic linking:
400
            clang your_program.c -lcrc_fast -L/path/to/crc-fast/lib -I/path/to/crc-fast/include
401
          
402
          Static linking:
403
            clang your_program.c /path/to/crc-fast/lib/libcrc_fast.a -I/path/to/crc-fast/include
404
          
405
          USAGE
406
          =====
407
          Command-line tools:
408
            checksum --help           # Calculate CRC checksums
409
            arch-check                # Display CPU architecture features
410
            get-custom-params --help  # Generate CRC parameters
411
          
412
          DOCUMENTATION
413
          =============
414
          Full documentation: https://github.com/awesomized/crc-fast-rust
415
          
416
          LICENSE
417
          =======
418
          This software is dual-licensed under MIT OR Apache-2.0.
419
          See LICENSE-MIT and LICENSE-Apache files for details.
420
          EOF
421
          
422
          echo "Copying license files..."
423
          cp LICENSE-MIT "$PKG_NAME/"
424
          cp LICENSE-Apache "$PKG_NAME/"
425
          
426
          echo "✓ macOS package staged successfully"
427
          ls -lR "$PKG_NAME"
428
429
      - name: Create tar.gz package (macOS)
430
        if: matrix.platform == 'macos'
431
        shell: bash
432
        run: |
433
          PKG_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
434
          ARCHIVE_NAME="${PKG_NAME}.tar.gz"
435
          
436
          echo "Creating compressed archive: $ARCHIVE_NAME"
437
          tar -czf "$ARCHIVE_NAME" "$PKG_NAME"
438
          
439
          echo "Verifying archive was created..."
440
          test -f "$ARCHIVE_NAME" || { echo "Failed to create $ARCHIVE_NAME"; exit 1; }
441
          
442
          echo "Archive details:"
443
          ls -lh "$ARCHIVE_NAME"
444
          
445
          echo "✓ tar.gz package created successfully"
446
447
      - name: Generate SHA256 checksum (macOS)
448
        if: matrix.platform == 'macos'
449
        shell: bash
450
        run: |
451
          ARCHIVE_NAME="crc-fast-$TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
452
          CHECKSUM_FILE="${ARCHIVE_NAME}.sha256"
453
          
454
          echo "Generating SHA256 checksum for $ARCHIVE_NAME..."
455
          shasum -a 256 "$ARCHIVE_NAME" > "$CHECKSUM_FILE"
456
          
457
          echo "Verifying checksum file was created..."
458
          test -f "$CHECKSUM_FILE" || { echo "Failed to create $CHECKSUM_FILE"; exit 1; }
459
          
460
          echo "Checksum file contents:"
461
          cat "$CHECKSUM_FILE"
462
          
463
          echo "✓ SHA256 checksum generated successfully"
464
465
      - name: Stage Windows package
466
        if: matrix.platform == 'windows'
467
        shell: pwsh
468
        run: |
469
          $PKG_NAME = "crc-fast-$env:TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
470
          Write-Host "Creating package directory structure for $PKG_NAME..."
471
          
472
          New-Item -ItemType Directory -Path "$PKG_NAME/bin" -Force | Out-Null
473
          New-Item -ItemType Directory -Path "$PKG_NAME/lib" -Force | Out-Null
474
          New-Item -ItemType Directory -Path "$PKG_NAME/include" -Force | Out-Null
475
          
476
          Write-Host "Copying library files..."
477
          Copy-Item "target/${{ matrix.target }}/release/crc_fast.dll" "$PKG_NAME/bin/"
478
          Copy-Item "target/${{ matrix.target }}/release/crc_fast.dll.lib" "$PKG_NAME/lib/"
479
          Copy-Item "target/${{ matrix.target }}/release/crc_fast.lib" "$PKG_NAME/lib/"
480
          
481
          Write-Host "Copying header file..."
482
          Copy-Item "libcrc_fast.h" "$PKG_NAME/include/"
483
          
484
          Write-Host "Copying CLI binaries..."
485
          Copy-Item "target/${{ matrix.target }}/release/checksum.exe" "$PKG_NAME/bin/"
486
          Copy-Item "target/${{ matrix.target }}/release/arch-check.exe" "$PKG_NAME/bin/"
487
          Copy-Item "target/${{ matrix.target }}/release/get-custom-params.exe" "$PKG_NAME/bin/"
488
          
489
          Write-Host "Creating VERSION file..."
490
          "$env:TAG_NAME" | Out-File -FilePath "$PKG_NAME/VERSION" -Encoding utf8 -NoNewline
491
          
492
          Write-Host "Creating README.txt..."
493
          @"
494
          crc-fast Binary Distribution
495
          Version: $env:TAG_NAME
496
          Platform: Windows ${{ matrix.arch }}
497
          
498
          CONTENTS
499
          ========
500
          This package contains:
501
          - Dynamic library (crc_fast.dll) with import library (crc_fast.dll.lib)
502
          - Static library (crc_fast.lib)
503
          - C/C++ header file (libcrc_fast.h)
504
          - Command-line utilities (checksum.exe, arch-check.exe, get-custom-params.exe)
505
          
506
          INSTALLATION
507
          ============
508
          1. Extract this archive to your desired location
509
          2. Add the bin\ directory to your PATH environment variable:
510
             - Open System Properties > Environment Variables
511
             - Edit the PATH variable and add: C:\path\to\crc-fast\bin
512
          
513
          For development:
514
            - Add lib\ directory to your linker library path
515
            - Add include\ directory to your compiler include path
516
          
517
          LINKING
518
          =======
519
          Dynamic linking (MSVC):
520
            cl your_program.c /I"C:\path\to\crc-fast\include" /link crc_fast.dll.lib /LIBPATH:"C:\path\to\crc-fast\lib"
521
            Note: crc_fast.dll must be in PATH or same directory as your executable
522
          
523
          Static linking (MSVC):
524
            cl your_program.c /I"C:\path\to\crc-fast\include" /link crc_fast.lib /LIBPATH:"C:\path\to\crc-fast\lib"
525
          
526
          Dynamic linking (MinGW):
527
            gcc your_program.c -I"C:\path\to\crc-fast\include" -L"C:\path\to\crc-fast\lib" -lcrc_fast
528
          
529
          USAGE
530
          =====
531
          Command-line tools:
532
            checksum.exe --help           # Calculate CRC checksums
533
            arch-check.exe                # Display CPU architecture features
534
            get-custom-params.exe --help  # Generate CRC parameters
535
          
536
          DOCUMENTATION
537
          =============
538
          Full documentation: https://github.com/awesomized/crc-fast-rust
539
          
540
          LICENSE
541
          =======
542
          This software is dual-licensed under MIT OR Apache-2.0.
543
          See LICENSE-MIT and LICENSE-Apache files for details.
544
          "@ | Out-File -FilePath "$PKG_NAME/README.txt" -Encoding utf8
545
          
546
          Write-Host "Copying license files..."
547
          Copy-Item "LICENSE-MIT" "$PKG_NAME/"
548
          Copy-Item "LICENSE-Apache" "$PKG_NAME/"
549
          
550
          Write-Host "✓ Windows package staged successfully"
551
          Get-ChildItem -Recurse "$PKG_NAME"
552
553
      - name: Create zip package (Windows)
554
        if: matrix.platform == 'windows'
555
        shell: pwsh
556
        run: |
557
          $PKG_NAME = "crc-fast-$env:TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}"
558
          $ARCHIVE_NAME = "${PKG_NAME}.zip"
559
          
560
          Write-Host "Creating compressed archive: $ARCHIVE_NAME"
561
          Compress-Archive -Path "$PKG_NAME" -DestinationPath "$ARCHIVE_NAME" -CompressionLevel Optimal
562
          
563
          Write-Host "Verifying archive was created..."
564
          if (-not (Test-Path "$ARCHIVE_NAME")) {
565
            Write-Error "Failed to create $ARCHIVE_NAME"
566
            exit 1
567
          }
568
          
569
          Write-Host "Archive details:"
570
          Get-Item "$ARCHIVE_NAME" | Format-List Name, Length, LastWriteTime
571
          
572
          Write-Host "✓ zip package created successfully"
573
574
      - name: Generate SHA256 checksum (Windows)
575
        if: matrix.platform == 'windows'
576
        shell: pwsh
577
        run: |
578
          $ARCHIVE_NAME = "crc-fast-$env:TAG_NAME-${{ matrix.platform }}-${{ matrix.arch }}.zip"
579
          $CHECKSUM_FILE = "${ARCHIVE_NAME}.sha256"
580
          
581
          Write-Host "Generating SHA256 checksum for $ARCHIVE_NAME..."
582
          $hash = (Get-FileHash -Path "$ARCHIVE_NAME" -Algorithm SHA256).Hash.ToLower()
583
          "$hash  $ARCHIVE_NAME" | Out-File -FilePath "$CHECKSUM_FILE" -Encoding utf8 -NoNewline
584
          
585
          Write-Host "Verifying checksum file was created..."
586
          if (-not (Test-Path "$CHECKSUM_FILE")) {
587
            Write-Error "Failed to create $CHECKSUM_FILE"
588
            exit 1
589
          }
590
          
591
          Write-Host "Checksum file contents:"
592
          Get-Content "$CHECKSUM_FILE"
593
          
594
          Write-Host "✓ SHA256 checksum generated successfully"
595
596
      - name: Upload package artifact
597
        uses: actions/upload-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
598
        with:
599
          name: crc-fast-${{ needs.validate.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}
600
          path: crc-fast-${{ needs.validate.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}
601
          if-no-files-found: error
602
          retention-days: 90
603
604
      - name: Upload checksum artifact
605
        uses: actions/upload-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
606
        with:
607
          name: crc-fast-${{ needs.validate.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}.sha256
608
          path: crc-fast-${{ needs.validate.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.arch }}.${{ matrix.ext }}.sha256
609
          if-no-files-found: error
610
          retention-days: 90
611
612
  publish:
613
    name: Publish
614
    needs: [validate, build]
615
    runs-on: ubuntu-latest
616
    env:
617
      TAG_NAME: ${{ needs.validate.outputs.tag_name }}
618
    steps:
619
      - name: Download all artifacts
620
        uses: actions/download-artifact@v4 # not pinning to commit hash since this is a GitHub action, which we trust
621
        with:
622
          path: artifacts
623
          merge-multiple: false
624
625
      - name: Check for existing release
626
        id: check_release
627
        shell: bash
628
        env:
629
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
630
        run: |
631
          echo "Checking if release exists for tag: $TAG_NAME"
632
          
633
          RELEASE_DATA=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
634
            -H "Accept: application/vnd.github+json" \
635
            "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME")
636
          
637
          if echo "$RELEASE_DATA" | jq -e '.id' > /dev/null 2>&1; then
638
            RELEASE_ID=$(echo "$RELEASE_DATA" | jq -r '.id')
639
            echo "release_exists=true" >> $GITHUB_OUTPUT
640
            echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT
641
            echo "✓ Release already exists with ID: $RELEASE_ID"
642
          else
643
            echo "release_exists=false" >> $GITHUB_OUTPUT
644
            echo "release_id=" >> $GITHUB_OUTPUT
645
            echo "✓ No existing release found for this tag"
646
          fi
647
648
      - name: Organize files for upload
649
        shell: bash
650
        run: |
651
          echo "Organizing downloaded artifacts..."
652
          
653
          mkdir -p release-assets
654
          
655
          echo "Moving packages and checksums to release-assets directory..."
656
          find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" -o -name "*.sha256" \) -exec mv {} release-assets/ \;
657
          
658
          echo "Release assets ready for upload:"
659
          ls -lh release-assets/
660
          
661
          echo "Verifying all expected files are present..."
662
          EXPECTED_FILES=(
663
            "crc-fast-$TAG_NAME-linux-x86_64.tar.gz"
664
            "crc-fast-$TAG_NAME-linux-x86_64.tar.gz.sha256"
665
            "crc-fast-$TAG_NAME-linux-x86.tar.gz"
666
            "crc-fast-$TAG_NAME-linux-x86.tar.gz.sha256"
667
            "crc-fast-$TAG_NAME-linux-aarch64.tar.gz"
668
            "crc-fast-$TAG_NAME-linux-aarch64.tar.gz.sha256"
669
            "crc-fast-$TAG_NAME-macos-aarch64.tar.gz"
670
            "crc-fast-$TAG_NAME-macos-aarch64.tar.gz.sha256"
671
            "crc-fast-$TAG_NAME-windows-x86_64.zip"
672
            "crc-fast-$TAG_NAME-windows-x86_64.zip.sha256"
673
            "crc-fast-$TAG_NAME-windows-x86.zip"
674
            "crc-fast-$TAG_NAME-windows-x86.zip.sha256"
675
            "crc-fast-$TAG_NAME-windows-aarch64.zip"
676
            "crc-fast-$TAG_NAME-windows-aarch64.zip.sha256"
677
          )
678
          
679
          MISSING_FILES=()
680
          for file in "${EXPECTED_FILES[@]}"; do
681
            if [ ! -f "release-assets/$file" ]; then
682
              MISSING_FILES+=("$file")
683
            fi
684
          done
685
          
686
          if [ ${#MISSING_FILES[@]} -gt 0 ]; then
687
            echo "ERROR: Missing expected files:"
688
            printf '%s\n' "${MISSING_FILES[@]}"
689
            exit 1
690
          fi
691
          
692
          echo "✓ All expected files are present"
693
          
694
          echo "Total number of files: $(ls -1 release-assets/ | wc -l)"
695
          echo "Total size: $(du -sh release-assets/ | cut -f1)"
696
697
      - name: Create or update GitHub release
698
        uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # pinned commit for 2.4.1
699
        with:
700
          files: release-assets/*
701
          draft: true
702
          prerelease: false
703
          fail_on_unmatched_files: true
704
          generate_release_notes: true
705
        env:
706
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}