Skip to content

Commit 693acf1

Browse files
testing via CI all of the possible configurations and refactored run_codegen_test script (#54)
1 parent 08faef0 commit 693acf1

File tree

5 files changed

+99
-99
lines changed

5 files changed

+99
-99
lines changed

Whitespace-only changes.

.github/workflows/main.yml

+16-21
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252
matrix:
5353
os: [ 'ubuntu-latest' ]
5454
architecture: [ 'x64', 'arm64' ]
55-
dotnet-version: [ '8.0.x' ]
5655

5756
steps:
5857
- uses: actions/checkout@v4
@@ -61,10 +60,10 @@ jobs:
6160
with:
6261
load-mode: strict
6362

64-
- name: Setup Dotnet ${{ matrix.dotnet-version }}
63+
- name: Setup Dotnet
6564
uses: actions/setup-dotnet@v4
6665
with:
67-
dotnet-version: ${{ matrix.dotnet-version }}
66+
dotnet-version: '8.0.x'
6867

6968
- name: install Wasi workload
7069
run: dotnet workload install wasi-experimental
@@ -88,20 +87,21 @@ jobs:
8887
./scripts/wasm/copy_plugin_to.sh dist
8988
9089
- name: upload wasm plugin as artifact
91-
if: matrix.architecture == 'arm64'
90+
if: matrix.architecture == 'arm64' # this needs to happen once across matrix
9291
uses: actions/upload-artifact@v4
9392
with:
9493
name: wasm-file
9594
path: dist/plugin.wasm
9695

97-
generate-tests:
98-
name: Codegen Tests
96+
codegen-tests:
97+
name: Codegen Test
9998
runs-on: ubuntu-latest
10099
needs: [build]
101100
strategy:
102101
matrix:
103102
file-per-query: [ 'true', 'false' ]
104103
generate-csproj: [ 'true', 'false' ]
104+
target-framework: [ 'net8.0', 'netstandard2.0', 'netstandard2.1' ]
105105

106106
steps:
107107
- uses: actions/checkout@v4
@@ -119,27 +119,22 @@ jobs:
119119
with:
120120
sqlc-version: '1.25.0'
121121

122-
- name: Updating configuration
123-
env:
124-
FILE_PER_QUERY: ${{ matrix.file-per-query }}
125-
GENERATE_CSPROJ: ${{ matrix.generate-csproj }}
126-
run: |
127-
./scripts/wasm/update_sha.sh sqlc.ci.yaml
128-
./scripts/update_config.sh sqlc.ci.yaml $FILE_PER_QUERY $GENERATE_CSPROJ
122+
- name: Updating plugin sha
123+
run: ./scripts/wasm/update_sha.sh sqlc.ci.yaml
129124

130-
- name: Sqlc generate using Wasm plugin
131-
env:
132-
FILE_PER_QUERY: ${{ matrix.file-per-query }}
133-
GENERATE_CSPROJ: ${{ matrix.generate-csproj }}
125+
- name: Codegen Test
134126
run: |
135-
rm MySqlConnectorExample/*.cs NpgsqlExample/*.cs
136-
sqlc -f sqlc.ci.yaml generate
137-
./scripts/run_codegen_tests.sh $FILE_PER_QUERY $GENERATE_CSPROJ
127+
./scripts/run_codegen_test.sh sqlc.ci.yaml \
128+
${{ matrix.file-per-query }} ${{ matrix.generate-csproj }} ${{ matrix.target-framework }}
138129
130+
- uses: actions/setup-dotnet@v4
131+
with:
132+
dotnet-version: ${{ matrix.target-framework == 'net8.0' && '8.0.x' || '3.1.x' }}
133+
139134
end2end-tests:
140135
name: End-to-End Tests
141136
runs-on: ubuntu-latest
142-
needs: [generate-tests]
137+
needs: [codegen-tests]
143138

144139
steps:
145140
- uses: actions/checkout@v4

scripts/run_codegen_test.sh

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
declare -a examples=("MySqlConnectorExample" "NpgsqlExample")
6+
7+
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
16+
}
17+
18+
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
31+
}
32+
33+
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
41+
}
42+
43+
check_project_compiles() {
44+
for example_dir in "${examples[@]}"
45+
do
46+
dotnet build "${example_dir}/"
47+
done
48+
}
49+
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}"
68+
sqlc -f "${config_file}" generate
69+
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
76+
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

scripts/run_codegen_tests.sh

-65
This file was deleted.

scripts/update_config.sh

-13
This file was deleted.

0 commit comments

Comments
 (0)