Skip to content

Commit 258d0b0

Browse files
split ci job to build and test (#51)
1 parent 7264d98 commit 258d0b0

File tree

7 files changed

+74
-49
lines changed

7 files changed

+74
-49
lines changed

.github/workflows/main.yml

+51-31
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: actions/checkout@v3
2626

2727
- name: Set up .NET
28-
uses: actions/setup-dotnet@v1
28+
uses: actions/setup-dotnet@v3
2929
with:
3030
dotnet-version: "8.0.x"
3131

@@ -38,12 +38,16 @@ jobs:
3838
GeneratedProtobuf
3939
MySqlConnectorExample
4040
NpgsqlExample
41-
41+
42+
- name: Verify pushed Dockerfile is synced
43+
run: |
44+
./scripts/generate_dockerfile.sh /tmp/Dockerfile
45+
diff /tmp/Dockerfile Dockerfile
4246
43-
ci:
44-
name: CI
47+
build:
48+
name: Build & Generate
4549
runs-on: ${{ matrix.os }}
46-
if: ${{ always() }}
50+
needs: [lint]
4751
strategy:
4852
matrix:
4953
os: [ 'ubuntu-latest' ]
@@ -82,13 +86,7 @@ jobs:
8286
- name: Dotnet Wasm Publish
8387
run: |
8488
WASI_SDK_PATH="$(pwd)/wasi-sdk-22.0" dotnet publish WasmRunner -c release
85-
./scripts/wasm/copy_to_dist.sh
86-
./scripts/wasm/update_sha.sh
87-
88-
- name: Verify pushed Dockerfile is synced
89-
run: |
90-
./scripts/generate_dockerfile.sh /tmp/Dockerfile
91-
diff /tmp/Dockerfile Dockerfile
89+
./scripts/wasm/copy_plugin_to.sh dist
9290
9391
- uses: sqlc-dev/setup-sqlc@v4
9492
with:
@@ -97,42 +95,64 @@ jobs:
9795
- name: Updating configuration
9896
env:
9997
FILE_PER_QUERY: ${{ matrix.file-per-query }}
100-
run: ./scripts/update_config.sh $FILE_PER_QUERY
101-
102-
- name: Verify pushed generated code is synced
103-
if: matrix.file-per-query == 'false'
104-
run: sqlc -f sqlc.wasm.yaml diff
98+
run: |
99+
./scripts/wasm/update_sha.sh sqlc.ci.yaml
100+
./scripts/update_config.sh sqlc.ci.yaml $FILE_PER_QUERY
105101
106102
- name: Sqlc generate using Wasm plugin
107103
run: |
108104
rm MySqlConnectorExample/*.cs NpgsqlExample/*.cs
109-
sqlc -f sqlc.wasm.yaml generate
105+
sqlc -f sqlc.ci.yaml generate
106+
107+
- name: upload wasm plugin as artifact
108+
if: matrix.file-per-query == 'false' && matrix.architecture == 'arm64'
109+
uses: actions/upload-artifact@v4
110+
with:
111+
name: wasm-file
112+
path: dist/plugin.wasm
113+
114+
test:
115+
name: Test
116+
runs-on: ubuntu-latest
117+
needs: [build]
110118

119+
steps:
120+
- uses: actions/checkout@v4
121+
- uses: actions/download-artifact@v4
122+
with:
123+
name: wasm-file
124+
path: dist
125+
126+
- uses: sqlc-dev/setup-sqlc@v4
127+
with:
128+
sqlc-version: '1.25.0'
129+
130+
- name: Verify pushed generated code is synced
131+
run: |
132+
./scripts/wasm/update_sha.sh sqlc.ci.yaml
133+
sqlc -f sqlc.ci.yaml diff
134+
111135
- name: Docker compose
112-
if: matrix.file-per-query == 'false'
113136
uses: hoverkraft-tech/[email protected]
114137
with:
115138
services: |
116139
mysqldb
117140
postgresdb
118141
plugin-tests
119-
142+
143+
- name: Load .env file
144+
uses: xom9ikk/[email protected]
145+
with:
146+
load-mode: strict
147+
120148
- name: Test generated code
121-
if: matrix.file-per-query == 'false'
122149
run: ./scripts/run_tests.sh
123-
124-
- name: upload wasm plugin as artifact
125-
uses: actions/upload-artifact@v2
126-
if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[release]')
127-
with:
128-
name: wasm-file
129-
path: dist/plugin.wasm
130-
150+
131151
release:
132152
name: Release
133153
runs-on: ubuntu-latest
134154
if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[release]')
135-
needs: [ci]
155+
needs: [build, test]
136156
steps:
137157
- name: Check out Git repository
138158
uses: actions/checkout@v4
@@ -142,7 +162,7 @@ jobs:
142162
- uses: actions/download-artifact@v2
143163
with:
144164
name: wasm-file
145-
165+
146166
- name: Bump version and create new tag
147167
id: bump_version
148168
run: |

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ _NCrunch*
135135
dist/*
136136
output/*
137137
docker-upload/*
138+
139+
plugin.wasm

Makefile

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ test-process-plugin: sqlc-generate-process dockerfile-generate run-tests
3232
# WASM type plugin
3333
dotnet-publish-wasm: protobuf-generate
3434
dotnet publish WasmRunner -c release --output dist/
35-
./scripts/wasm/copy_to_dist.sh
35+
./scripts/wasm/copy_plugin_to.sh dist
3636

3737
update-wasm-plugin:
38-
./scripts/wasm/update_sha.sh
38+
./scripts/wasm/update_sha.sh sqlc.ci.yaml
3939

4040
sqlc-generate-wasm: dotnet-publish-wasm update-wasm-plugin
41-
SQLCCACHE=./; sqlc -f sqlc.wasm.yaml generate
42-
yq -i ".plugins[0].wasm.sha256 = \"SHA_TO_REPLACE\"" sqlc.wasm.yaml
41+
SQLCCACHE=./; sqlc -f sqlc.ci.yaml generate
4342

44-
test-wasm-plugin: sqlc-generate-wasm dockerfile-generate run-tests
43+
test-wasm-plugin: sqlc-generate-wasm update-wasm-plugin dockerfile-generate run-tests

scripts/update_config.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
set -ex
44

5-
file_per_query=$1
6-
yq -i ".sql[0].codegen[0].options.filePerQuery = ${file_per_query}" sqlc.wasm.yaml
7-
yq -i ".sql[1].codegen[0].options.filePerQuery = ${file_per_query}" sqlc.wasm.yaml
5+
filename=$1
6+
file_per_query=$2
7+
yq -i "
8+
.sql[0].codegen[0].options.filePerQuery = ${file_per_query} |
9+
.sql[1].codegen[0].options.filePerQuery = ${file_per_query}
10+
" "$filename"

scripts/wasm/copy_to_dist.sh scripts/wasm/copy_plugin_to.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
set -e
44
source .env
55

6+
target_dir=$1
67
if [ "${GITHUB_ACTIONS}" = "true" ]; then
78
WASM_FILE="${SOURCE_WASM_FILE_UBUNTU}"
89
else
910
WASM_FILE="${SOURCE_WASM_FILE}"
1011
fi
1112

1213
echo "WASM_FILE = ${WASM_FILE}"
13-
mkdir -p dist
14-
cp "${WASM_FILE}" dist/plugin.wasm
15-
echo "WASM filesize:" && du -sh dist/plugin.wasm
14+
mkdir -p "${target_dir}" && cp "${WASM_FILE}" "${target_dir}/plugin.wasm"
15+
echo "WASM filesize:" && du -sh "${target_dir}/plugin.wasm"

scripts/wasm/update_sha.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
22

3+
filename=$1
34
plugin_sha=$(shasum -a 256 dist/plugin.wasm | awk '{ print $1 }')
4-
yq -i ".plugins[0].wasm.sha256 = \"${plugin_sha}\"" sqlc.wasm.yaml
5+
yq -i ".plugins[0].wasm.sha256 = \"${plugin_sha}\"" "${filename}"

sqlc.wasm.yaml sqlc.ci.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ sql:
1313
out: NpgsqlExample
1414
options:
1515
driver: Npgsql
16-
filePerQuery: BOOL_TO_REPLACE
17-
# targetFramework: netstandard2.0
18-
# generateCsproj: true
16+
filePerQuery: false
17+
targetFramework: net8.0
18+
generateCsproj: true
1919
- schema: "examples/authors/mysql/schema.sql"
2020
queries: "examples/authors/mysql/query.sql"
2121
engine: "mysql"
@@ -24,6 +24,6 @@ sql:
2424
out: MySqlConnectorExample
2525
options:
2626
driver: MySqlConnector
27-
filePerQuery: BOOL_TO_REPLACE
28-
# targetFramework: netstandard2.0
29-
# generateCsproj: true
27+
filePerQuery: false
28+
targetFramework: net8.0
29+
generateCsproj: true

0 commit comments

Comments
 (0)