Skip to content

Commit

Permalink
[release] [minor] added type validation with steep check (#29)
Browse files Browse the repository at this point in the history
fixed SemanticVersionRegex to include whitespace
  • Loading branch information
SockworkOrange authored Jul 2, 2024
1 parent 538318f commit 3882c16
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 74 deletions.
50 changes: 48 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,56 @@ jobs:
name: wasm-file
path: dist/plugin.wasm

end2end-tests:
codegen_test:
name: Codegen Test
needs: [build]
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby-version: [ '3.3' ]
generate-types: [ 'true' ]
generate-gemfile: [ 'false' ]

steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Load .env file
uses: xom9ikk/[email protected]
with:
load-mode: strict

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

- uses: actions/download-artifact@v4
with:
name: wasm-file
path: dist

- uses: sqlc-dev/setup-sqlc@v4
with:
sqlc-version: '1.25.0'

- name: Updating plugin sha
run: ./scripts/wasm/update_sha.sh ${SQLC_CI_FILE}

- name: Codegen Test
run: ./scripts/tests/run_codegen.sh ${SQLC_CI_FILE} \
${{ matrix.ruby-version }} ${{ matrix.generate-types }} ${{ matrix.generate-gemfile }}

- name: Steep check
if: ${{ matrix.generate-types == 'true' }}
run: rake steep

end2end_tests:
name: End-to-End Tests
runs-on: ubuntu-latest
needs: [build]
needs: [build, codegen_test]

steps:
- uses: actions/checkout@v4
Expand Down
17 changes: 12 additions & 5 deletions Drivers/MethodGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MethodDeclaration OneDeclare(string funcName, string queryTextConstant, s
funcName,
argInterface,
GetMethodArgs(argInterface, parameters),
returnInterface,
$"{returnInterface}?",
new List<IComposable>
{
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody.ToList())
Expand All @@ -56,8 +56,11 @@ public MethodDeclaration ManyDeclare(string funcName, string queryTextConstant,
dbDriver.PrepareStmt(funcName, queryTextConstant),
ExecuteAndAssign(funcName, queryParams),
new SimpleStatement(Variable.Entities.AsVar(), new SimpleExpression("[]")),
new ForeachLoop(Variable.Result.AsVar(), Variable.Row.AsVar(),
new List<IComposable> { listAppend }),
new ForeachLoop(
Variable.Result.AsVar(),
Variable.Row.AsVar(),
new List<IComposable> { listAppend }
),
new SimpleExpression($"return {Variable.Entities.AsVar()}")
]
);
Expand All @@ -66,10 +69,14 @@ public MethodDeclaration ManyDeclare(string funcName, string queryTextConstant,
funcName,
argInterface,
GetMethodArgs(argInterface, parameters),
returnInterface,
$"Array[{returnInterface}]",
new List<IComposable>
{
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody.ToList())
new WithResource(
Variable.Pool.AsProperty(),
Variable.Client.AsVar(),
withResourceBody.ToList()
)
});
}

Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ gem 'connection_pool'
gem 'mysql2'
gem 'pg', '1.5.2'
gem 'minitest'
gem 'rake'
gem 'rake'
gem 'steep'
63 changes: 63 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,73 @@
GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.2)
activesupport (7.1.3.3)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.5)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
csv (3.2.8)
drb (2.2.0)
ruby2_keywords
ffi (1.16.3)
fileutils (1.7.2)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.0)
minitest (5.24.0)
mutex_m (0.2.0)
mysql2 (0.5.6)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
pg (1.5.2)
racc (1.7.3)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbs (3.4.0)
abbrev
ruby2_keywords (0.0.5)
securerandom (0.3.1)
steep (1.6.0)
activesupport (>= 5.1)
concurrent-ruby (>= 1.1.10)
csv (>= 3.0.9)
fileutils (>= 1.1.0)
json (>= 2.1.0)
language_server-protocol (>= 3.15, < 4.0)
listen (~> 3.0)
logger (>= 1.3.0)
parser (>= 3.1)
rainbow (>= 2.2.2, < 4.0)
rbs (>= 3.1.0)
securerandom (>= 0.1)
strscan (>= 1.0.0)
terminal-table (>= 2, < 4)
strscan (3.0.7)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-23
Expand All @@ -17,6 +79,7 @@ DEPENDENCIES
mysql2
pg (= 1.5.2)
rake
steep

