From 41dd677338e45fc041bbd8e5ab46eeca69ef77f1 Mon Sep 17 00:00:00 2001 From: khoaxuantu <68913255+khoaxuantu@users.noreply.github.com> Date: Tue, 9 Apr 2024 02:20:04 +0700 Subject: [PATCH] Add Ruby test CI (#1242) * test: add test all Ruby code * test: add ruby test ci * Update ruby.yml --------- Co-authored-by: Yudong Jin --- .github/workflows/ruby.yml | 37 +++++++++++++++++++++++++++++++++++++ codes/ruby/test_all.rb | 23 +++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/ruby.yml create mode 100644 codes/ruby/test_all.rb diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 000000000..2083cc086 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,37 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by separate terms of service, privacy policy, and support documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake。 +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: Ruby + +on: + push: + branches: [ "main" ] + paths: ["codes/ruby/**/*.rb"] + pull_request: + branches: [ "main" ] + paths: ["codes/ruby/**/*.rb"] + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + + name: Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + ruby-version: ['3.3'] + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + - name: Run tests + run: ruby codes/ruby/test_all.rb diff --git a/codes/ruby/test_all.rb b/codes/ruby/test_all.rb new file mode 100644 index 000000000..a4d417800 --- /dev/null +++ b/codes/ruby/test_all.rb @@ -0,0 +1,23 @@ +require 'open3' + +start_time = Time.now +ruby_code_dir = File.dirname(__FILE__) +files = Dir.glob("#{ruby_code_dir}/chapter_*/*.rb") + +errors = [] + +files.each do |file| + stdout, stderr, status = Open3.capture3("ruby #{file}") + errors << stderr unless status.success? +end + +puts "\x1b[34mTested #{files.count} files\x1b[m" + +unless errors.empty? + puts "\x1b[33mFound exception in #{errors.length} files\x1b[m" + raise errors.join("\n\n") +else + puts "\x1b[32mPASS\x1b[m" +end + +puts "Testing finishes after #{((Time.now - start_time) * 1000).round} ms"