Release #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Release tag (e.g., v0.1.0)' | |
| required: true | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.target }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| # macOS ARM64 (Apple Silicon) | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| artifact: karate-darwin-arm64 | |
| ext: tar.gz | |
| # macOS x64 (Intel) | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| artifact: karate-darwin-x64 | |
| ext: tar.gz | |
| # Linux x64 (GNU) | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| artifact: karate-linux-x64 | |
| ext: tar.gz | |
| # Linux ARM64 (GNU) | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| artifact: karate-linux-arm64 | |
| ext: tar.gz | |
| cross: true | |
| # Windows x64 (MSVC) | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| artifact: karate-windows-x64 | |
| ext: zip | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Determine version from tag | |
| id: version | |
| shell: bash | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| TAG="${{ github.event.inputs.tag }}" | |
| else | |
| TAG="${GITHUB_REF#refs/tags/}" | |
| fi | |
| # Strip 'v' prefix: v0.2.0 -> 0.2.0 | |
| VERSION="${TAG#v}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Building version: $VERSION" | |
| - name: Set version in Cargo.toml | |
| shell: bash | |
| run: | | |
| if [[ "$RUNNER_OS" == "macOS" ]]; then | |
| sed -i '' 's/^version = .*/version = "${{ steps.version.outputs.version }}"/' Cargo.toml | |
| else | |
| sed -i 's/^version = .*/version = "${{ steps.version.outputs.version }}"/' Cargo.toml | |
| fi | |
| grep '^version' Cargo.toml | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools | |
| if: matrix.cross | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu | |
| - name: Configure cross-compilation | |
| if: matrix.cross | |
| run: | | |
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| - name: Build release binary | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Prepare artifact (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| mkdir -p dist | |
| cp target/${{ matrix.target }}/release/karate dist/ | |
| cd dist | |
| tar -czvf ${{ matrix.artifact }}.tar.gz karate | |
| shasum -a 256 ${{ matrix.artifact }}.tar.gz > ${{ matrix.artifact }}.tar.gz.sha256 | |
| - name: Prepare artifact (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Force -Path dist | |
| Copy-Item target/${{ matrix.target }}/release/karate.exe dist/ | |
| Compress-Archive -Path dist/karate.exe -DestinationPath dist/${{ matrix.artifact }}.zip | |
| $hash = (Get-FileHash dist/${{ matrix.artifact }}.zip -Algorithm SHA256).Hash.ToLower() | |
| "$hash ${{ matrix.artifact }}.zip" | Out-File -FilePath dist/${{ matrix.artifact }}.zip.sha256 -Encoding utf8 | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact }} | |
| path: | | |
| dist/${{ matrix.artifact }}.${{ matrix.ext }} | |
| dist/${{ matrix.artifact }}.${{ matrix.ext }}.sha256 | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: true | |
| - name: List artifacts | |
| run: find artifacts -type f | head -20 | |
| - name: Determine tag | |
| id: tag | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.tag.outputs.tag }} | |
| name: ${{ steps.tag.outputs.tag }} | |
| draft: false | |
| prerelease: ${{ contains(steps.tag.outputs.tag, '-') }} | |
| generate_release_notes: true | |
| files: | | |
| artifacts/**/* |