BUNDLED WITH
2.5.10
2 changes: 1 addition & 1 deletion PluginOptions/RubyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public static bool ImmutableDataSupported(this RubyVersion me)
return me.AtLeast(new RubyVersion(3, 2));
}

[GeneratedRegex(@"^(0|[1-9][0-9]*)(?:\.(0|[1-9][0-9]*))?(?:\.(0|[1-9][0-9]*))?$")]
[GeneratedRegex(@"^\s*(0|[1-9][0-9]*)(?:\.(0|[1-9][0-9]*))?(?:\.(0|[1-9][0-9]*))?\s*$")]
private static partial Regex SemanticVersionRegex();
}
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Rake::TestTask.new(:end2end_tests) do |t| # called inside Docker
t.pattern = "tests/end2end_*.rb"
end

task :steep do
sh "bundle exec steep check --with-expectations"
end

task :run_end2end_tests do
sh "./scripts/tests/run_end2end.sh"
end
Expand Down
3 changes: 2 additions & 1 deletion RubySyntax/Flows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public string BuildCode()
{
var foreachBody = statements
.Select(s => s.BuildCode())
.JoinByNewLine();
.JoinByNewLine()
.Indent();
var foreachLoop = $"{collectionVar}.each do |{controlVar}|\n{foreachBody}\nend";
return foreachLoop;
}
Expand Down
4 changes: 4 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target :gen do
check "examples"
signature "examples"
end
2 changes: 1 addition & 1 deletion examples/mysql2/query_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def list_authors
result = stmt.execute
entities = []
result.each do |row|
entities << ListAuthorsRow.new(row['id'], row['name'], row['bio'])
entities << ListAuthorsRow.new(row['id'], row['name'], row['bio'])
end
return entities
end
Expand Down
6 changes: 3 additions & 3 deletions examples/mysql2/query_sql.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ module Mysql2Codegen
@pool: untyped
def initialize: (Hash[String, String], Hash[String, String]) -> void

def get_author: (GetAuthorArgs) -> GetAuthorRow
def get_author: (GetAuthorArgs) -> GetAuthorRow?

def list_authors: -> ListAuthorsRow
def list_authors: -> Array[ListAuthorsRow]

def create_author: (CreateAuthorArgs) -> void

Expand All @@ -151,6 +151,6 @@ module Mysql2Codegen

def delete_author: (DeleteAuthorArgs) -> void

def test: -> TestRow
def test: -> TestRow?
end
end
2 changes: 1 addition & 1 deletion examples/pg/query_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def list_authors
result = client.exec_prepared('list_authors')
entities = []
result.each do |row|
entities << ListAuthorsRow.new(row['id'], row['name'], row['bio'])
entities << ListAuthorsRow.new(row['id'], row['name'], row['bio'])
end
return entities
end
Expand Down
8 changes: 4 additions & 4 deletions examples/pg/query_sql.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ module PgCodegen
@prepared_statements: Set[String]
def initialize: (Hash[String, String], Hash[String, String]) -> void

def get_author: (GetAuthorArgs) -> GetAuthorRow
def get_author: (GetAuthorArgs) -> GetAuthorRow?

def list_authors: -> ListAuthorsRow
def list_authors: -> Array[ListAuthorsRow]

def create_author: (CreateAuthorArgs) -> CreateAuthorRow
def create_author: (CreateAuthorArgs) -> CreateAuthorRow?

def delete_author: (DeleteAuthorArgs) -> void

def test: -> TestRow
def test: -> TestRow?
end
end
Loading

0 comments on commit 3882c16

Please sign in to comment.