diff --git a/.github/actions/build_cli_target/action.yaml b/.github/actions/build_cli_target/action.yaml index f6096837..f0407856 100644 --- a/.github/actions/build_cli_target/action.yaml +++ b/.github/actions/build_cli_target/action.yaml @@ -29,8 +29,16 @@ runs: # Install gcc-mingw-w64-x86-64 for Windows target cross-compilation sudo apt-get install -y build-essential gcc-mingw-w64-x86-64 + - name: Cache cross binary + uses: actions/cache@v4 + id: cache-cross + with: + path: ~/.cargo/bin/cross + key: cross-git-latest + - name: Install cross shell: bash + if: steps.cache-cross.outputs.cache-hit != 'true' run: cargo install cross --git https://github.com/cross-rs/cross --force - name: Build CLI ${{ inputs.target }} target (Windows GNU native) diff --git a/.github/actions/setup_rust_cargo/action.yaml b/.github/actions/setup_rust_cargo/action.yaml index ea6d5a84..670668cc 100644 --- a/.github/actions/setup_rust_cargo/action.yaml +++ b/.github/actions/setup_rust_cargo/action.yaml @@ -14,12 +14,5 @@ runs: with: targets: wasm32-unknown-unknown - - uses: actions/cache@v4 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.arch }}-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 59d0e675..e0f25738 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -68,11 +68,83 @@ jobs: with: lfs: "true" - - name: Setup Xcode 16 + - name: Setup Rust & Cargo + uses: ./.github/actions/setup_rust_cargo + + - name: Build darwin target + uses: ./.github/actions/build_cli_macos_target if: contains(matrix.platform.os-name, 'darwin') - uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: 16 + target: ${{ matrix.platform.target }} + profile: release + force-sentry-dev: true + + - name: Build unix/Windows target + uses: ./.github/actions/build_cli_linux_windows_target + if: ${{ !contains(matrix.platform.os-name, 'darwin') }} + with: + target: ${{ matrix.platform.target }} + profile: release + force-sentry-dev: true + + - name: Upload built binary + uses: actions/upload-artifact@v4 + if: always() + with: + name: binary-${{ matrix.platform.target }} + path: target/${{ matrix.platform.target }}/release/trunk-analytics-cli* + retention-days: 1 + + test: + name: Test for ${{ matrix.platform.target }} + needs: [build_release] + strategy: + matrix: + platform: + - os-name: linux-x86_64 + runs-on: ubuntu-latest + target: x86_64-unknown-linux-musl + + - os-name: linux-aarch64 + runs-on: ubuntu-24.04-arm + target: aarch64-unknown-linux-musl + + - os-name: x86_64-darwin + runs-on: macos-latest + target: x86_64-apple-darwin + + - os-name: aarch64-darwin + runs-on: macos-latest + target: aarch64-apple-darwin + + - os-name: windows-x86_64 + runs-on: public-amd64-4xlarge-dind-germany + target: x86_64-pc-windows-gnu + + runs-on: ${{ matrix.platform.runs-on }} + steps: + # we've been hitting out of free space issues + - name: Delete unnecessary tools folder + run: rm -rf /opt/hostedtoolcache + + - name: Install build tools (Windows and Linux build) + shell: bash + if: ${{ !contains(matrix.platform.os-name, 'darwin') }} + run: | + sudo bash -c 'cat << EOF > /etc/apt/sources.list + deb http://mirror.hetzner.com/ubuntu/packages jammy main restricted universe multiverse + deb http://mirror.hetzner.com/ubuntu/packages jammy-updates main restricted universe multiverse + deb http://mirror.hetzner.com/ubuntu/packages jammy-backports main restricted universe multiverse + deb http://mirror.hetzner.com/ubuntu/packages jammy-security main restricted universe multiverse + EOF' + sudo apt-get update + sudo apt-get install -y git-lfs build-essential + git lfs install + + - name: Checkout + uses: actions/checkout@v4 + with: + lfs: "true" - name: Setup Rust & Cargo uses: ./.github/actions/setup_rust_cargo @@ -99,21 +171,16 @@ jobs: target: ${{ matrix.platform.target }} codecov-token: ${{ secrets.CODECOV_TOKEN }} - - name: Build darwin target - uses: ./.github/actions/build_cli_macos_target - if: contains(matrix.platform.os-name, 'darwin') + - name: Download built binary + uses: actions/download-artifact@v4 with: - target: ${{ matrix.platform.target }} - profile: release - force-sentry-dev: true + name: binary-${{ matrix.platform.target }} + path: target/${{ matrix.platform.target }}/release/ - - name: Build unix/Windows target - uses: ./.github/actions/build_cli_linux_windows_target - if: ${{ !contains(matrix.platform.os-name, 'darwin') }} - with: - target: ${{ matrix.platform.target }} - profile: release - force-sentry-dev: true + - name: Make binary executable + shell: bash + if: ${{ !contains(matrix.platform.os-name, 'windows') }} + run: chmod +x target/${{ matrix.platform.target }}/release/trunk-analytics-cli - name: Extract step outcome shell: bash @@ -169,13 +236,33 @@ jobs: - name: Build workspace run: cargo build --all + - name: Trunk Check + uses: trunk-io/trunk-action@v1 + with: + cache: false + + build_pyo3: + name: Build context-py + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Delete huge unnecessary tools folder + run: rm -rf /opt/hostedtoolcache + - name: Setup and build pyo3 uses: ./.github/actions/setup_build_pyo3 + build_wasm: + name: Build context-js (WASM) + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Delete huge unnecessary tools folder + run: rm -rf /opt/hostedtoolcache + - name: Setup and build wasm uses: ./.github/actions/setup_build_wasm - - - name: Trunk Check - uses: trunk-io/trunk-action@v1 - with: - cache: false diff --git a/.github/workflows/pyo3.yml b/.github/workflows/pyo3.yml index ffe308de..1a6a1174 100644 --- a/.github/workflows/pyo3.yml +++ b/.github/workflows/pyo3.yml @@ -83,6 +83,39 @@ jobs: with: name: wheels-linux-${{ matrix.platform.target }} path: dist + + - name: Upload wheel package to S3 + uses: ./.github/actions/upload_to_s3 + if: "!cancelled() && github.event_name != 'pull_request'" + with: + bucket: ${{ secrets.S3_ASSET_BUCKET }} + name: linux-${{ matrix.platform.target }} + path: dist + s3-flags: --recursive + role-to-assume: ${{ secrets.S3_UPLOAD_ROLE_ARN }} + date: ${{ needs.get-date-sha.outputs.date }} + sha: ${{ needs.get-date-sha.outputs.sha }} + + linux-pytest: + needs: [linux] + runs-on: ${{ matrix.platform.runner }} + strategy: + fail-fast: false + matrix: + platform: + - runner: ubuntu-latest + target: x86_64 + - runner: ubuntu-latest + target: aarch64 + steps: + - uses: actions/checkout@v4 + + - name: Download wheels + uses: actions/download-artifact@v4 + with: + name: wheels-linux-${{ matrix.platform.target }} + path: dist + - name: pytest if: ${{ startsWith(matrix.platform.target, 'x86_64') }} shell: bash @@ -95,6 +128,7 @@ jobs: uv pip install -r requirements-dev.txt uv pip install context-py --find-links ../dist --force-reinstall pytest --cov + - name: pytest if: ${{ startsWith(matrix.platform.target, 'aarch64') }} uses: uraimo/run-on-arch-action@v2 @@ -122,18 +156,6 @@ jobs: slug: trunk-io/analytics-cli directory: ./context-py - - name: Upload wheel package to S3 - uses: ./.github/actions/upload_to_s3 - if: "!cancelled() && github.event_name != 'pull_request'" - with: - bucket: ${{ secrets.S3_ASSET_BUCKET }} - name: linux-${{ matrix.platform.target }} - path: dist - s3-flags: --recursive - role-to-assume: ${{ secrets.S3_UPLOAD_ROLE_ARN }} - date: ${{ needs.get-date-sha.outputs.date }} - sha: ${{ needs.get-date-sha.outputs.sha }} - macos: needs: [get-date-sha] runs-on: ${{ matrix.platform.runner }}