Skip to content

Commit 3882c16

Browse files
[release] [minor] added type validation with steep check (#29)
fixed SemanticVersionRegex to include whitespace
1 parent 538318f commit 3882c16

16 files changed

+245
-74
lines changed

.github/workflows/ci.yml

+48-2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,56 @@ jobs:
8585
name: wasm-file
8686
path: dist/plugin.wasm
8787

88-
end2end-tests:
88+
codegen_test:
89+
name: Codegen Test
90+
needs: [build]
91+
runs-on: ubuntu-latest
92+
93+
strategy:
94+
fail-fast: false
95+
matrix:
96+
ruby-version: [ '3.3' ]
97+
generate-types: [ 'true' ]
98+
generate-gemfile: [ 'false' ]
99+
100+
steps:
101+
- name: Check out Git repository
102+
uses: actions/checkout@v4
103+
104+
- name: Load .env file
105+
uses: xom9ikk/[email protected]
106+
with:
107+
load-mode: strict
108+
109+
- uses: ruby/setup-ruby@v1
110+
with:
111+
ruby-version: ${{ matrix.ruby-version }}
112+
bundler-cache: true
113+
114+
- uses: actions/download-artifact@v4
115+
with:
116+
name: wasm-file
117+
path: dist
118+
119+
- uses: sqlc-dev/setup-sqlc@v4
120+
with:
121+
sqlc-version: '1.25.0'
122+
123+
- name: Updating plugin sha
124+
run: ./scripts/wasm/update_sha.sh ${SQLC_CI_FILE}
125+
126+
- name: Codegen Test
127+
run: ./scripts/tests/run_codegen.sh ${SQLC_CI_FILE} \
128+
${{ matrix.ruby-version }} ${{ matrix.generate-types }} ${{ matrix.generate-gemfile }}
129+
130+
- name: Steep check
131+
if: ${{ matrix.generate-types == 'true' }}
132+
run: rake steep
133+
134+
end2end_tests:
89135
name: End-to-End Tests
90136
runs-on: ubuntu-latest
91-
needs: [build]
137+
needs: [build, codegen_test]
92138

93139
steps:
94140
- uses: actions/checkout@v4

Drivers/MethodGen.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public MethodDeclaration OneDeclare(string funcName, string queryTextConstant, s
3030
funcName,
3131
argInterface,
3232
GetMethodArgs(argInterface, parameters),
33-
returnInterface,
33+
$"{returnInterface}?",
3434
new List<IComposable>
3535
{
3636
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody.ToList())
@@ -56,8 +56,11 @@ public MethodDeclaration ManyDeclare(string funcName, string queryTextConstant,
5656
dbDriver.PrepareStmt(funcName, queryTextConstant),
5757
ExecuteAndAssign(funcName, queryParams),
5858
new SimpleStatement(Variable.Entities.AsVar(), new SimpleExpression("[]")),
59-
new ForeachLoop(Variable.Result.AsVar(), Variable.Row.AsVar(),
60-
new List<IComposable> { listAppend }),
59+
new ForeachLoop(
60+
Variable.Result.AsVar(),
61+
Variable.Row.AsVar(),
62+
new List<IComposable> { listAppend }
63+
),
6164
new SimpleExpression($"return {Variable.Entities.AsVar()}")
6265
]
6366
);
@@ -66,10 +69,14 @@ public MethodDeclaration ManyDeclare(string funcName, string queryTextConstant,
6669
funcName,
6770
argInterface,
6871
GetMethodArgs(argInterface, parameters),
69-
returnInterface,
72+
$"Array[{returnInterface}]",
7073
new List<IComposable>
7174
{
72-
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody.ToList())
75+
new WithResource(
76+
Variable.Pool.AsProperty(),
77+
Variable.Client.AsVar(),
78+
withResourceBody.ToList()
79+
)
7380
});
7481
}
7582

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ gem 'connection_pool'
44
gem 'mysql2'
55
gem 'pg', '1.5.2'
66
gem 'minitest'
7-
gem 'rake'
7+
gem 'rake'
8+
gem 'steep'

Gemfile.lock

+63
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,73 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
abbrev (0.1.2)
5+
activesupport (7.1.3.3)
6+
base64
7+
bigdecimal
8+
concurrent-ruby (~> 1.0, >= 1.0.2)
9+
connection_pool (>= 2.2.5)
10+
drb
11+
i18n (>= 1.6, < 2)
12+
minitest (>= 5.1)
13+
mutex_m
14+
tzinfo (~> 2.0)
15+
ast (2.4.2)
16+
base64 (0.2.0)
17+
bigdecimal (3.1.5)
18+
concurrent-ruby (1.2.3)
419
connection_pool (2.4.1)
20+
csv (3.2.8)
21+
drb (2.2.0)
22+
ruby2_keywords
23+
ffi (1.16.3)
24+
fileutils (1.7.2)
25+
i18n (1.14.5)
26+
concurrent-ruby (~> 1.0)
27+
json (2.7.1)
28+
language_server-protocol (3.17.0.3)
29+
listen (3.9.0)
30+
rb-fsevent (~> 0.10, >= 0.10.3)
31+
rb-inotify (~> 0.9, >= 0.9.10)
32+
logger (1.6.0)
533
minitest (5.24.0)
34+
mutex_m (0.2.0)
635
mysql2 (0.5.6)
36+
parser (3.3.1.0)
37+
ast (~> 2.4.1)
38+
racc
739
pg (1.5.2)
40+
racc (1.7.3)
41+
rainbow (3.1.1)
842
rake (13.2.1)
43+
rb-fsevent (0.11.2)
44+
rb-inotify (0.10.1)
45+
ffi (~> 1.0)
46+
rbs (3.4.0)
47+
abbrev
48+
ruby2_keywords (0.0.5)
49+
securerandom (0.3.1)
50+
steep (1.6.0)
51+
activesupport (>= 5.1)
52+
concurrent-ruby (>= 1.1.10)
53+
csv (>= 3.0.9)
54+
fileutils (>= 1.1.0)
55+
json (>= 2.1.0)
56+
language_server-protocol (>= 3.15, < 4.0)
57+
listen (~> 3.0)
58+
logger (>= 1.3.0)
59+
parser (>= 3.1)
60+
rainbow (>= 2.2.2, < 4.0)
61+
rbs (>= 3.1.0)
62+
securerandom (>= 0.1)
63+
strscan (>= 1.0.0)
64+
terminal-table (>= 2, < 4)
65+
strscan (3.0.7)
66+
terminal-table (3.0.2)
67+
unicode-display_width (>= 1.1.1, < 3)
68+
tzinfo (2.0.6)
69+
concurrent-ruby (~> 1.0)
70+
unicode-display_width (2.5.0)
971

