Enhance build-release workflow to conditionally log dependency build … #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: Build and Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.package_name }} | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - package_name: machinetool-windows-amd64 | |
| runner: windows-2025 | |
| plugin_suffix: amd64 | |
| cmake_generator: Visual Studio 17 2022 | |
| cmake_generator_platform: x64 | |
| - package_name: machinetool-linux-x86_64 | |
| runner: ubuntu-24.04 | |
| plugin_suffix: x86_64 | |
| cmake_generator: Ninja | |
| - package_name: machinetool-linux-arm64 | |
| runner: ubuntu-24.04-arm | |
| plugin_suffix: arm64 | |
| cmake_generator: Ninja | |
| - package_name: machinetool-macos-x86_64 | |
| runner: macos-15-intel | |
| plugin_suffix: x86_64 | |
| cmake_generator: Ninja | |
| build_parallel: 2 | |
| rerun_c_target: x86_64-apple-darwin | |
| - package_name: machinetool-macos-arm64 | |
| runner: macos-15 | |
| plugin_suffix: arm64 | |
| cmake_generator: Ninja | |
| build_parallel: 2 | |
| defaults: | |
| run: | |
| shell: bash | |
| env: | |
| PACKAGE_NAME: ${{ matrix.package_name }} | |
| PLUGIN_SUFFIX: ${{ matrix.plugin_suffix }} | |
| CMAKE_GENERATOR: ${{ matrix.cmake_generator }} | |
| CMAKE_GENERATOR_PLATFORM: ${{ matrix.cmake_generator_platform }} | |
| BUILD_PARALLEL: ${{ matrix.build_parallel }} | |
| RERUN_C_TARGET: ${{ matrix.rerun_c_target }} | |
| RERUN_C_VERSION: 0.27.3 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Configure | |
| run: | | |
| cmake_args=( | |
| -S . | |
| -B build | |
| -DCMAKE_INSTALL_PREFIX="$PWD/dist/${PACKAGE_NAME}" | |
| -DPLUGIN_SUFFIX="${PLUGIN_SUFFIX}" | |
| ) | |
| if [ -n "${CMAKE_GENERATOR:-}" ]; then | |
| cmake_args+=(-G "${CMAKE_GENERATOR}") | |
| fi | |
| if [ -n "${CMAKE_GENERATOR_PLATFORM:-}" ]; then | |
| cmake_args+=(-A "${CMAKE_GENERATOR_PLATFORM}") | |
| else | |
| cmake_args+=(-DCMAKE_BUILD_TYPE=Release) | |
| fi | |
| if [ -n "${RERUN_C_TARGET:-}" ]; then | |
| rustup target add "${RERUN_C_TARGET}" | |
| cmake -E make_directory "$PWD/.ci-rerun-c" | |
| curl -L "https://crates.io/api/v1/crates/rerun_c/${RERUN_C_VERSION}/download" \ | |
| -o "$PWD/.ci-rerun-c/rerun_c-${RERUN_C_VERSION}.crate" | |
| cmake -E chdir "$PWD/.ci-rerun-c" \ | |
| cmake -E tar xf "$PWD/.ci-rerun-c/rerun_c-${RERUN_C_VERSION}.crate" | |
| cargo build \ | |
| --manifest-path "$PWD/.ci-rerun-c/rerun_c-${RERUN_C_VERSION}/Cargo.toml" \ | |
| --release \ | |
| --target "${RERUN_C_TARGET}" | |
| cmake_args+=( | |
| "-DRERUN_C_LIB=$PWD/.ci-rerun-c/rerun_c-${RERUN_C_VERSION}/target/${RERUN_C_TARGET}/release/librerun_c.a" | |
| ) | |
| fi | |
| cmake "${cmake_args[@]}" | |
| - name: Build | |
| run: | | |
| if [ -n "${BUILD_PARALLEL:-}" ]; then | |
| CMAKE_BUILD_PARALLEL_LEVEL="${BUILD_PARALLEL}" \ | |
| cmake --build build --config Release --parallel "${BUILD_PARALLEL}" | |
| else | |
| cmake --build build --config Release --parallel | |
| fi | |
| - name: Print dependency build logs | |
| if: failure() | |
| run: | | |
| log_dir=build/_deps/rerun_cpp_sdk-build/arrow/src/arrow_cpp-stamp | |
| if [ ! -d "${log_dir}" ]; then | |
| exit 0 | |
| fi | |
| find "${log_dir}" \ | |
| -type f \ | |
| \( -name 'arrow_cpp-build-*.log' -o -name 'arrow_cpp-configure-*.log' \) | | |
| sort | | |
| while IFS= read -r log; do | |
| echo "::group::${log}" | |
| tail -n 240 "${log}" | |
| echo "::endgroup::" | |
| done | |
| - name: Install | |
| run: cmake --install build --config Release --prefix "dist/${PACKAGE_NAME}" | |
| - name: Check macOS runtime dependencies | |
| if: startsWith(matrix.package_name, 'machinetool-macos-') | |
| run: | | |
| bad_link=0 | |
| while IFS= read -r -d '' file; do | |
| echo "Runtime dependencies for ${file}:" | |
| otool -L "${file}" | |
| if otool -L "${file}" | grep -E '(/opt/homebrew|/usr/local)/(Cellar|opt|lib)'; then | |
| bad_link=1 | |
| fi | |
| done < <(find "dist/${PACKAGE_NAME}" -type f -name '*.plugin' -print0) | |
| if [ "${bad_link}" -ne 0 ]; then | |
| echo "Found a Homebrew or /usr/local runtime dependency." | |
| exit 1 | |
| fi | |
| - name: Add runtime assets | |
| run: | | |
| cmake -E copy_directory models "dist/${PACKAGE_NAME}/models" | |
| cmake -E copy_if_different README.md "dist/${PACKAGE_NAME}/README.md" | |
| - name: Archive package | |
| run: cmake -E chdir dist cmake -E tar cf "${PACKAGE_NAME}.zip" --format=zip -- "${PACKAGE_NAME}" | |
| - name: Upload package | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| path: dist/${{ matrix.package_name }}.zip | |
| if-no-files-found: error | |
| archive: false | |
| release: | |
| name: Publish GitHub release | |
| needs: build | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| actions: read | |
| contents: write | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Download packages | |
| uses: actions/download-artifact@v8 | |
| with: | |
| path: release-assets | |
| pattern: machinetool-* | |
| merge-multiple: true | |
| skip-decompress: true | |
| - name: Create release | |
| env: | |
| GH_REPO: ${{ github.repository }} | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| short_sha="${GITHUB_SHA::7}" | |
| tag_name="build-${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}-${short_sha}" | |
| gh release create "${tag_name}" release-assets/*.zip \ | |
| --target "${GITHUB_SHA}" \ | |
| --title "machinetool ${short_sha}" \ | |
| --notes "Automated build from main at ${GITHUB_SHA}." \ | |
| --latest=false |