gem-build #1
Workflow file for this run
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: gem-build | |
| on: | |
| workflow_call: | |
| inputs: | |
| platforms: | |
| description: 'JSON array of platforms to build (e.g., ["x86_64-linux", "arm64-darwin"])' | |
| required: false | |
| type: string | |
| default: '' | |
| workflow_dispatch: | |
| inputs: | |
| platforms: | |
| description: 'JSON array of platforms to build' | |
| required: false | |
| type: string | |
| default: '' | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| BUNDLER_VER: latest | |
| jobs: | |
| prepare: | |
| name: Prepare platform matrix | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - id: set-matrix | |
| run: | | |
| if [[ -n "${{ inputs.platforms }}" ]]; then | |
| # Use provided platforms input | |
| PLATFORMS='${{ inputs.platforms }}' | |
| else | |
| # Read from platforms.json and extract platforms where build=true | |
| PLATFORMS=$(jq -c '[.platforms | to_entries[] | .value[] | select(.build == true) | {platform: .platform, os: .os, ruby: .ruby}]' .github/platforms.json) | |
| fi | |
| echo "matrix=$PLATFORMS" >> $GITHUB_OUTPUT | |
| build: | |
| name: build (${{ matrix.os }}, ${{ matrix.platform }}) | |
| needs: prepare | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{ fromJSON(needs.prepare.outputs.matrix) }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Cache built dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ports | |
| tmp | |
| lib/ffi-libarchive-binary/libarchive.* | |
| key: deps-${{ matrix.platform }}-${{ hashFiles('ext/configuration.yml', 'lib/ffi-libarchive-binary/*_recipe.rb', 'lib/ffi-libarchive-binary/base_recipe.rb') }} | |
| restore-keys: | | |
| deps-${{ matrix.platform }}- | |
| - uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: ${{ matrix.ruby }} | |
| bundler: ${{ env.BUNDLER_VER }} | |
| bundler-cache: true | |
| - if: matrix.platform == 'aarch64-linux' || matrix.platform == 'aarch64-linux-gnu' || matrix.platform == 'aarch64-linux-musl' | |
| name: Install aarch64 compilers | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu gperf | |
| echo "CMAKE_TOOLCHAIN_FILE=$(pwd)/toolchain/aarch64-linux-gnu.cmake" >> $GITHUB_ENV | |
| - if: matrix.platform == 'aarch64-linux-musl' | |
| name: Install musl cross-compiler for aarch64 | |
| run: | | |
| # Install musl-tools for musl builds | |
| sudo apt-get install musl-tools | |
| # For aarch64-musl, we'll use musl-gcc wrapper with aarch64-linux-gnu-gcc | |
| # This creates a musl-targeted build | |
| - run: bundle exec rake gem:native:${{ matrix.platform }} | |
| # Display compiled libraries for debugging - MUST FAIL if none found | |
| - name: Inspect built libraries | |
| if: matrix.platform != 'any' | |
| shell: bash | |
| run: | | |
| echo "=== Platform: ${{ matrix.platform }} ===" | |
| echo "=== Compiled libraries ===" | |
| FOUND=0 | |
| for ext in dll so dylib; do | |
| for f in lib/ffi-libarchive-binary/*.$ext; do | |
| if [ -f "$f" ]; then | |
| echo "$f" | |
| FOUND=1 | |
| fi | |
| done | |
| done | |
| if [ "$FOUND" -eq 0 ]; then | |
| echo "ERROR: No compiled libraries found!" | |
| echo "=== Library directory contents ===" | |
| ls -la lib/ffi-libarchive-binary/ 2>/dev/null || echo "Directory not found" | |
| exit 1 | |
| fi | |
| echo "=== Library directory contents ===" | |
| ls -la lib/ffi-libarchive-binary/ | |
| # Unpack gem and verify it contains compiled libraries - MUST FAIL if none found | |
| - name: Inspect gem contents | |
| shell: bash | |
| run: | | |
| cd pkg/ | |
| gem unpack ffi-libarchive-binary-*.gem | |
| echo "=== Files in gem ===" | |
| ls -R */lib/ 2>/dev/null | head -50 | |
| echo "=== Compiled libraries in gem ===" | |
| FOUND=0 | |
| for ext in dll so dylib; do | |
| for f in $(find . -name "*.$ext" 2>/dev/null); do | |
| echo "$f" | |
| FOUND=1 | |
| done | |
| done | |
| if [ "$FOUND" -eq 0 ] && [ "${{ matrix.platform }}" != "any" ]; then | |
| echo "ERROR: No compiled libraries found in gem!" | |
| exit 1 | |
| fi | |
| - uses: actions/upload-artifact@v6 | |
| if: failure() | |
| with: | |
| name: build-logs-${{ github.run_number }}-${{ matrix.platform }} | |
| path: tmp/*/ports/*/*/*.log | |
| - name: List native dependencies | |
| if: matrix.platform != 'any' | |
| continue-on-error: true | |
| uses: metanorma/metanorma-build-scripts/native-deps-action@main | |
| with: | |
| libname: archive | |
| directory: lib/ffi-libarchive-binary | |
| - run: | | |
| cd pkg/ | |
| gem unpack ffi-libarchive-binary-*.gem | |
| ls */lib/ffi-libarchive-binary | |
| - uses: actions/upload-artifact@v6 | |
| with: | |
| name: ${{ github.run_number }}-${{ matrix.platform }}-pkg | |
| path: pkg/*.gem | |
| - if: matrix.platform != 'any' | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: lib-${{ github.run_number }}-${{ matrix.platform }} | |
| path: lib/ffi-libarchive-binary/libarchive.* |