1072
PLATFORMS
1173
arm64-darwin-23
@@ -17,6 +79,7 @@ DEPENDENCIES
1779
mysql2
1880
pg (= 1.5.2)
1981
rake
82+
steep
2083

2184
BUNDLED WITH
2285
2.5.10

PluginOptions/RubyVersion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ public static bool ImmutableDataSupported(this RubyVersion me)
6464
return me.AtLeast(new RubyVersion(3, 2));
6565
}
6666

67-
[GeneratedRegex(@"^(0|[1-9][0-9]*)(?:\.(0|[1-9][0-9]*))?(?:\.(0|[1-9][0-9]*))?$")]
67+
[GeneratedRegex(@"^\s*(0|[1-9][0-9]*)(?:\.(0|[1-9][0-9]*))?(?:\.(0|[1-9][0-9]*))?\s*$")]
6868
private static partial Regex SemanticVersionRegex();
6969
}

Rakefile

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Rake::TestTask.new(:end2end_tests) do |t| # called inside Docker
66
t.pattern = "tests/end2end_*.rb"
77
end
88

9+
task :steep do
10+
sh "bundle exec steep check --with-expectations"
11+
end
12+
913
task :run_end2end_tests do
1014
sh "./scripts/tests/run_end2end.sh"
1115
end

RubySyntax/Flows.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public string BuildCode()
7878
{
7979
var foreachBody = statements
8080
.Select(s => s.BuildCode())
81-
.JoinByNewLine();
81+
.JoinByNewLine()
82+
.Indent();
8283
var foreachLoop = $"{collectionVar}.each do |{controlVar}|\n{foreachBody}\nend";
8384
return foreachLoop;
8485
}

Steepfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target :gen do
2+
check "examples"
3+
signature "examples"
4+
end

examples/mysql2/query_sql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def list_authors
118118
result = stmt.execute
119119
entities = []
120120
result.each do |row|
121-
entities << ListAuthorsRow.new(row['id'], row['name'], row['bio'])
121+
entities << ListAuthorsRow.new(row['id'], row['name'], row['bio'])
122122
end
123123
return entities
124124
end

examples/mysql2/query_sql.rbs

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ module Mysql2Codegen
139139
@pool: untyped
140140
def initialize: (Hash[String, String], Hash[String, String]) -> void
141141

142-
def get_author: (GetAuthorArgs) -> GetAuthorRow
142+
def get_author: (GetAuthorArgs) -> GetAuthorRow?
143143

144-
def list_authors: -> ListAuthorsRow
144+
def list_authors: -> Array[ListAuthorsRow]
145145

146146
def create_author: (CreateAuthorArgs) -> void
147147

@@ -151,6 +151,6 @@ module Mysql2Codegen
151151

152152
def delete_author: (DeleteAuthorArgs) -> void
153153

154-
def test: -> TestRow
154+
def test: -> TestRow?
155155
end
156156
end

examples/pg/query_sql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def list_authors
9797
result = client.exec_prepared('list_authors')
9898
entities = []
9999
result.each do |row|
100-
entities << ListAuthorsRow.new(row['id'], row['name'], row['bio'])
100+
entities << ListAuthorsRow.new(row['id'], row['name'], row['bio'])
101101
end
102102
return entities
103103
end

examples/pg/query_sql.rbs

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ module PgCodegen
9393
@prepared_statements: Set[String]
9494
def initialize: (Hash[String, String], Hash[String, String]) -> void
9595

96-
def get_author: (GetAuthorArgs) -> GetAuthorRow
96+
def get_author: (GetAuthorArgs) -> GetAuthorRow?
9797

98-
def list_authors: -> ListAuthorsRow
98+
def list_authors: -> Array[ListAuthorsRow]
9999

100-
def create_author: (CreateAuthorArgs) -> CreateAuthorRow
100+
def create_author: (CreateAuthorArgs) -> CreateAuthorRow?
101101

102102
def delete_author: (DeleteAuthorArgs) -> void
103103

104-
def test: -> TestRow
104+
def test: -> TestRow?
105105
end
106106
end

0 commit comments

Comments
 (0)