tinyetl 0.11.0

Fast, zero-config ETL in a single binary for transforming data between formats and databases
name: Release

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch: # Allow manual trigger for testing

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    continue-on-error: false
    strategy:
      fail-fast: false
      matrix:
        include:
          # macOS builds. Intel is cross-compiled on the Apple Silicon runner; everything it links is
          # either built from source or part of macOS.
          - target: aarch64-apple-darwin
            os: macos-latest
            name: tinyetl-macos-apple-silicon-aarch64
          - target: x86_64-apple-darwin
            os: macos-latest
            name: tinyetl-macos-intel-x86_64
          # Linux build. Built on the oldest supported Ubuntu because a binary only runs where glibc and
          # libstdc++ are at least as new as on the build machine: 22.04 gives glibc 2.35 / GCC 11.
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-22.04
            name: tinyetl-linux-x86_64
          # Linux ARM64, built natively on GitHub's arm64 runner (same Ubuntu, same glibc floor)
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-22.04-arm
            name: tinyetl-linux-aarch64
          # Windows builds
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            name: tinyetl-windows-x86_64
          - target: aarch64-pc-windows-msvc
            os: windows-latest
            name: tinyetl-windows-aarch64

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

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

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

    - name: Install system dependencies (Ubuntu)
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        # Nothing beyond the runner's compiler and perl (for OpenSSL) is needed: unixODBC and OpenSSL
        # are compiled from vendored sources. Don't install unixodbc-dev: its libodbc could be linked
        # instead of the bundled copy.
        echo "No extra packages needed"

    - name: Install system dependencies (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        # Windows has native ODBC support, no additional installation needed
        echo "Using Windows native ODBC driver manager"

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


    - name: Check build success
      if: failure() && steps.build.outcome == 'failure'
      run: |
        echo "::error::Build failed for ${{ matrix.target }}"
        echo "::notice::This platform will be skipped in the release"
        exit 1

    # The binary must run on a machine with nothing installed (no libodbc, libssl, etc.)
    - name: Verify no third-party shared libraries (Linux)
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        BIN=target/${{ matrix.target }}/release/tinyetl
        ldd "$BIN"
        # Only the C/C++ runtime that every Linux system has is allowed
        ALLOWED='^\s*(linux-vdso\.so|(/lib64/|/lib/)?ld-linux|libc\.so|libm\.so|libgcc_s\.so|libstdc\+\+\.so|libpthread\.so|libdl\.so|librt\.so)'
        if ldd "$BIN" | grep -v -E "$ALLOWED"; then
          echo "::error::Binary links a library that is not available on a clean system (listed above)"
          exit 1
        fi
        # Run it in bare containers, as a user downloading the release would: the oldest supported
        # glibc (Ubuntu 22.04, 2.35), Debian 12, and the current Ubuntu LTS
        for image in ubuntu:22.04 debian:12-slim ubuntu:24.04; do
          echo "--- $image"
          docker run --rm -v "$PWD/target/${{ matrix.target }}/release:/dist:ro" "$image" /dist/tinyetl --version
        done

    - name: Verify no third-party shared libraries (macOS)
      if: matrix.os == 'macos-latest'
      run: |
        BIN=target/${{ matrix.target }}/release/tinyetl
        otool -L "$BIN"
        if otool -L "$BIN" | tail -n +2 | grep -v -E "^\s+(/usr/lib/|/System/Library/)"; then
          echo "::error::Binary links a library outside /usr/lib and /System/Library"
          exit 1
        fi

    - name: Prepare binary (Unix)
      if: matrix.os != 'windows-latest'
      run: |
        mkdir -p dist
        cp target/${{ matrix.target }}/release/tinyetl dist/
        chmod +x dist/tinyetl
        # The binary bundles unixODBC (LGPL-2.1-or-later); ship the license texts with it
        cp LICENSE THIRD_PARTY_LICENSES.md dist/
        cp -r licenses dist/
        # Record the exact versions of the statically linked third-party libraries
        UNIX_ODBC=$(grep -A1 '^name = "unix-odbc"' Cargo.lock | grep version | cut -d'"' -f2)
        {
          echo "TinyETL ${{ github.ref_name }} (${{ matrix.target }}), commit ${{ github.sha }}"
          echo "unixODBC: 2.3.14 via the unix-odbc crate ${UNIX_ODBC} (https://crates.io/crates/unix-odbc/${UNIX_ODBC})"
          if [ "$RUNNER_OS" = "Linux" ]; then
            OPENSSL_SRC=$(grep -A1 '^name = "openssl-src"' Cargo.lock | grep version | cut -d'"' -f2)
            echo "OpenSSL: ${OPENSSL_SRC#*+} via the openssl-src crate ${OPENSSL_SRC} (https://crates.io/crates/openssl-src/${OPENSSL_SRC})"
          fi
        } > dist/licenses/BUILD-INFO.txt
        cat dist/licenses/BUILD-INFO.txt

    - name: Prepare binary (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        mkdir dist
        cp target/${{ matrix.target }}/release/tinyetl.exe dist/
        cp LICENSE dist/
        cp THIRD_PARTY_LICENSES.md dist/
        # AWS-LC is statically linked on Windows too; ship the license texts
        cp -r licenses dist/

    - name: Create archive (Unix)
      if: matrix.os != 'windows-latest'
      run: |
        tar -czf ${{ matrix.name }}.tar.gz -C dist .

    - name: Create archive (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        Compress-Archive -Path dist/* -DestinationPath ${{ matrix.name }}.zip

    - name: Upload build artifact
      uses: actions/upload-artifact@v4
      with:
        name: ${{ matrix.name }}
        path: |
          ${{ matrix.name }}.tar.gz
          ${{ matrix.name }}.zip
        if-no-files-found: ignore

  release:
    name: Create Release
    needs: build
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v') && !cancelled()
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Check build results
      id: check-builds
      run: |
        echo "Checking which builds succeeded..."
        # The workflow will continue even if some builds failed
        # We'll upload whatever artifacts are available

    - name: Download all artifacts
      uses: actions/download-artifact@v4
      with:
        path: artifacts
      continue-on-error: true

    - name: Prepare release assets
      run: |
        mkdir -p release-assets
        if [ -d "artifacts" ]; then
          find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} release-assets/ \;
          echo "Available release assets:"
          ls -la release-assets/ || echo "No artifacts found"
          
          # Count successful builds
          ASSET_COUNT=$(find release-assets -type f | wc -l)
          echo "::notice::Found $ASSET_COUNT platform builds for release"
          
          if [ "$ASSET_COUNT" -eq 0 ]; then
            echo "::error::No build artifacts found - all builds may have failed"
            exit 1
          fi
        else
          echo "::error::No artifacts directory found"
          exit 1
        fi

    - name: Create Release
      uses: softprops/action-gh-release@v1
      with:
        files: release-assets/*
        draft: false
        prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
        generate_release_notes: true
        body: |
          ### License notice

          The Linux and macOS binaries include the [unixODBC](https://www.unixodbc.org/) driver manager (version 2.3.14), statically linked and licensed under the **GNU LGPL v2.1 or later**. The Linux binary also includes OpenSSL (Apache License 2.0), and every binary includes AWS-LC (ISC/Apache-2.0). TinyETL itself is licensed under Apache 2.0; the LGPL applies only to unixODBC, and the additional commercial terms in `LICENSE` do not apply to the bundled libraries. License texts are included in each download (`THIRD_PARTY_LICENSES.md` and `licenses/`). See [THIRD_PARTY_LICENSES.md](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/THIRD_PARTY_LICENSES.md) for source and relinking information.
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}