Skip to content

Commit 3920269

Browse files
small logging changes around codegen-test and small refactoring of Drivers project (#55)
1 parent 693acf1 commit 3920269

13 files changed

+73
-80
lines changed

.github/workflows/main.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ jobs:
123123
run: ./scripts/wasm/update_sha.sh sqlc.ci.yaml
124124

125125
- name: Codegen Test
126-
run: |
127-
./scripts/run_codegen_test.sh sqlc.ci.yaml \
128-
${{ matrix.file-per-query }} ${{ matrix.generate-csproj }} ${{ matrix.target-framework }}
126+
run: ./scripts/run_codegen_test.sh sqlc.ci.yaml \
127+
${{ matrix.file-per-query }} ${{ matrix.generate-csproj }} ${{ matrix.target-framework }}
129128

130129
- uses: actions/setup-dotnet@v4
131130
with:
@@ -186,7 +185,7 @@ jobs:
186185
- name: Bump version and create new tag
187186
id: bump_version
188187
run: |
189-
set -ex
188+
set -e
190189
echo "Extract the latest tag version"
191190
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
192191
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ COPY Drivers/*.csproj ./Drivers/
99
COPY EndToEndTests/*.csproj ./EndToEndTests/
1010
COPY Extensions/*.csproj ./Extensions/
1111
COPY GeneratedProtobuf/*.csproj ./GeneratedProtobuf/
12+
COPY LocalRunner/*.csproj ./LocalRunner/
1213
COPY MySqlConnectorExample/*.csproj ./MySqlConnectorExample/
1314
COPY NpgsqlExample/*.csproj ./NpgsqlExample/
1415
COPY PluginOptions/*.csproj ./PluginOptions/
15-
COPY ProcessRunner/*.csproj ./ProcessRunner/
1616
COPY SqlcGenCsharp/*.csproj ./SqlcGenCsharp/
1717
COPY WasmRunner/*.csproj ./WasmRunner/
1818

@@ -21,10 +21,10 @@ COPY Drivers/ ./Drivers/
2121
COPY EndToEndTests/ ./EndToEndTests/
2222
COPY Extensions/ ./Extensions/
2323
COPY GeneratedProtobuf/ ./GeneratedProtobuf/
24+
COPY LocalRunner/ ./LocalRunner/
2425
COPY MySqlConnectorExample/ ./MySqlConnectorExample/
2526
COPY NpgsqlExample/ ./NpgsqlExample/
2627
COPY PluginOptions/ ./PluginOptions/
27-
COPY ProcessRunner/ ./ProcessRunner/
2828
COPY SqlcGenCsharp/ ./SqlcGenCsharp/
2929
COPY WasmRunner/ ./WasmRunner/
3030

Drivers/DbDriver.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public virtual UsingDirectiveSyntax[] GetUsingDirectives()
2525
public string AddNullableSuffix(string csharpType, bool notNull)
2626
{
2727
if (notNull) return csharpType;
28-
if (Utils.IsCsharpPrimitive(csharpType)) return $"{csharpType}?";
28+
if (IsCsharpPrimitive(csharpType)) return $"{csharpType}?";
2929
return DotnetFramework.LatestDotnetSupported() ? $"{csharpType}?" : csharpType;
3030
}
3131

@@ -73,4 +73,10 @@ public abstract MemberDeclarationSyntax ExecDeclare(string funcName, string text
7373

7474
public abstract MemberDeclarationSyntax ExecLastIdDeclare(string funcName, string queryTextConstant,
7575
string argInterface, IList<Parameter> parameters);
76+
77+
public static bool IsCsharpPrimitive(string csharpType)
78+
{
79+
var csharpPrimitives = new HashSet<string> { "long", "double", "int", "float", "bool" };
80+
return csharpPrimitives.Contains(csharpType.Replace("?", ""));
81+
}
7682
}

Drivers/Generators/CommonGen.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ string GetNullExpression(Column column)
5555
var csharpType = dbDriver.GetColumnType(column);
5656
if (csharpType == "string")
5757
return "string.Empty";
58-
return !dbDriver.DotnetFramework.LatestDotnetSupported() && Utils.IsCsharpPrimitive(csharpType)
58+
return !dbDriver.DotnetFramework.LatestDotnetSupported() && DbDriver.IsCsharpPrimitive(csharpType)
5959
? $"({csharpType}) null"
6060
: "null";
6161
}

Drivers/Utils.cs

-12
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dotnet-publish-process: dotnet-build-process
2525
dotnet publish ProcessRunner -c release --output dist/
2626

2727
sqlc-generate-process: dotnet-publish-process
28-
sqlc -f sqlc.process.yaml generate
28+
sqlc -f sqlc.local.yaml generate
2929

3030
test-process-plugin: sqlc-generate-process dockerfile-generate run-tests
3131

scripts/run_codegen_test.sh

+58-58
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,80 @@ set -e
44

55
declare -a examples=("MySqlConnectorExample" "NpgsqlExample")
66

7+
config_file=$1
8+
file_per_query=$2
9+
generate_csproj=$3
10+
target_framework=$4
11+
712
generated_files_cleanup() {
8-
generate_csproj=$1
9-
for example_dir in "${examples[@]}"
10-
do
11-
echo "Deleting .cs files" && find "${example_dir}/" -type f -name "*.cs" -exec rm -f {} \;
12-
if [ "${generate_csproj}" = "true" ]; then
13-
echo "Deleting .csproj file" && rm "${example_dir}/${example_dir}.csproj"
14-
fi
15-
done
13+
for example_dir in "${examples[@]}"
14+
do
15+
echo "Deleting .cs files in ${example_dir}"
16+
find "${example_dir}/" -type f -name "*.cs" -exec rm -f {} \;
17+
if [ "${generate_csproj}" = "true" ]; then
18+
echo "Deleting .csproj file" && rm "${example_dir}/${example_dir}.csproj"
19+
fi
20+
done
21+
}
22+
23+
change_config() {
24+
for ((i=0; i<${#examples[@]}; i++)); do
25+
echo "Changing configuration for project ${example_dir}"
26+
yq -i "
27+
.sql[${i}].codegen[0].options.filePerQuery = ${file_per_query} |
28+
.sql[${i}].codegen[0].options.generateCsproj = ${generate_csproj} |
29+
.sql[${i}].codegen[0].options.targetFramework = \"${target_framework}\"
30+
" "${config_file}"
31+
echo "${examples[i]} codegen config:" && yq ".sql[${i}].codegen[0]" "${config_file}"
32+
done
1633
}
1734

1835
check_cs_file_count() {
19-
file_per_query=$1
20-
for example_dir in "${examples[@]}"
21-
do
22-
file_count=$(find "${example_dir}/" -maxdepth 1 -name "*.cs" 2>/dev/null | wc -l)
23-
if [[ "${file_per_query}" = "true" && "${file_count}" -le 2 ]]; then
24-
echo "Assertion failed: Not more than 2 .cs files in the directory ${example_dir}."
25-
return 1
26-
elif [[ "${file_per_query}" = "false" && "${file_count}" -ne 2 ]]; then
27-
echo "Assertion failed: Not exactly 2 .cs files in the directory ${example_dir}."
28-
return 1
29-
fi
30-
done
36+
for example_dir in "${examples[@]}"
37+
do
38+
echo "Checking C# file count in ${example_dir}/"
39+
file_count=$(find "${example_dir}/" -maxdepth 1 -name "*.cs" 2>/dev/null | wc -l)
40+
if [[ "${file_per_query}" = "true" && "${file_count}" -le 2 ]]; then
41+
echo "Assertion failed: Not more than 2 .cs files in the directory ${example_dir}."
42+
return 1
43+
elif [[ "${file_per_query}" = "false" && "${file_count}" -ne 2 ]]; then
44+
echo "Assertion failed: Not exactly 2 .cs files in the directory ${example_dir}."
45+
return 1
46+
fi
47+
done
3148
}
3249

3350
check_csproj_file() {
34-
for example_dir in "${examples[@]}"
35-
do
36-
if [ ! -f "${example_dir}/${example_dir}.csproj" ]; then
37-
echo "Assertion failed: A .csproj file is not present in the directory ${example_dir}."
38-
return 1
39-
fi
40-
done
51+
for example_dir in "${examples[@]}"
52+
do
53+
echo "Checking ${example_dir}.csproj file generated"
54+
if [ ! -f "${example_dir}/${example_dir}.csproj" ]; then
55+
echo "Assertion failed: A .csproj file is not present in the directory ${example_dir}."
56+
return 1
57+
fi
58+
done
4159
}
4260

4361
check_project_compiles() {
62+
if [ "${generate_csproj}" = "true" ]; then
4463
for example_dir in "${examples[@]}"
4564
do
65+
echo "Checking ${example_dir} project compiles"
4666
dotnet build "${example_dir}/"
4767
done
68+
fi
4869
}
4970

50-
config_file=$1
51-
file_per_query=$2
52-
generate_csproj=$3
53-
target_framework=$4
54-
55-
yq -i "
56-
.sql[0].codegen[0].options.filePerQuery = ${file_per_query} |
57-
.sql[1].codegen[0].options.filePerQuery = ${file_per_query} |
58-
.sql[0].codegen[0].options.generateCsproj = ${generate_csproj} |
59-
.sql[1].codegen[0].options.generateCsproj = ${generate_csproj} |
60-
.sql[0].codegen[0].options.targetFramework = \"${target_framework}\" |
61-
.sql[1].codegen[0].options.targetFramework = \"${target_framework}\"
62-
" "${config_file}"
63-
64-
generated_files_cleanup "${generate_csproj}"
65-
echo "Using the following codegen config:" && \
66-
yq '.sql[0].codegen[0]' "${config_file}" && \
67-
yq '.sql[1].codegen[0]' "${config_file}"
71+
generated_files_cleanup && change_config
6872
sqlc -f "${config_file}" generate
6973

70-
status_code=$(check_cs_file_count "${file_per_query}")
71-
if [ "${status_code}" -ne 0 ]; then
72-
exit "${status_code}"
73-
fi
74-
status_code=$(check_csproj_file)
75-
if [ "${status_code}" -ne 0 ]; then
74+
test_functions=("check_cs_file_count" "check_csproj_file" "check_project_compiles")
75+
for test_function in "${test_functions[@]}"; do
76+
${test_function}
77+
status_code=$?
78+
if [ ${status_code} -ne 0 ]; then
79+
echo "Function ${test_function} failed with status code ${status_code}"
7680
exit "${status_code}"
77-
fi
78-
if [ "${generate_csproj}" = "true" ]; then
79-
status_code=$(check_project_compiles "${target_framework}")
80-
if [ "${status_code}" -ne 0 ]; then
81-
exit "${status_code}"
82-
fi
83-
fi
81+
fi
82+
echo "Test ${test_function} passed"
83+
done

sqlc-gen-csharp.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessRunner", "ProcessRunner\ProcessRunner.csproj", "{649CFB46-68D1-41F8-BD76-FF4B79B16825}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalRunner", "LocalRunner\LocalRunner.csproj", "{649CFB46-68D1-41F8-BD76-FF4B79B16825}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySqlConnectorExample", "MySqlConnectorExample\MySqlConnectorExample.csproj", "{6406B659-77CF-4978-ABD3-BFBB2CBFFCA3}"
99
EndProject

sqlc.process.yaml sqlc.local.yaml

File renamed without changes.

0 commit comments

Comments
 (0)