From c73df46a7614425ce8e50e1f77ca7e80a70931d3 Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Thu, 25 Sep 2025 21:35:56 +0200 Subject: [PATCH 1/4] ci: comprehensive workflow improvements - Fix cargo publish to trigger only on GitHub releases instead of every master commit - Add version verification between release tag and Cargo.toml - Update actions/checkout to @v5 - Replace cargo install with taiki-e/install-action for faster tool installation - Add Swatinem/rust-cache@v2 for faster builds - Add job dependencies to fail fast and save CI minutes - Add caching for Linux audio packages and Rust builds - Name jobs for better clarity in GitHub Actions UI - Use setup actions for Android SDK Closes: - #994 - #997 --- .github/workflows/cpal.yml | 198 ++++++++++++++++++++++++++----------- CHANGELOG.md | 3 + 2 files changed, 141 insertions(+), 60 deletions(-) diff --git a/.github/workflows/cpal.yml b/.github/workflows/cpal.yml index 5c02fbe02..40276038f 100644 --- a/.github/workflows/cpal.yml +++ b/.github/workflows/cpal.yml @@ -1,50 +1,95 @@ name: cpal -on: [push, pull_request] +on: + push: + branches: [master] + paths-ignore: + - "**.md" + - "docs/**" + - "LICENSE*" + - ".gitignore" + - "Dockerfile*" + - "Cross.toml" + pull_request: + branches: [master] + paths-ignore: + - "**.md" + - "docs/**" + - "LICENSE*" + - ".gitignore" + - "Dockerfile*" + - "Cross.toml" + release: + types: [published] jobs: + rustfmt: + name: Check code formatting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - name: Check formatting + run: cargo fmt --all -- --check - clippy-and-fmt: + clippy: + name: Run Clippy lints runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install Linux audio dependencies - run: | - sudo apt update - sudo apt-get install -y libasound2-dev libjack-jackd2-dev libjack-jackd2-0 libdbus-1-dev - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - with: - components: clippy, rustfmt - targets: armv7-linux-androideabi - - name: Run rustfmt - run: cargo fmt --all -- --check - - name: Run clippy - run: cargo clippy --all --all-features - - name: Run clippy for Android target - run: cargo clippy --all --features asio --target armv7-linux-androideabi + - uses: actions/checkout@v5 + + - name: Cache Linux audio packages + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: libasound2-dev libjack-jackd2-dev libjack-jackd2-0 libdbus-1-dev + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + targets: armv7-linux-androideabi + + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + + - name: Run clippy + run: cargo clippy --all --all-features + - name: Run clippy for Android target + run: cargo clippy --all --features asio --target armv7-linux-androideabi cargo-publish: - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + name: Publish to crates.io + if: github.event_name == 'release' + needs: [test-native, test-cross, test-wasm, test-android, test-ios] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install Linux audio dependencies - run: | - sudo apt update - sudo apt-get install -y libasound2-dev - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - - name: Verify publish crate - uses: katyo/publish-crates@v2 - with: - dry-run: true - ignore-unpublished-changes: true - - name: Publish crate - uses: katyo/publish-crates@v2 - with: - ignore-unpublished-changes: true - registry-token: ${{ secrets.CRATESIO_TOKEN }} + - uses: actions/checkout@v5 + + - name: Cache Linux audio packages + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: libasound2-dev libjack-jackd2-dev libjack-jackd2-0 libdbus-1-dev + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + # Verify the release tag matches Cargo.toml version + - name: Verify release version + run: | + CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') + RELEASE_VERSION=${GITHUB_REF#refs/tags/v} + echo "Cargo.toml version: $CARGO_VERSION" + echo "Release tag version: $RELEASE_VERSION" + if [ "$CARGO_VERSION" != "$RELEASE_VERSION" ]; then + echo "Version mismatch! Cargo.toml has $CARGO_VERSION but release tag is v$RELEASE_VERSION" + exit 1 + fi + + - name: Publish to crates.io + run: cargo publish --token ${{ secrets.CRATESIO_TOKEN }} # Native platform testing test-native: @@ -55,16 +100,10 @@ jobs: # Linux x86_64 - os: ubuntu-latest name: linux-x64 - deps: | - sudo apt update - sudo apt-get install -y libasound2-dev libjack-jackd2-dev libjack-jackd2-0 libdbus-1-dev # Linux ARM64 native - os: ubuntu-24.04-arm name: linux-arm64 - deps: | - sudo apt update - sudo apt-get install -y libasound2-dev libjack-jackd2-dev libjack-jackd2-0 libdbus-1-dev # Windows x86_64 - os: windows-latest @@ -99,9 +138,16 @@ jobs: runs-on: ${{ matrix.os }} name: test-${{ matrix.name }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - - name: Install dependencies + - name: Cache Linux audio packages + if: runner.os == 'Linux' + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: libasound2-dev libjack-jackd2-dev libjack-jackd2-0 libdbus-1-dev + + - name: Install non-Linux dependencies + if: runner.os != 'Linux' run: ${{ matrix.deps }} - name: Install Rust toolchain @@ -109,6 +155,9 @@ jobs: with: target: ${{ matrix.target }} + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + - name: Build beep example (macOS only) if: matrix.build-beep run: cargo build --example beep @@ -126,23 +175,30 @@ jobs: # Cross-compilation for architectures without native runners test-cross: + name: Test cross-compilation (${{ matrix.target }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: target: [armv7-unknown-linux-gnueabihf] - name: test-cross-${{ matrix.target }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable with: target: ${{ matrix.target }} + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + key: cross-${{ matrix.target }} + - name: Install cross - run: cargo install cross + uses: taiki-e/install-action@v2 + with: + tool: cross - name: Check without features run: cross check --target ${{ matrix.target }} --workspace --no-default-features --verbose @@ -158,6 +214,7 @@ jobs: # WebAssembly builds test-wasm: + name: Test WebAssembly (${{ matrix.target }}) runs-on: ubuntu-latest strategy: fail-fast: false @@ -174,9 +231,8 @@ jobs: setup-emscripten: false args: "" - name: test-wasm-${{ matrix.target }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Setup Emscripten toolchain if: matrix.setup-emscripten @@ -187,6 +243,11 @@ jobs: with: target: ${{ matrix.target }} + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + key: wasm-${{ matrix.target }} + - name: Build beep example run: cargo build --example beep --target ${{ matrix.target }} ${{ matrix.args }} @@ -195,18 +256,23 @@ jobs: working-directory: ./examples/wasm-beep run: cargo build --target ${{ matrix.target }} - # Android cross-compilation test-android: + name: Test Android cross-compilation runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Install Rust toolchain (Android targets) uses: dtolnay/rust-toolchain@stable with: targets: armv7-linux-androideabi,aarch64-linux-android,i686-linux-android,x86_64-linux-android + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + key: android + - name: Check Android examples run: | cargo check --example beep --target armv7-linux-androideabi --verbose @@ -218,12 +284,17 @@ jobs: working-directory: examples/android run: cargo check --target armv7-linux-androideabi --verbose - - name: Set up Android SDK - run: | - ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT --install "build-tools;30.0.2" "platforms;android-30" + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + with: + api-level: 30 + build-tools: 30.0.2 + cache-disabled: false - - name: Install Cargo APK - run: cargo install cargo-apk + - name: Install cargo-apk + uses: taiki-e/install-action@v2 + with: + tool: cargo-apk - name: Build APK working-directory: examples/android @@ -231,9 +302,10 @@ jobs: # iOS cross-compilation test-ios: + name: Test iOS cross-compilation runs-on: macOS-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Install dependencies run: brew install llvm @@ -243,9 +315,15 @@ jobs: with: targets: aarch64-apple-ios,x86_64-apple-ios - - name: Install cargo lipo - run: cargo install cargo-lipo + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + key: ios + + - name: Install cargo-lipo + uses: taiki-e/install-action@v2 + with: + tool: cargo-lipo - name: Build iOS example run: cd examples/ios-feedback && xcodebuild -scheme cpal-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator - diff --git a/CHANGELOG.md b/CHANGELOG.md index a666b813e..f9795f815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ - ALSA(process_output): Pass `silent=true` to `PCM.try_recover`, so it doesn't write to stderr. - ASIO: Fix linker flags for MinGW cross-compilation. - CI: Added native ARM64 Linux support in GitHub Actions. +- CI: Fix cargo publish to trigger on GitHub releases instead of every master commit. +- CI: Replace cargo install commands with cached tool installation for faster builds. +- CI: Update actions to latest versions (checkout@v5, rust-cache@v2). - CoreAudio: Change `Device::supported_configs` to return a single element containing the available sample rate range when all elements have the same `mMinimum` and `mMaximum` values. - CoreAudio: Change default audio device detection to be lazy when building a stream, instead of during device enumeration. - CoreAudio: Add `i8`, `i32` and `I24` sample format support (24-bit samples stored in 4 bytes). From 68d26524290d8a3e4e58b2e0a54d484c5755b7a9 Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Thu, 25 Sep 2025 22:22:44 +0200 Subject: [PATCH 2/4] refactor: remove job name fields from GitHub Actions workflow --- .github/workflows/cpal.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/cpal.yml b/.github/workflows/cpal.yml index 40276038f..5fa4c3655 100644 --- a/.github/workflows/cpal.yml +++ b/.github/workflows/cpal.yml @@ -24,7 +24,6 @@ on: jobs: rustfmt: - name: Check code formatting runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -36,7 +35,6 @@ jobs: run: cargo fmt --all -- --check clippy: - name: Run Clippy lints runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -61,7 +59,6 @@ jobs: run: cargo clippy --all --features asio --target armv7-linux-androideabi cargo-publish: - name: Publish to crates.io if: github.event_name == 'release' needs: [test-native, test-cross, test-wasm, test-android, test-ios] runs-on: ubuntu-latest @@ -175,7 +172,6 @@ jobs: # Cross-compilation for architectures without native runners test-cross: - name: Test cross-compilation (${{ matrix.target }}) runs-on: ubuntu-latest strategy: fail-fast: false @@ -214,7 +210,6 @@ jobs: # WebAssembly builds test-wasm: - name: Test WebAssembly (${{ matrix.target }}) runs-on: ubuntu-latest strategy: fail-fast: false @@ -258,7 +253,6 @@ jobs: # Android cross-compilation test-android: - name: Test Android cross-compilation runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -287,9 +281,7 @@ jobs: - name: Setup Android SDK uses: android-actions/setup-android@v3 with: - api-level: 30 - build-tools: 30.0.2 - cache-disabled: false + cmdline-tools-version: 10406996 # API level 30 (Android 11) - name: Install cargo-apk uses: taiki-e/install-action@v2 @@ -302,7 +294,6 @@ jobs: # iOS cross-compilation test-ios: - name: Test iOS cross-compilation runs-on: macOS-latest steps: - uses: actions/checkout@v5 From f2bac41dabeac8cc3a44196bd785860b23e8b62c Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Thu, 25 Sep 2025 22:27:58 +0200 Subject: [PATCH 3/4] fix: update Android SDK setup to install required packages --- .github/workflows/cpal.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpal.yml b/.github/workflows/cpal.yml index 5fa4c3655..9558edbd8 100644 --- a/.github/workflows/cpal.yml +++ b/.github/workflows/cpal.yml @@ -281,7 +281,7 @@ jobs: - name: Setup Android SDK uses: android-actions/setup-android@v3 with: - cmdline-tools-version: 10406996 # API level 30 (Android 11) + packages: platforms;android-30 build-tools;30 - name: Install cargo-apk uses: taiki-e/install-action@v2 From 1de29dec7baf7f161ad5dd830c71146beceeeaf1 Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Thu, 25 Sep 2025 22:30:46 +0200 Subject: [PATCH 4/4] fix: update Android build-tools to version 30.0.3 in CI workflow --- .github/workflows/cpal.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpal.yml b/.github/workflows/cpal.yml index 9558edbd8..c104a9883 100644 --- a/.github/workflows/cpal.yml +++ b/.github/workflows/cpal.yml @@ -281,7 +281,7 @@ jobs: - name: Setup Android SDK uses: android-actions/setup-android@v3 with: - packages: platforms;android-30 build-tools;30 + packages: platforms;android-30 build-tools;30.0.3 - name: Install cargo-apk uses: taiki-e/install-action@v2