Skip to content

Commit

Permalink
Pre-build JRuby gem
Browse files Browse the repository at this point in the history
Use Github-Actions to build gems for **all conceivable versions**.

Fixes ConradIrwin#22

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>
  • Loading branch information
stdedos committed Oct 2, 2024
1 parent 74f8a47 commit 4ff277c
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 15 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/build-gems.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Build Gems

on:
push:
pull_request:
release:
types:
- published

jobs:
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
ruby-version:
- 'head'
- '3.4'
- '3.3'
- '3.2'
- '3.1'
- '3.0'
- '2.7'
- '2.6'
- '2.5'
- '2.4'
- '2.3'
- '2.2'
- '2.1'
# - '2.1.0' # Does not exist in ruby/setup-ruby@v1
- '2.0.0'
- '1.9'
- '1.9.3'
# - '1.9.2' # Does not exist in ruby/setup-ruby@v1
# - '1.8(.7)' # Does not exist in ruby/setup-ruby@v1
- 'jruby-head'
- 'jruby-9.4'
- 'jruby-9.3'
- 'jruby-9.2'
- 'jruby-9.1'
# - 'jruby-1[89]mode'
- truffleruby-24
- truffleruby-23
- truffleruby-22
- truffleruby+graalvm-24
- truffleruby+graalvm-23
- truffleruby+graalvm-22
# - rbx # Does not exist in ruby/setup-ruby@v1
# - ree # Does not exist in ruby/setup-ruby@v1

defaults:
run:
shell: /bin/bash --noprofile --norc -Eeuxo pipefail {0}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Slugify GITHUB_REPOSITORY
run: echo "GITHUB_REPOSITORY_SLUG=${GITHUB_REPOSITORY////_}" >> $GITHUB_ENV

- name: Build Extensions and Test
continue-on-error: true # XXX: Tests are a small mess
run: bundle exec rake

- name: Build Gem
run: gem build "${{ github.event.repository.name }}.gemspec"

- name: Create artifacts
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: ${{ env.GITHUB_REPOSITORY_SLUG }}_${{ github.event_name }}_${{ github.event.pull_request.number || github.sha }}_${{ matrix.os
}}_ruby-${{ matrix.ruby-version }}_gems
path: ${{ github.event.repository.name }}-*.gem
44 changes: 33 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
# frozen_string_literal: true

task :clean do
sh 'rm -f ext/*.o ext/*.so ext/*.dylib'
sh 'rm -f ext/org/pryrepl/*.class'
sh 'rm -f ext/org/pryrepl/*.jar'
end

desc "Compile *.c files"
task :compile => [:clean] do
desc 'Compile C extension for CRuby'
task :compile_cruby do
cd 'ext/' do
sh 'ruby extconf.rb'
sh 'make'
end
end

desc "Run example"
desc 'Compile Java extension for JRuby'
task :compile_jruby do
cd 'ext/' do
sh 'find . -name "*.java" | xargs jrubyc --javac'
sh 'find . -name "*.class" | xargs jar cf InterceptionEventHook.jar'
sh 'cp InterceptionEventHook.jar ../lib/'
end
end

desc 'Compile extension'
task :compile => [:clean] do
case defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'undefined' # `undefined`: MRI < 1.9
when 'jruby'
Rake::Task[:compile_jruby].invoke
when 'ruby', 'undefined', 'truffleruby'
Rake::Task[:compile_cruby].invoke
else
raise "Unhandled engine: #{RUBY_ENGINE}"
end
end

desc 'Run example'
task :example do
sh "ruby -I./lib/ ./examples/example.rb "
sh 'ruby -I./lib/ ./examples/example.rb'
end

desc "Run example 2"
desc 'Run example 2'
task :example2 do
sh "ruby -I./lib/ ./examples/example2.rb "
sh 'ruby -I./lib/ ./examples/example2.rb'
end

desc "Run tests"
task :test do
desc 'Run tests'
task :test => [:compile] do
sh 'rspec spec -r ./spec/spec_helpers.rb'
end

task :default => [:compile, :test]


desc 'Compile and run tests'
task :default => [:test]
8 changes: 5 additions & 3 deletions interception.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ Gem::Specification.new do |s|
s.homepage = "http://github.com/ConradIrwin/interception"
s.summary = "Intercept exceptions as they are being raised"
s.description = "Provides a cross-platform ability to intercept all exceptions as they are raised."
s.required_ruby_version = ">= 1.8" # Even though 1.9 is only tested

s.files = `git ls-files`.split("\n")
s.files = `git ls-files -z`.split("\x0")
s.extensions = "ext/extconf.rb"
s.require_path = "lib"

s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
# Rake DOES NOT SUPPORT <1.9.3
s.add_development_dependency 'rake', '>= 12.2'
s.add_development_dependency 'rspec', '~> 3.4'
end
5 changes: 4 additions & 1 deletion lib/cross_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ class << Rubinius
elsif defined?(JRuby)

require 'java'
require 'jruby'

$CLASSPATH << File.expand_path('../../ext/', __FILE__)
java_import org.pryrepl.InterceptionEventHook

def start
old_verbose = $VERBOSE
$VERBOSE = nil

JRuby.runtime.add_event_hook(hook)
ensure
$VERBOSE = old_verbose
Expand All @@ -61,7 +64,7 @@ def hook

# For MRI
# @note For Ruby 2.0 and later we use the new TracePoint API.
elsif RUBY_VERSION.to_f >= 2.0 && RUBY_ENGINE == 'ruby'
elsif (RUBY_VERSION.to_f >= 2.0 && RUBY_ENGINE == 'ruby') || RUBY_ENGINE == 'truffleruby'

def start
@tracepoint ||= TracePoint.new(:raise) do |tp|
Expand Down

0 comments on commit 4ff277c

Please sign in to comment.