Skip to content

Commit

Permalink
Add test github action
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed May 6, 2024
1 parent eb36a43 commit 45d71e4
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 60 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Unit Test

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
name: Test with ${{ matrix.ruby }}
strategy:
matrix:
# Find the versions available at https://github.com/ruby/setup-ruby/blob/master/ruby-builder-versions.json
ruby:
- '3.3.1'
- '3.2.4'
- '3.1.5'
- '3.0.6'
- '2.7.8'
- '2.6.10'
# - '2.5.9' # TODO: Missing `minitest/test_task` in minitest 5.15.0
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the test
run: bundle exec rake test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/Gemfile.lock
/rbs_collection.lock.yaml
/.gem_rbs_collection
/tmp
gemfiles/*.lock
24 changes: 2 additions & 22 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "rake", "~> 13.1.0"

gemspec

group :test do
gem "minitest", "~> 5.20.0"
end

group :check do
gem "rubocop", "~> 1.62.1", require: false
gem "rubocop-minitest", "~> 0.33.0", require: false
gem "rubocop-rake", "~> 0.6.0", require: false
gem "standard", "~> 1.0", require: false
gem "steep", "~> 1.6.0", require: false
end

group :debug do
gem "debug"
gem "irb"
end
gemfile = "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION.split(".").take(2).join(".")}.rb"
eval_gemfile "gemfiles/#{gemfile}"
5 changes: 0 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

# @type self: Rake::TaskLib

require "standard/rake"

# load rake tasks from tasks directory
Dir.glob(File.join(__dir__ || Dir.pwd, "tasks", "*.rake")) { |f| import f }

task default: [:test, :check]

desc "Run checks"
task check: [:standard, :rubocop, :"steep:check"]
14 changes: 14 additions & 0 deletions gemfiles/ruby-2.5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake", "~> 13.1.0"

group :test do
gem "minitest", "~> 5.15.0"
end

group :debug do
gem "debug"
gem "irb"
end
14 changes: 14 additions & 0 deletions gemfiles/ruby-2.6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake", "~> 13.1.0"

group :test do
gem "minitest", "~> 5.22.3"
end

group :debug do
gem "debug"
gem "irb"
end
14 changes: 14 additions & 0 deletions gemfiles/ruby-2.7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake", "~> 13.1.0"

group :test do
gem "minitest", "~> 5.22.3"
end

group :debug do
gem "debug"
gem "irb"
end
14 changes: 14 additions & 0 deletions gemfiles/ruby-3.0.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake", "~> 13.1.0"

group :test do
gem "minitest", "~> 5.22.3"
end

group :debug do
gem "debug"
gem "irb"
end
14 changes: 14 additions & 0 deletions gemfiles/ruby-3.1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake", "~> 13.1.0"

group :test do
gem "minitest", "~> 5.22.3"
end

group :debug do
gem "debug"
gem "irb"
end
14 changes: 14 additions & 0 deletions gemfiles/ruby-3.2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake", "~> 13.1.0"

group :test do
gem "minitest", "~> 5.22.3"
end

group :debug do
gem "debug"
gem "irb"
end
22 changes: 22 additions & 0 deletions gemfiles/ruby-3.3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake", "~> 13.1.0"

group :test do
gem "minitest", "~> 5.22.3"
end

group :check do
gem "rubocop", "~> 1.62.1", require: false
gem "rubocop-minitest", "~> 0.33.0", require: false
gem "rubocop-rake", "~> 0.6.0", require: false
gem "standard", "~> 1.0", require: false
gem "steep", "~> 1.6.0", require: false
end

group :debug do
gem "debug"
gem "irb"
end
10 changes: 8 additions & 2 deletions tasks/rubocop.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# @type self: Rake::DSL

require "rubocop/rake_task"
begin
require "rubocop/rake_task"

RuboCop::RakeTask.new
RuboCop::RakeTask.new

desc "Run RuboCop"
task check: :rubocop
rescue LoadError
end
11 changes: 11 additions & 0 deletions tasks/standard.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

# @type self: Rake::DSL

begin
require "standard/rake"

desc "Run StandardRB"
task check: :standard
rescue LoadError
end
70 changes: 39 additions & 31 deletions tasks/steep.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,57 @@

# @type self: Rake::TaskLib

namespace :steep do
desc "Run static type checking"
task :check do |_task, args|
args_sh = args.to_a.map { |a| "'#{a}'" }.join(" ")
begin
require "steep"

sh "steep check #{args_sh}".strip
end
namespace :steep do
desc "Run static type checking"
task :check do |_task, args|
args_sh = args.to_a.map { |a| "'#{a}'" }.join(" ")

desc "Output static type checking statistics"
task :stats do |_task, args|
format = args.to_a.first || "table"
sh "steep check #{args_sh}".strip
end

if format == "md"
data = `steep stats --format=csv`
desc "Output static type checking statistics"
task :stats do |_task, args|
format = args.to_a.first || "table"

require "csv"
if format == "md"
data = `steep stats --format=csv`

csv = CSV.new(data, headers: true)
headers = true
csv.each do |row|
hrow = row.to_h
require "csv"

if headers
$stdout.write("|")
$stdout.write(hrow.keys.join("|"))
$stdout.write("|")
$stdout.write("\n")
csv = CSV.new(data, headers: true)
headers = true
csv.each do |row|
hrow = row.to_h

if headers
$stdout.write("|")
$stdout.write(hrow.keys.join("|"))
$stdout.write("|")
$stdout.write("\n")

$stdout.write("|")
$stdout.write(hrow.values.map { |v| /^\d+$/.match?(v) ? "--:" : ":--" }.join("|"))
$stdout.write("|")
$stdout.write("\n")
end

headers = false

$stdout.write("|")
$stdout.write(hrow.values.map { |v| /^\d+$/.match?(v) ? "--:" : ":--" }.join("|"))
$stdout.write(hrow.values.join("|"))
$stdout.write("|")
$stdout.write("\n")
end

headers = false

$stdout.write("|")
$stdout.write(hrow.values.join("|"))
$stdout.write("|")
$stdout.write("\n")
else
sh "steep stats --format=#{format}"
end
else
sh "steep stats --format=#{format}"
end
end

desc "Run type checks"
# task check: "steep:check"
rescue LoadError
end

0 comments on commit 45d71e4

Please sign in to comment.