ruby-bindings #150
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: ruby-bindings | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| xtask: | |
| name: Build xtask | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 15 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Cargo Cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Build xtask | |
| run: | | |
| docker build -t xtask -f ci/docker/Dockerfile.bindgen --target=builder . | |
| docker run --rm -v $PWD:/workdir xtask cp target/release/xtask /workdir/xtask.bin | |
| - name: Upload xtask binary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: xtask | |
| path: xtask.bin | |
| generate: | |
| name: Generate Ruby bindings | |
| runs-on: ubuntu-24.04 | |
| needs: [xtask] | |
| timeout-minutes: 20 | |
| continue-on-error: true | |
| env: | |
| CARGO: cargo | |
| TARGET_FLAGS: --target ${{ matrix.target }} | |
| RUST_BACKTRACE: 1 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| ruby-version: [ | |
| # ruby 1_9_1_* and 1_9_2_* builds fail with yylex error | |
| 1_9_3_551, | |
| 2_0_0_648, | |
| 2_1_0, 2_1_1, 2_1_2, 2_1_3, 2_1_4, 2_1_5, 2_1_6, 2_1_7, 2_1_8, 2_1_9, 2_1_10, | |
| 2_2_0, 2_2_1, 2_2_2, 2_2_3, 2_2_4, 2_2_5, 2_2_6, 2_2_7, 2_2_8, 2_2_9, 2_2_10, | |
| 2_3_0, 2_3_1, 2_3_2, 2_3_3, 2_3_4, 2_3_5, 2_3_6, 2_3_7, 2_3_8, | |
| 2_4_0, 2_4_1, 2_4_2, 2_4_3, 2_4_4, 2_4_5, 2_4_6, 2_4_7, 2_4_8, 2_4_9, 2_4_10, | |
| 2_5_0, 2_5_1, 2_5_2, 2_5_3, 2_5_4, 2_5_5, 2_5_6, 2_5_7, 2_5_8, 2_5_9, | |
| 2_6_0, 2_6_1, 2_6_2, 2_6_3, 2_6_4, 2_6_5, 2_6_6, 2_6_7, 2_6_8, 2_6_9, 2_6_10, | |
| 2_7_0, 2_7_1, 2_7_2, 2_7_3, 2_7_4, 2_7_5, 2_7_6, 2_7_7, 2_7_8, | |
| 3_0_0, 3_0_1, 3_0_2, 3_0_3, 3_0_4, 3_0_5, 3_0_6, 3_0_7, | |
| 3_1_0, 3_1_1, 3_1_2, 3_1_3, 3_1_4, 3_1_5, 3_1_6, 3_1_7, | |
| 3_2_0, 3_2_1, 3_2_2, 3_2_3, 3_2_4, 3_2_5, 3_2_6, 3_2_7, 3_2_8, 3_2_9, | |
| 3_3_0, 3_3_1, 3_3_2, 3_3_3, 3_3_4, 3_3_5, 3_3_6, 3_3_7, 3_3_8, 3_3_9, 3_3_10, | |
| 3_4_0, 3_4_1, 3_4_2, 3_4_3, 3_4_4, 3_4_5, 3_4_6, 3_4_7, | |
| 4_0_0_preview2 | |
| ] | |
| target: ["x86_64-unknown-linux-gnu"] | |
| steps: | |
| - name: Checkout rbspy repository | |
| uses: actions/checkout@v4 | |
| with: | |
| path: "rbspy" | |
| - name: Download xtask binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: xtask | |
| path: xtask | |
| - name: Generate bindings for ruby ${{ matrix.ruby-version }} | |
| run: | | |
| set -euo pipefail | |
| if [[ "$(ruby -e 'puts Gem::Version.new("${{ matrix.ruby-version }}".gsub("_", ".")) >= Gem::Version.new("3.4.0")')" == "true" ]]; then | |
| ubuntu_version=24.04 | |
| ruby_system_version=3.3.6 | |
| else | |
| ubuntu_version=20.04 | |
| ruby_system_version=2.7.0 | |
| fi | |
| chmod +x xtask/xtask.bin | |
| cd rbspy | |
| docker build -t xtask -f ci/docker/Dockerfile.bindgen --target=generate --build-arg UBUNTU_VERSION=$ubuntu_version --build-arg RUBY_VERSION=$ruby_system_version . | |
| docker run --rm -v $(pwd)/../xtask/xtask.bin:/xtask -v $PWD/ruby-structs:/ruby-structs xtask v${{ matrix.ruby-version }} | |
| mkdir ../bindings-staging | |
| # Add new files to the index so that they get picked up | |
| git add ruby-structs/src | |
| cp $(git diff --name-only --staged | xargs) ../bindings-staging || echo "No new or modified files - bindings are up to date" | |
| - name: Upload Bindings | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: ignore | |
| name: bindings-${{ matrix.ruby-version }} | |
| path: bindings-staging | |
| create-branch: | |
| name: Create branch with updated bindings | |
| runs-on: ubuntu-24.04 | |
| needs: [generate] | |
| steps: | |
| - name: Checkout rbspy repository | |
| uses: actions/checkout@v4 | |
| with: | |
| path: "rbspy" | |
| fetch-depth: 0 | |
| - uses: actions/download-artifact@v4 | |
| - name: Copy bindings into place | |
| id: copy-bindings | |
| run: | | |
| if cp bindings-*/ruby*.rs rbspy/ruby-structs/src/; then | |
| echo "generated_bindings=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No new bindings were generated. Everything is up to date." | |
| echo "generated_bindings=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| - name: Create branch | |
| if: steps.copy-bindings.outputs.generated_bindings == 'true' | |
| run: | | |
| # Configure git just enough that it can push branches | |
| cat <<- EOF > $HOME/.netrc | |
| machine github.com | |
| login ${{ github.actor }} | |
| password ${{ secrets.GITHUB_TOKEN }} | |
| machine api.github.com | |
| login ${{ github.actor }} | |
| password ${{ secrets.GITHUB_TOKEN }} | |
| EOF | |
| chmod 600 $HOME/.netrc | |
| cd rbspy | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "GitHub Actions" | |
| branch_name="generate-ruby-bindings-${{ github.run_number }}" | |
| git checkout -b $branch_name | |
| git add ruby-structs/src/ruby*.rs | |
| git commit -a -m "Regenerate ruby C bindings" --author="GitHub Actions <[email protected]>" | |
| git push -f --set-upstream origin $branch_name |